/* ================================ +
		NATIONAAL GLASMUSEUM
 + ================================ */



/* 
** Made by: Thomas Lievestro
** Email:	info@lievestro.com
** Website:	www.lievestro.com
*/


/* ================================ +
              Variables
 + ================================ */

var currentImage = 0;
var busy = false;


// Function to scroll to the left in photoviewer
function scrollLeft(){

	if(0 < currentImage-2){
		
		currentImage = currentImage - 2; 
		$('#navigation_items').scrollTo($('#navigation_items_inner').find('.navigation_item')[currentImage], 500, {easing:'easeOutCirc'} );
		
	}else if(0 <= currentImage-1){
		currentImage = currentImage - 1;
		$('#navigation_items').scrollTo($('#navigation_items_inner').find('.navigation_item')[currentImage], 500, {easing:'easeOutCirc'} );
	}
	
	
	if(0 == currentImage){
		$('#previous_button').attr('id', 'previous_button_inactive');
	}else if($('#next_button_inactive')){
		$('#next_button_inactive').attr('id', 'next_button');
	}
}

// Function to scroll to the right in photoviewer
function scrollRight(){

	var photo_total = $('#photo_total').val();
	
	if(photo_total-1 > currentImage+2){
		
		currentImage = currentImage + 2; 
		$('#navigation_items').scrollTo($('#navigation_items_inner').find('.navigation_item')[currentImage], 500, {easing:'easeOutCirc'} );
		
	}else if(photo_total-1 >= currentImage+1){
		currentImage = currentImage + 1;
		$('#navigation_items').scrollTo($('#navigation_items_inner').find('.navigation_item')[currentImage], 500, {easing:'easeOutCirc'} );
	}
	
	
	if(photo_total-1 == currentImage){
		$('#next_button').attr('id', 'next_button_inactive');
	}else if($('#previous_button_inactive')){
		$('#previous_button_inactive').attr('id', 'previous_button');
	}
}


function goTo(item){
	//check if goTo is busy
	if(busy == false){
		//set busy = true
		busy = true;
		
		$('#zoom_button').fadeOut(50);
		//remove link from zoom button
		$('#zoom_button').removeAttr('href');
		
		//remove active class from active navigation_item
		$('.navigation_item.active').removeClass('active');
		//add active class to new active navigation item
		$(item).addClass('active');

		//get src from image of navigation item
		var src = $('.navigation_item.active a:first img:first').attr('src');
		//split src to array
		var name = src.split("/");
		
		
		
		//fade out old image in 0.1 seconden
		$('#big_view img:first').animate({
			opacity: 0.0
		}, 100, function(){
		
			//show loader
			var loaderTimeout = window.setTimeout(function(){
				$('#loader').show();
			},1000);
			
			//Preload big image
			imageObj = new Image();							
			imageObj.src = "footage/img/360x445/"+name[3];   
		
			//If image is loaded
			imageObj.onload = function() {  
				
				//add new big_view image (opacity:0) now the real big image
				$('#big_view img').after('<img width="360" src="footage/img/360x445/'+name[3]+'" style="opacity:0;"/>');
				
				//clear timeout and hide loader 
				window.clearTimeout(loaderTimeout);
				$('#loader').hide();
				
				//fade in new image in 1 seconden
				$('#big_view img:last').animate({
					opacity: 1.0
				}, 1000, function(){ 
					//remove old image
					$('#big_view img:first').remove();
										
					$('#zoom_button').fadeIn(200);
					
					//add href to zoom button
					$('#zoom_button').attr('href','footage/img/360x445/'+name[3]+'');
					//set busy = true
					busy = false;
				});
			} 
		});
	}
}


function showTooltip(item){
	var item = item.getElementsByTagName("a")[0];
	var alt = $(item).attr('title');
	
	$(item).ezpz_tooltip(alt);
	
}
	
function hideTooltip(id){

}






/* parse the Jquery functions after document ready */
$(document).ready(function(){
	
	// previous button
	$("#previous_button")
	.click(function(){
		scrollLeft();
		return false;
	});
	
	// next button
	$("#next_button")
	.click(function(){
		scrollRight();
		return false;
	});
	
	// navigation item
	$(".collection_detail .navigation_item")
	.click(function(){
		//goTo(this);
		//return false;
	})
	.mouseover(function(){
		//showTooltip(this);
	})
	.mouseout(function(){
		//hideTooltip(this);
	})		
	
	
	// make previous_button inactive
	$('#previous_button').attr('id', 'previous_button_inactive');
	
});
  

