/* ================================ +
		 	   NATIONAAL GLASMUSEUM
 + ================================ */



/* 
** Made by: Thomas Lievestro
** Email:	info@lievestro.com
** Website:	www.lievestro.com
*/



/* ================================ +
              CARROUSEL
 + ================================ */

/* variables */
//var	CarrouselTimeoutTime = 7000;
var CarrouselTimeoutTime = 5000;
var marginTopCarrouselLink;


// Function for init Carrousel
function initCarrousel(){			

	//start carrousel
	startRotate();
}

// Function for auto Rotate the carrousel
function autoRotate(){
	showItemSlow();
	rotateTimer=setTimeout(function(){
		autoRotate();
	},CarrouselTimeoutTime);
}

// Function for start rotating the carrousel
function startRotate(){
	rotateTimer=setTimeout(function(){
		autoRotate();
	},CarrouselTimeoutTime);
}

// Function for stop rotating the carrousel
function stopRotate(){
	if(typeof rotateTimer != 'undefined'){
		clearTimeout(rotateTimer);
	}
}


// Function for show carrousel item
function showItemSlow(){
	
	//PHOTO
	var activeItem = $('#carrousel_items .carrousel_item.active');
	activeItem.stop();	

    if ( activeItem.length == 0 ) activeItem = $('#carrousel_items .carrousel_item:last');
	

	// use this to pull the divs in the order they appear in the markup
    var nextItem =  activeItem.next().length ? activeItem.next()
        : $('#carrousel_items .carrousel_item:first');

	
	  
	    activeItem.addClass('last-active');
		
	    nextItem.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 800, function() {
	            activeItem.removeClass('active last-active');
	           
	        });
	 
}







/* parse the Jquery functions after document ready */
$(document).ready(function(){
	
	// inet the carrousel
	initCarrousel();	
	
	
	// carrousel on mouse over and out
	$("#carrousel")
	.mouseover(function(){
		//Stop the carrousel
		stopRotate()
		return false;
	})
	.mouseout(function(){
		//Start the carrousel
		startRotate();
		return false;
	})	
	
	
});


