$(function() {
	
	$('.submenu').hover(function() {	
		$(this).find('div').css('display', 'block');
	}, function() {
		$(this).find('div').css('display', 'none');		
	});
	
	
	if ($('#mycarousel').length > 0) {
		$('#mycarousel').jcarousel({
			scroll: 1,
	        start: 1,     
	        animation: 300,
	        auto: 5	
	    });
	    
	    $('#mycarousel li').click(function() {
	    	$('.paddingtop').toggle();
	    	$('.back_overview').toggle();
			var index = $(this).index();
			
			$('.jcarousel-skin-tango').hide();	    
			$('.addheight').hide();	    		
	 	    $('.jcarousel-skin-tango2').removeClass('hide'); 
	 	    
 	   	    var carousel = $('#mycarousel').data('jcarousel');	
		    carousel.stopAuto(); 
	 	    		
			$('#mycarousel2').jcarousel({
				scroll: 1,
		        start: index+1,     
		        animation: 300,
		        itemVisibleInCallback: itemVisibleIn
		    });   
		    
		    $('#container').css('height', '690px');
	
	    });
    }
    
    function itemVisibleIn(carousel, li, index, state) {

		$('#mycarousel2 li').each(function() {
			$(this).removeClass('current');
		});
		
		$(li).addClass('current');
		
    }
    
    if ($('#content_image_homepage')) {
    
    	var number = Math.floor(Math.random()*3)+1
		
		var image = document.createElement('img');
		image.setAttribute('src', 'assets/gfx/roulatie/' + number + '.jpg');
		image.setAttribute('alt', 'Sander de Ponti');
		image.setAttribute('title', 'Sander de Ponti');		

		$('#content_image_homepage').append($(image));
    
    }
    
    $('.back_overview a').click(function() {
    	
		$('.jcarousel-skin-tango').show();	    	
    	$('.addheight').show();		
 	    $('.jcarousel-skin-tango2').addClass('hide');     	
    	$('.paddingtop').toggle();
    	$('.back_overview').toggle();    	
    	
    	var start = $('#mycarousel2').find('.current').index()+1; 
    	 	    
	    var carousel = $('#mycarousel').data('jcarousel');	 
	    carousel.remove();
	    
		$('#mycarousel').jcarousel({
			scroll: 1,
	        start: start,     
	        animation: 300
	    });	    
    	
    	return false;  
	    
    });
   
});
