// JavaScript Document


var tabCLick= true;
var idYear
var ciclo = 1
$(document).ready(function() {
	
	$("#scrollHistory").scrollable({easing: 'swing', speed: 2600, circular: false})
	
	$(".textContainer p").empty();
	$(".imgYears").empty();
	
	
	$('#readBox').css ({display: "none"})
	$('#readBox').css ({opacity: 0})
	
	$(".items a").click(function(){
			
			
			idYear = this.id
			
			if(ciclo == 1)
			{
				changeHTML()
				ciclo = 2
			}else{
				exitText()		
			}
			
			
			

	})
	
	$("#history #closeYear").click(function(){
		
		tabCLick = false
		
		exitText()
		
		$('#history').removeClass().addClass('normal');

	})
	
	
	
});

function changeHTML(){
	
	switch(idYear)
	
	{
	case '1800': caption = year1800;
	break;
	case '1838': caption =  year1838;
	break;
	case '1873': caption =  year1873;
	break;
	case '1885': caption =  year1885;
	break;
	case '1889': caption =  year1889;
	break;
	case '1892': caption =  year1892;
	break;
	case '1899': caption =  year1899;
	break;
	case '1900': caption =  year1900;
	break;
	case '1944': caption =  year1944;
	break;
	case '1947': caption =  year1947;
	break;
	case '1948': caption =  year1948;
	break;
	case '1953': caption =  year1953;
	break;
	case '1958': caption = year1958;
	break;
	case '1960': caption =  year1960;
	break;
	case '1968': caption =  year1968;
	break;
	case '1987': caption =  year1987;
	break;
	case '1989': caption =  year1989;
	break;
	case '1994': caption =  year1994;
	break;
	case '1997': caption =  year1997;
	break;
	case '1998': caption =  year1998;
	break;
	case '2000': caption =  year2000;
	break;
	case '2003': caption =  year2003;
	break;
	case '2004': caption =  year2004;
	break;
	case '2006': caption =  year2006;
	break;
	case '2007': caption =  year2007;
	break;
	case '2008': caption =  year2008;
	break;
	case '2009': caption =  year2009;
	break;
	}
	
	
	$('#readBox').css ({display: "block"})
	
	//$('#readBox').css ({opacity: .1})
	//alert("finito")
	var pathIMG = '<img src="img/title_'+ idYear +'.png" alt="'+ idYear + '">'
	
	$(".textContainer p").html(caption)
	$(".titleYear").html(idYear + " - Il sapore della storia.")
	$(".imgYears").html(pathIMG)
	
	$('#readBox').animate({"opacity":1, "right":0}, 1100,function(){
																		 
		$('#history').removeClass().addClass('feather');
		tabCLick = true
		
	});
	

	

}

function exitText(){
	
	$('#readBox').animate({"opacity": 0, "right":-150}, 1000,function(){
			
			$(".textContainer p").empty();
			$(this).css({display:"none"})
			//$('#readBox').css ({opacity: 0})
			$(this).css({right:150});
			
			if(tabCLick == true){
				
				changeHTML()
				
			}else{
				
				ciclo = 1
				tabCLick = false

			}
	
			
			
		});
	
	
	
	
	
}
