$(document).ready(function()
{
	$('.menu_item').click(function()
	{
		$('#sub_' + $(this).attr('id') ).toggle();
	});
	
	if(document.getElementById('random_img_1_front') && document.getElementById('random_img_2_front') && document.getElementById('random_img_3_front'))
	{
		// Mouseover
		$("#random_img_1_front").mouseover(function()
		{
			$('#random_img_1_hover').css({'display':'block', 'opacity':1.0});
		});
		$("#random_img_2_front").mouseover(function()
		{
			$('#random_img_2_hover').css({'display':'block', 'opacity':1.0});
		});
		$("#random_img_3_front").mouseover(function()
		{
			$('#random_img_3_hover').css({'display':'block', 'opacity':1.0});
		});
		
		// Mouseout
		$('#random_img_1_hover').mouseout(function()
		{
			$(this).animate({opacity:0.1},200, function(){
				$(this).hide();
			});
		});
		$('#random_img_2_hover').mouseout(function()
		{
			$(this).animate({opacity:0.1},200, function(){
				$(this).hide();
			});
		});
		$('#random_img_3_hover').mouseout(function()
		{
			$(this).animate({opacity:0.1},200, function(){
				$(this).hide();
			});
		});
	}
	
	
	$('.generate_random').click(function()
	{
		$.ajax({
			type: "POST",
			url: "/random_ajax",
			data: 'img1=' + $('#random_img_1_front').attr('src') + '&link=' + $('#project_link').attr('href') + '&img2=' + $('#random_img_2_front').attr('src') + '&img3=' + $('#random_img_3_front').attr('src'),
			success: function(msg)
			{
				var images = msg.split('|||');
				
				// De afbeeldingen vervangen
				$('#random_img_1_front').attr('src', images[0]);
				$('#project_link').attr('href', images[1]);
				$('#project_link_hover').attr('href', images[1]);
				$('#random_img_2_front').attr('src', images[2]);
				$('#random_img_3_front').attr('src', images[3]);
			}
		});

		return false;
	});


});
