$(function(){
	setTimeout('rotate()',1000);
	
	$('#viewport').css('height',$(window).height()-521);
	$('#viewport li').css('height',$(window).height()-521);
	
	/*
	$('#menu a').stop(true,true).hover(function(){
		$(this).animate({opacity:1.0},500);
	},function(){
		$(this).animate({opacity:0.7},500);
	});
	
	if(location.href.indexOf('menukaart') != -1 || location.href.indexOf('wijnkaart') != -1 || location.href.indexOf('drankkaart') != -1){
		$('#viewport').css('height',100);
		$('#viewport li').css('height',100);
		$('#container').css('height',871);
		
		$('.frame_menu').hide();
		
		if(location.href.indexOf('menukaart') != -1){
			$('#frame_menukaart').show();
		}else if(location.href.indexOf('wijnkaart') != -1){
			$('#frame_wijnkaart').show();
		}else if(location.href.indexOf('drankkaart') != -1){
			$('#frame_drankkaart').show();
		}
	}
	*/
});

function rotate() {	
	//Get the first image
	var current = ($('ul#viewport li.show') ? $('ul#viewport li.show') : $('ul#viewport li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('ul#viewport li:first') :current.next()) : $('ul#viewport li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	if($('ul#viewport li').size() == 4){
		next.addClass('show').fadeIn(500);
	}else{
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 3500);
	}
	

	//Hide the current image
	current.removeClass('show').animate({opacity: 0.0}, 3500, function(){ 
		if($('ul#viewport li').size() == 4){
			$('ul#viewport li:first').remove();
		}
		
		setTimeout('rotate()',5000);
	});
	
};

