// JavaScript Document Dimensione Parquet
var numImages=0;
var currentImage=0;
var rotationInterval=3000;
var myInterval=0;

function moveScritta(){
	$("#scritta").animate({
			opacity: 1,
			left:"+=100px",
			top:"+=50px",}, 
			10000
		).delay(5000);
	
	$("#scritta").animate({
		opacity: 0
		},
		3000
		);
     $("#scritta").animate({
		 left:"-=100px",
		 top:"-=50px",}, 
		 1
		);
	  		
}

function rotateImage() {
	 currentImage++; 
	 if(currentImage >= numImages) currentImage=0;
	 $("#bigImage img")[0].src=$("#thumbsList img")[currentImage].src;
	
	 $("#bigImage img").last().fadeOut("slow", function (){
      		$("#bigImage img")[1].src=$("#bigImage img")[0].src;
	  		$("#bigImage img")[1].style.display="block";
	  		$("#bigImage img")[1].style.visibility="visible";
	  });
	 
	 //window.setInterval("rotateImage", rotationInterval);
}

function closeAll() {
	$("#ChiSiamo").fadeOut("slow");
	$("#Realizzazioni").fadeOut("slow");
	$("#Contatti").fadeOut("slow");
	$("#Prodotti").fadeOut("slow");
	
	showProdotti=false;
	showContatti=false;
	showProdotti=false;
	showRealizzazioni=false;	
}

 $(document).ready(function (){ 
          //Recupero il numero delle immagini
		  numImages=$('#thumbsList img').length;
		  
  		  var showProdotti=false;
		  var showChiSiamo=false;
		  var showContatti=false;
		  var showRealizzazioni=false;
		  
		  var topIndex=100;
		  
		  $('#supersize').supersized(); 
		  
		  //Funzioni per la finestra ChiSiamo
		  $("#ChiSiamo").draggable({ handle:'.TopBar' });
		   $("#ChiSiamo .TopBar").click(function() {
			  	$("#ChiSiamo")[0].style.zIndex=topIndex++;
		   });
		  $("#ChiSiamo .TopBar img").click(function() {
			  	$("#ChiSiamo").fadeOut("slow");
				showChiSiamo=false;
		   });
		  
		   //Link per l'apertura della finestra ChiSiamo
		  $("#buttonChiSiamo").click(function () {
			    closeAll();
			  	if(!showChiSiamo) 
				{
					$(".buttons").fadeOut("slow");
					showChiSiamo = showRealizzazioni = showContatti = showProdotti = false;
					$("#ChiSiamo").fadeIn("slow");
					$("#ChiSiamo")[0].style.zIndex=topIndex++;
				}
				else $("#ChiSiamo").fadeOut("slow");
				showChiSiamo=!showChiSiamo;
			  });
		  
		  
		  
		   //Funzioni per la finestra Realizzazioni
		  $("#Realizzazioni").draggable({ handle:'.TopBar' });
		   $("#Realizzazioni .TopBar").click(function() {
			  	$("#Realizzazioni")[0].style.zIndex=topIndex++;
		   });
		  $("#Realizzazioni .TopBar img").click(function() {
			  	$("#Realizzazioni").fadeOut("slow");
				showRealizzazioni=false;
		   });
		  
		   //Link per l'apertura della finestra Realizzazioni
		  $("#buttonRealizzazioni").click(function () {
			  	closeAll();
			  	if(!showRealizzazioni) 
				{
					$(".buttons").fadeOut("slow");
					showChiSiamo = showRealizzazioni = showContatti = showProdotti = false;
					$("#Realizzazioni").fadeIn("slow");
					$("#Realizzazioni")[0].style.zIndex=topIndex++;
					myInterval=setInterval("rotateImage()", rotationInterval);
				}
				else 
				{
					$("#Realizzazioni").fadeOut("slow");
					window.clearInterval(myInterval);
				}
				showRealizzazioni=!showRealizzazioni;
			  });
		  
		  
		  //Funzioni per la finestra Contatti
		  $("#Contatti").draggable({ handle:'.TopBar' });
		   $("#Contatti .TopBar").click(function() {
			  	$("#Contatti")[0].style.zIndex=topIndex++;
		   });
		  $("#Contatti .TopBar img").click(function() {
			  	$("#Contatti").fadeOut("slow");
				showContatti=false;
		   });
		  
		   //Link per l'apertura della finestra Contatti
		  $("#buttonContatti").click(function () {
			  	closeAll();
			  	if(!showContatti) 
				{
					$(".buttons").fadeOut("slow");
					showChiSiamo = showRealizzazioni = showContatti = showProdotti = false;
					$("#Contatti").fadeIn("slow");
					$("#Contatti")[0].style.zIndex=topIndex++;
				}
				else $("#Contatti").fadeOut("slow");
				showContatti=!showContatti;
			  });
		  
		  
		  
		  
		  //Funzioni per la finestra Prodotti
          $("#Prodotti").draggable({ handle:'.TopBar' });
		  $("#Prodotti .TopBar").click(function() {
			  $("#Prodotti")[0].style.zIndex=topIndex++;
		  });
		  
		  $("#Prodotti .TopBar a").click(function() {
			  $("#Prodotti").fadeIn("slow", function() {
						$.ajax({
							type: "GET",
							url: "php/prodotti.php",
							data: "IDCollezione=all",
							success: function(response){
							$("#Prodotti .Body").html(response);
							
							$(".collezione").click(function() { 
								  $("#Prodotti .Menu").slideUp("slow");
								  $(this).find(".Menu").slideDown("slow");
							  });
							}
							});
					});
		  });
		  $("#Prodotti .TopBar img").click(function() {
			  	$("#Prodotti").fadeOut("slow");
				showProdotti=false;
		   });
		    
		   //Link per l'apertura della finestra Prodotti
		  $("#buttonProdotti").click(function () {
			    closeAll();
			  	if(!showProdotti) 
				{
					$(".buttons").fadeOut("slow");
					showChiSiamo = showRealizzazioni = showContatti = showProdotti = false;
					$("#Prodotti").fadeIn("slow", function() {
						$.ajax({
							type: "GET",
							url: "php/prodotti.php",
							data: "IDCollezione=all",
							success: function(response){
							$("#Prodotti .Body").html(response);
							
							$(".collezione").click(function() {
								  $("#Prodotti .Menu").slideUp("slow");
								  $(this).find(".Menu").slideDown("slow");
							  });
							 $("#Gaia").click(function() {
								 window.open("http://www.treelifelab.com","treeLifeLab","width=1024,height=768, scrollbars=yes");  
							});
							}
							});
					});
					$("#Prodotti")[0].style.zIndex=topIndex++;
				}	
				else $("#Prodotti").fadeOut("slow");
				showProdotti=!showProdotti;
			  });
	      
		  
		  
		  
		  //ThumbList
		  //Ingrandimento dell'immagine
		  $("#thumbsList li").mouseover(function() {
			  	if(myInterval!=0) 
				{
				  window.clearInterval(myInterval);
				  myInterval=0;
				}
			  	$(this).find("img")[0].style.width="80px";
				$(this).find("img")[0].style.height="50px";
		  });
		  
		  //Resize dimensione normale
		  $("#thumbsList li").mouseout(function() {
			 if(!myInterval) myInterval=setInterval("rotateImage()", rotationInterval);
			  $(this).find("img")[0].style.width="68px";
			  $(this).find("img")[0].style.height="38px";
		  });
		  
		  //Click (cambio immagine)
		  $("#thumbsList li").click(function() {
			  $("#bigImage img")[0].src=$(this).find("img")[0].src;
			  $("#bigImage img").last().fadeOut("slow", function (){
				  	$("#bigImage img")[1].src=$("#bigImage img")[0].src;
					$("#bigImage img")[1].style.display="block";
					$("#bigImage img")[1].style.visibility="visible";
			  });
		  });
		  
		  $("#bigImage img").mouseover(function() {
			  if(myInterval!=0) 
			  {
				  window.clearInterval(myInterval);
				  myInterval=0;
			  }
		  });
		  
		  $("#bigImage img").mouseout(function() {
			  if(!myInterval) myInterval=setInterval("rotateImage()", rotationInterval);
		  });
		  
		  
		  //Scritta in movimento
		  moveScritta();
	      //window.setInterval(moveScritta,25000);
  });
