// JavaScript Document

function topClick(n){
	name=document.getElementById("imt-"+n).src;
	if(name.indexOf(",")!=-1){
		namex=name.split(",");
		ext=namex[namex.length-1];
	}else{
		namex=name.split(".");
		ext=namex[namex.length-1];
	}
	name1=document.getElementById("imt-"+n).src.replace("."+ext,"_b."+ext);
	document.getElementById("l-content").innerHTML="<img src='"+name1+"' class='gallery'/>";	
	document.getElementById("img-top-"+n).style.backgroundColor=bgOver;
	document.getElementById("img-top-"+n).style.bottom="25px";

	if((document.getElementById("img-top-"+top)!=null)&&(top!=n)){		
		document.getElementById("img-top-"+top).style.backgroundColor=bgColor;
		switch(top){
			case 1: document.getElementById("img-top-"+top).style.bottom="-25px"; break;
			case 2: document.getElementById("img-top-"+top).style.bottom="-30px"; break;
			case 3: document.getElementById("img-top-"+top).style.bottom="-35px"; break;
			case 4: document.getElementById("img-top-"+top).style.bottom="-25px"; break;
			case 5: document.getElementById("img-top-"+top).style.bottom="-30px"; break;
			case 6: document.getElementById("img-top-"+top).style.bottom="-20px"; break;
			case 7: document.getElementById("img-top-"+top).style.bottom="-40px"; break;
			case 8: document.getElementById("img-top-"+top).style.bottom="-35px"; break;
		}
	}
	top=n;
}
function rightClick(n){
	switch(n){
		case 1: location.href='home.php'; break;
		case 2: url='storia.php'; $('#home').css('background','url(img/sfondo13.jpg) 0px 150px no-repeat'); break;
		case 3: url='cucina.php'; $('#home').css('background','url(img/sfondo10.jpg) 0px 150px no-repeat'); break;
		case 4: url='dove.php'; $('#home').css('background','url(img/sfondo7.jpg) 0px 150px no-repeat');break;
		case 5: url='galleria.php'; $('#home').css('background','url(img/sfondo12.jpg) 0px 150px no-repeat'); break;
		case 6: url='articoli.php'; $('#home').css('background','url(img/sfondo11.jpg) 0px 150px no-repeat'); break;
		case 7: window.open('http://blog.ristorantetrere.it','_blank'); return false;
		case 8: url='form.php'; $('#home').css('background','url(img/sfondo9.jpg) 0px 150px no-repeat'); break;
	}
	$.ajax({
	  	url: url,
	  	success: function(data) {
			$('#l-content').html(data);
	  	}
	});
	
	if(right!=n){
		document.getElementById("img-right-"+n).style.left="20px";
		//document.getElementById("imr-"+n).src=menuImg;
		//$(document.getElementById("imr-txt-"+right)).toggleClass("active").slideToggle("slow");
	//	$(document.getElementById("imr-txt-"+n)).toggleClass("active").slideToggle("slow");
	}
	if((document.getElementById("imr-"+right)!=null)&&(right!=n)){	
		//document.getElementById("imr-"+right).src=whiteImg;
		document.getElementById("imr-txt-"+right).style.color="#D4A017";
		switch(right){
			case 1: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 2: document.getElementById("img-right-"+right).style.left="-15px"; break;
			case 3: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 4: document.getElementById("img-right-"+right).style.left="-25px"; break;
			case 5: document.getElementById("img-right-"+right).style.left="-15px"; break;
			case 6: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 7: document.getElementById("img-right-"+right).style.left="-25px"; break;
			case 8: document.getElementById("img-right-"+right).style.left="-20px"; break;
		}
	}
	right=n;
}
$(window).ready(function(){

	//Hide (Collapse) the toggle containers on load
/*	$("#imr-txt-1").hide(); 
	$("#imr-txt-2").hide(); 
	$("#imr-txt-3").hide(); 
	$("#imr-txt-4").hide(); 
	$("#imr-txt-5").hide(); 
	$("#imr-txt-6").hide(); 
	$("#imr-txt-7").hide(); 
	$("#imr-txt-8").hide(); */
	
	$("#logo").click(function(){
		location.href='home.php';
	});
	$("#logo").mouseover(function(){
		document.getElementById("logo").style.cursor='pointer';
	});
	$("#logo").mouseout(function(){
		document.getElementById("logo").style.cursor='default';
	});	
	$('div[id*="img-right-"]').mouseenter(function(event){
		this.style.cursor="pointer";
		if(this!=document.getElementById("img-right-"+right)){
			id=event.currentTarget.id;
			id=id.replace("g-right","r-txt");
			//$(document.getElementById(id)).toggleClass("active").slideToggle("fast");
			document.getElementById(id).style.color="white";
		}
		//$(this).children("img").attr('src',menuImg);
	});
	$('div[id*="img-right-"]').mouseleave(function(event){
		this.style.cursor="default";
		if(this!=document.getElementById("img-right-"+right)){
			id=event.currentTarget.id;
			id=id.replace("g-right","r-txt");
			//$(document.getElementById(id)).toggleClass("active").slideToggle("fast");
			document.getElementById(id).style.color="#D4A017";
			//$(this).children("img").attr('src',whiteImg);
		}
	});
	
	
	
	$('div[id*="imr-txt-"]').mouseenter(function(event){
		this.style.cursor="pointer";
		if(this!=document.getElementById("imr-txt-"+right)){
			id=event.currentTarget.id;
			id=id.replace("g-right","r-txt");
			//$(document.getElementById(id)).toggleClass("active").slideToggle("fast");
			document.getElementById(id).style.color="white";
		}
		//$(this).children("img").attr('src',menuImg);
	});
	$('div[id*="imr-txt-"]').mouseleave(function(event){
		this.style.cursor="default";
		if(this!=document.getElementById("imr-txt-"+right)){
			id=event.currentTarget.id;
			id=id.replace("g-right","r-txt");
			//$(document.getElementById(id)).toggleClass("active").slideToggle("fast");
			document.getElementById(id).style.color="#D4A017";
			//$(this).children("img").attr('src',whiteImg);
		}
	});
	
	
	document.getElementById("img-right-1").style.left="20px";
	//document.getElementById("imr-1").src=menuImg;
	//$(document.getElementById("imr-txt-"+right)).toggleClass("active").slideToggle("slow");
	//$(document.getElementById("imr-txt-1")).toggleClass("active").slideToggle("slow");
	document.getElementById("imr-txt-1").style.color="white";
	if((document.getElementById("imr-"+right)!=null)&&(right!=n)){	
		document.getElementById("imr-"+right).src=whiteImg;
		switch(right){
			case 1: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 2: document.getElementById("img-right-"+right).style.left="-15px"; break;
			case 3: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 4: document.getElementById("img-right-"+right).style.left="-25px"; break;
			case 5: document.getElementById("img-right-"+right).style.left="-15px"; break;
			case 6: document.getElementById("img-right-"+right).style.left="-20px"; break;
			case 7: document.getElementById("img-right-"+right).style.left="-25px"; break;
			case 8: document.getElementById("img-right-"+right).style.left="-20px"; break;
		}
	}
	right=1;
	
	
});
function topOver(x){
	$(x).css('background-color',bgOver);
}
function topOut(x){
	if(x!=document.getElementById("img-top-"+top))
		$(x).css('background-color',bgColor);
}
function loadStoria(){
	
	html='<div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-1" id="img-top-1" onclick="topClick(1);"><img alt="storia 1" id="imt-1" src="storia/1.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-2" id="img-top-2" onclick="topClick(2);"><img alt="storia 2" id="imt-2" src="storia/2.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-3" id="img-top-3" onclick="topClick(3);"><img alt="storia 3" id="imt-3" src="storia/3.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-4" id="img-top-4" onclick="topClick(4);"><img alt="storia 4" id="imt-4" src="storia/4.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-5" id="img-top-5" onclick="topClick(5);"><img alt="storia 5" id="imt-5" src="storia/5.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-6" id="img-top-6" onclick="topClick(6);"><img alt="storia 6" id="imt-6" src="storia/6.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-7" id="img-top-7" onclick="topClick(7);"><img alt="storia 7" id="imt-7" src="storia/7.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-8" id="img-top-8" onclick="topClick(8);"><img alt="storia 8" id="imt-8" src="storia/8.jpg" /></div>'
	$("#l-top").html(html);
	
}
function loadDove(){
	
	html='<div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-1" id="img-top-1" onclick="topClick(1);"><img alt="storia 1" id="imt-1" src="dove/1.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-2" id="img-top-2" onclick="topClick(2);"><img alt="storia 2" id="imt-2" src="dove/2.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-3" id="img-top-3" onclick="topClick(3);"><img alt="storia 3" id="imt-3" src="dove/3.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-4" id="img-top-4" onclick="topClick(4);"><img alt="storia 4" id="imt-4" src="dove/4.jpg" /></div>'
	$("#l-top").html(html);
	
}
function loadCucina(){ 
	cucina=0;
	html='<div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-1" id="img-top-1" onclick="topClick(1);"><img alt="cucina 1" id="imt-1" src="cucina/1.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-2" id="img-top-2" onclick="topClick(2);"><img alt="cucina 2" id="imt-2" src="cucina/2.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-3" id="img-top-3" onclick="topClick(3);"><img alt="cucina 3" id="imt-3" src="cucina/3.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-4" id="img-top-4" onclick="topClick(4);"><img alt="cucina 4" id="imt-4" src="cucina/4.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-5" id="img-top-5" onclick="topClick(5);"><img alt="cucina 5" id="imt-5" src="cucina/5.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-6" id="img-top-6" onclick="topClick(6);"><img alt="cucina 6" id="imt-6" src="cucina/6.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-7" id="img-top-7" onclick="topClick(7);"><img alt="cucina 7" id="imt-7" src="cucina/7.jpg" /></div><div onmouseover="topOver(this);" onmouseout="topOut(this);" class="img-top bordered rotate-8" id="img-top-8" onclick="topClick(8);"><img alt="cucina 8" id="imt-8" src="cucina/8.jpg" /></div>'
	$("#l-top").html(html);
}
function cucinaClick(n){
	if(cucina!=n){
		/*document.getElementById("cucina-"+n).style.color="#fff";
		document.getElementById("cucina-"+cucina).style.color="#ff0";*/
		$(document.getElementById("cucina-"+cucina)).toggleClass("active").slideToggle("slow");
		$(document.getElementById("cucina-"+n)).toggleClass("active").slideToggle("slow");
	}
	cucina=n;		
}
function loadGalleria(){
	galleria=-1;
	galleriaImg=0;
	galleriaMax=0;	
}
function galleriaClick(n,m){
	galleriaMax=m;
	galleriaImg=0;
	if(galleria!=n){
		/*document.getElementById("cucina-"+n).style.color="#fff";
		document.getElementById("cucina-"+cucina).style.color="#ff0";*/
		$(document.getElementById("galleria-"+cucina)).toggleClass("active").slideToggle("slow");
		$(document.getElementById("galleria-"+n)).toggleClass("active").slideToggle("slow");
	}
	galleria=n;		
	galleriaNext(n);
}
function galleriaNext(n){
	$.ajax({
		type: "POST",
	    data: "action=get&id="+n+"&offset="+(8*galleriaImg),
	  	url: "galleria.php",
	  	success: function(data) {
			$('#l-top').html(data);
	  	}
	});
}
function Next(){
	if(galleriaImg<galleriaMax){
		galleriaImg+=1;	
		galleriaNext(galleria);
	}
}
function Prev(){
	if(galleriaImg>0){
		galleriaImg-=1;	
		galleriaNext(galleria);
	}
}


