/**
 * @author Antonello Masini
 * 
 * 	www.wmamba.it
 */
//*************************************************************************************
//							Animazione	CORNICE
	var mainpath='http://www.peppinomuggittu.com/';
	var allowcapture=false;
	var capture=-1;
	var tmrcapt=null;
	var lastid=null;
	var w=0;h=0;
	var wmax=350;hmax=350;
	var wmin=200;hmin=200;
	var tmr=null;//timer per campionamento pagine

function StartCapture(id,pos){
	if(!allowcapture)return;
	if(lastid==id || capture==id )return;
	if(tmrcapt!=null){
		clearTimeout(tmrcapt);
		tmrcapt=null;
	}
	capture=id;
	tmrcapt=setTimeout("ZoomIn("+id+",'"+pos+"')",500);
}

function StopCapture(){
	//alert("StopCapture");
	if(capture=-1)return;
	
	clearTimeout(tmrcapt);
	tmrcapt=null;
	capture=-1;
}


function ZoomIn(id,pos){
	if(lastid==id || capture==-1)return;
	StopCapture();
	var crn=document.getElementById("cornice"+id.toString());
	var l=0;
	var t=0;
	switch (pos){
		case "left":
			t=crn.offsetTop+crn.offsetParent.offsetTop-5;
			l=crn.offsetLeft;
			break;
		case "right":
			t=crn.offsetTop+crn.offsetParent.offsetTop-5;
			l=crn.offsetLeft-140;
			break;
		case "bleft":
			t=crn.offsetTop+crn.offsetParent.offsetTop-140;
			l=crn.offsetLeft;
			break;
		case "bright":
			t=crn.offsetTop+crn.offsetParent.offsetTop-140;
			l=crn.offsetLeft-145;
	}
	absCornice.style.top=t+"px";
	absCornice.style.left=l+"px";
	absCrn.src=document.getElementById("crn"+id.toString()).src;
	absImg.src=document.getElementById("img"+id.toString()).src;
	absDesc.innerHTML=document.getElementById("desc"+id.toString()).innerHTML;
	document.getElementById("abslink").href=document.getElementById("link"+id.toString()).href;
	absCornice.style.display="block";
	lastid=id;
}//fine XoomIn

function ZoomOut(){
	absCornice.style.display="none";
	lastid=null;
	clearTimeout(tmrcapt);
	tmrcapt=null;
	capture=-1;
}//fine ZoomOut

function Centra(){
	var box=document.getElementById("boxMain");
	var wbody=document.body.offsetWidth;
	var l=(wbody-850)/2;
	if(l<0)l=15;
	box.style.left=l+"px";
}



//*************************************************************************************
//							Animazione	IMMAGINI PRODOTTI

var cimg=0;
var imgmax=2; //numero massimo di immagini da scansire
var canim=10;
var tmrimg=null;
var imgpath="";
var mtimg=new Array();
for (var i=0; i<4; i++){
	mtimg[i]=new Image();
}


function HideImage(){
	SetAlfa(document.getElementById("img0"));
	SetAlfa(document.getElementById("img1"));
	SetAlfa(document.getElementById("img2"));
	SetAlfa(document.getElementById("img3"));
	if(canim==0){
		clearInterval(tmrimg);
		SetNextImage();
		tmrimg=setInterval("ShowImage()",20);
		return;
	}
	canim--;
}

function ShowImage(){
	SetAlfa(document.getElementById("img0"));
	SetAlfa(document.getElementById("img1"));
	SetAlfa(document.getElementById("img2"));
	SetAlfa(document.getElementById("img3"));
	if(canim==10){
		clearInterval(tmrimg);
		setTimeout("StartImgAnimation()",5000);
		return;
	}
	canim++;
}

function SetNextImage(){
	if(cimg==imgmax){
		cimg=0;
	}else{
		cimg++;
	}
	document.getElementById("img0").src=mtimg[0].src;
	document.getElementById("img1").src=mtimg[1].src;
	document.getElementById("img2").src=mtimg[2].src;
	document.getElementById("img3").src=mtimg[3].src;
	PreloadImg();
}

function PreloadImg(){
	var c=0;
	if(cimg==imgmax){c=0;}else{c=cimg+1;}
	mtimg[0].src=imgpath+"hsq"+c+".jpg";
	mtimg[1].src=imgpath+"edlk"+c+".jpg";
	mtimg[2].src=imgpath+"nrd"+c+".jpg";
	mtimg[3].src=imgpath+"efc"+c+".jpg";
}

function SetAlfa(img){
	if(document.all){
		img.style.filter='alpha(opacity='+(0+canim*10)+')';
	}else{
		img.style.opacity=0+(0.1*canim);
	}
}

function StartImgAnimation(){
	tmrimg=setInterval("HideImage()",20);
}


//************************************************
//impostazioni per animazione info


function NextInfo(){
	if(cinfo==3){cinfo=0;}else{cinfo++;}
	infot=setInterval("MoveRight()",50);
}

function MoveRight(){
	var l=schermo.offsetLeft;
	if(l>=150){
		clearInterval(infot);
		schermo.style.left="150px";
		schermo.innerHTML=document.getElementById("info"+cinfo).innerHTML;
		infot=setInterval("MoveLeft()",50);
		return;
	}
	l+=10;
	schermo.style.left=l+"px";
}

function MoveLeft(){
	var l=schermo.offsetLeft;
	if(l<=0){
		clearInterval(infot);
		schermo.style.left="0px";
		setTimeout("NextInfo()",7000);
		return;
	}
	l-=10;
	schermo.style.left=l+"px";
}


//*********************************************************************************************************
//							Campionamento Pagine

function SetAutoload(value,tm){
	if(value==true){
		tmr=setInterval("Autoload()",tm);
	}else{
		clearInterval(tmr);
		tmr=null;
	}
}
//*********************************************************************************************************	
function Autoload(){
	clearInterval(tmr);
	tmr=null;
	window.location.replace(""+mainpath+"lib/rndpg.php");
}


