$(document).ready(function()
{
	$('.reactiesToggle').hide();
	
	/*
		$('.rating_star img').livequery('mouseover', function()
		{
			$(this).attr('src', $(this).attr('src').replace('_g.gif', '.gif'));
		});
		
		$('.rating_star img').livequery('mouseout', function()
		{
			$(this).attr('src', $(this).attr('src').replace('.gif', '_g.gif'));
		});
	*/
	
	$('.rating_star').live('click', function()
	{
		var ar_rating = explode('_', $(this).attr('id'));
		$.ajax(
		{
			type:    'POST',
			url:     '/a/vote.php',
			data:    { vote: $(this).attr('id') },
			success: function(msg)
			{
				$('#rating_' + ar_rating[1]).html(msg);
			}
		});
		return false;
	});
	
	$('.reactiesSwitch').toggle
	(
		function()
		{
			$('.reactiesToggle').show();
		},
		
		function()
		{
			$('.reactiesToggle').hide();
		}		
	);
	
	$('#form_reactie').submit(function()
	{
		$('.inputWhite').css('border-color', '#b4b6b8');
		$('.inputWhite').css('background-color', '#fff');
		
		$.ajax(
		{
			type:    'POST',
			url:     '/a/submit_comment.php',
			data:    $(this).serialize(),
			success: function(msg)
			{
				if(msg == 'success')
				{
					window.location.reload();
				}
				
				else if(msg != 'error')
				{
					$('.' + msg).css('border-color', '#a00');
					$('.' + msg).css('background-color', '#ffe1e1');
				}
			}
		});
		return false;
	});

	// Sort form: select boxes
	$('.sortSelect').livequery('change', function(e)
	{
		$('#inputMorePagina').val('1');
		$.ajax(
		{
			type:    'POST',
			url:     '/a/more.php',
			data:    $('#moreForm').serialize(),
			success: function(msg)
			{
				$('#asyncResultBox').html(msg);
			}
		});
		$(this).blur();
	});
	
	// Sort form: page links
	$('.morePagina').live('click', function()
	{
		$('#inputMorePagina').val($(this).attr('pid'));
		$.ajax(
		{
			type:    'POST',
			url:     '/a/more.php',
			data:    $('#moreForm').serialize(),
			success: function(msg)
			{
				$('#asyncResultBox').html(msg);
			}
		});
		$(this).blur();
		return false;
	});
	
	$('.humorBox .text').click(function() { window.location = '/upload/'; });
	$('.etenBox .text').click(function() { window.location = '/upload/'; });
	$('.mensenBox .text').click(function() { window.location = '/upload/'; });
	$('.objectenBox .text').click(function() { window.location = '/upload/'; });
	
	$('form.searchBox input[type="text"]').click(function()
	{
		if($(this).val() == 'Wat zoek je?') { $(this).val(''); }
	});

	$('form.searchBox input[type="text"]').blur(function()
	{
		if($(this).val() == '') { $(this).val('Wat zoek je?'); }
	});
	
	$('.nieuwsBox p').click(function()
	{
		var url = $(':nth-child(2)', $(this).parent()).attr('href');
		window.location = url;
	});

});
