//<![CDATA[
function sendMail() {
	var add=["info",["nare","it"].join(".")];
	var loc=["mailto",add.join("@")];
	self.location.href=loc.join(":");
	return false;
};



function photoPopupOpen(imageSrc,container) {
	var playing=(container.state=="play");
	if (playing) container.pause();
	document.getElementById("selectedPhotoContainer").innerHTML='<h6><a href="#" title="Chiudi la foto e torna alla presentazione">Chiudi</a></h6><p><img src="'+imageSrc+'" alt="Immagine" /></p>';
	document.getElementById("selectedPhotoContainer").style.display='block';
	document.getElementById("selectedPhotoContainer").getElementsByTagName("A")[0].onclick=function() {
		document.getElementById("selectedPhotoContainer").style.display='';
		if (playing) setTimeout(container.play,500);
		return false;
		};
	};
function photoshow(contId,contControlId,vStep,vTime,hStep,hTime,time,photoClickFunc,maxTrials,errorMessage) {
	if (!document.getElementById) return null;
	if (!(this.contObj=document.getElementById(contId)) || !(this.controlObj=document.getElementById(contControlId))) return null;
	if (!this.contObj.style || !this.contObj.innerHTML) return null;
	this.errorMessage=(errorMessage?errorMessage:"<div class='message'><p>Impossibile caricare la galleria fotografica</p></div>");
	this.obj=null; this.img=null;
	this.width=function() {return this.obj.offsetWidth};
	this.height=function() {return this.obj.offsetHeight};
	this.hScope=function() {return Math.floor(this.width()/2)};
	this.vScope=function() {var h=Math.floor(this.height()/2); return (h==this.height()/2)?(h-1):h};
	this.clippingState="vert"; this.hOffset=0; this.vOffset=0; this.showNext=false;
	this.hStep=hStep?hStep:20; this.hTime=hTime?hTime:5;
	this.vStep=vStep?vStep:20; this.vTime=vTime?vTime:5;
	this.time=time?time:2000;
	this.images=new Array(); this.bigImagesSrc=new Array(); this.loaded=0; this.currentImage=null; this.complete=false; this.intervalId=null; this.clipTimerId=null; this.state="stop";
	this.trials=0; this.maxTrials=(maxTrials?maxTrials:400);
	this.start=function(aImageSrcs) {
		this.clippingState="vert"; this.hOffset=0; this.vOffset=0; this.showNext=false; this.state="stop"; clearInterval(this.intervalId); clearTimeout(this.clipTimerId);
		if (aImageSrcs) this.loadGallery(aImageSrcs);
		if (document.getElementById(this.contObj.id+"_progressBar")) document.getElementById(this.contObj.id+"_progressBar").style.width=(Math.floor((this.loaded*100)/this.images.length)+"%")
		else this.contObj.innerHTML="<div class='message'><div class='text'>Attendere il caricamento della galleria</div><div id='"+this.contObj.id+"_progressBar' class='bar'>&nbsp;</div></div>";
		if (this.images.length==0) this.contObj.innerHTML="<div class='message'>Nessuna immagine nella galleria</div>"
		else if (this.loaded==this.images.length) {
			this.complete=true;
			this.contObj.innerHTML='<div id="'+this.contObj.id+'_imgContainer" class="imgOutWrap"><div class="imgInWrap"><img id="'+this.contObj.id+'_imgContent" src="'+this.images[0].src+'" alt="Immagine" /></div></div>';
			this.obj=document.getElementById(this.contObj.id+'_imgContainer'); this.img=document.getElementById(this.contObj.id+'_imgContent');
			var thisObj=this;
			if (photoClickFunc) this.img.onclick=function() {photoClickFunc(thisObj.bigImagesSrc[currentImage],thisObj)};
			this.obj.style.position="absolute"; this.obj.style.top="0"; this.obj.style.left="0";
			}
		else if (this.trials>this.maxTrials) this.contObj.innerHTML=this.errorMessage
		else {
			this.trials+=1;
			var thisObj=this;
			setTimeout(function(){thisObj.start()},50);
			};
		};
	this.appendPhoto=function(oImg) {
		if (!this.complete) return true;
		this.images[this.images.length]=oImg;
		if (this.currentImage==null) this.currentImage=0;
		return false;
		};
	this.notifyLoad=function() {
		this.loaded+=1;
		};
	this.loadGallery=function(aImageSrcs) {
		this.images.length=0; this.bigImagesSrc.length=0; this.loaded=0; this.currentImage=null; this.complete=false; clearInterval(this.intervalId);
		var thisObj=this;
		for (var i=0; i<aImageSrcs[0].length; i++) {
			this.images[i]=new Image();
			this.images[i].onload=function(){thisObj.notifyLoad()};
			this.images[i].onerror=function(){alert("errore caricamento immagine "+this.src)};
			this.images[i].src=aImageSrcs[0][i];
			this.bigImagesSrc[i]=aImageSrcs[1][i];
			};
		this.currentImage=0;
		};
	this.clipEffect=function() {
		if (!this.complete) return true;
		switch (this.clippingState) {
			case "vert":
				this.obj.style.visibility="hidden";
				this.obj.style.clip=("rect("+this.hOffset+"px,"+(this.width())+"px,"+(this.height()-this.hOffset)+"px,0px)");
				this.obj.style.visibility="visible";
				if (this.hOffset<this.vScope() && (this.hOffset+this.vStep)>this.vScope()) this.hOffset=this.vScope()
				else if (this.hOffset>=this.vScope()) {
					this.hOffset=this.vScope();
					this.clippingState="horiz"
					}
				else this.hOffset+=this.vStep;
				var thisObj=this;
				this.clipTimerId=setTimeout(function(){thisObj.clipEffect()},this.vTime);
				break;
			case "horiz":
				this.obj.style.visibility="hidden";
				this.obj.style.clip=("rect("+this.vScope()+"px,"+(this.width()-this.vOffset)+"px,"+(this.height()-this.vScope())+"px,"+this.vOffset+"px)");
				this.obj.style.visibility="visible";
				if (this.vOffset<this.hScope() && (this.vOffset+this.hStep)>this.hScope()) this.vOffset=this.hScope()
				else if (this.vOffset>=this.hScope()) {
					this.vOffset=this.hScope();
					this.clippingState="finished";
					clearTimeout(this.clipTimerId);
					}
				else this.vOffset+=this.hStep;
				var thisObj=this;
				this.clipTimerId=setTimeout(function(){thisObj.clipEffect()},this.hTime);
				break;
			default:
				this.clippingState="vert"; this.hOffset=0; this.vOffset=0;
				if (this.showNext) {
					this.img.src=this.images[this.currentImage].src;
					var thisObj=this;
					this.clipTimerId=setTimeout(function(){thisObj.restoreClip()},300);
					this.showNext=false;
					};
			};
		return false;
		};
	this.restoreClip=function() {
		if (!this.complete) return true;
		this.obj.style.visibility="hidden";
		this.obj.style.clip=("rect(0px,"+this.width()+"px,"+this.height()+"px,0px)");
		this.obj.style.visibility="visible";
		this.controlObj.getElementsByTagName("P")[0].innerHTML='Immagine '+(this.currentImage+1)+' di '+this.images.length
		return false;
		};
	this.nextPhoto=function() {
		if (this.images.length==0 || this.currentImage>=this.images.length || !this.complete) return true;
		this.currentImage=(this.currentImage>=this.images.length-1)?(0):(this.currentImage=this.currentImage+1);
		this.showNext=true;
		return this.clipEffect();
		};
	this.prevPhoto=function() {
		if (this.images.length==0 || this.currentImage>=this.images.length || !this.complete) return true;
		this.currentImage=(this.currentImage<=0)?(this.images.length-1):(this.currentImage=this.currentImage-1);
		this.showNext=true;
		return this.clipEffect();
		};
	this.play=function() {
		if (!this.complete) return true;
		if (this.state=="play") return false;
		this.state="play";
		this.enableAllControlsBut("play");
		var thisObj=this;
		clearInterval(this.intervalId);
		if (!thisObj.nextPhoto()) {
			this.intervalId=setInterval(function(){thisObj.nextPhoto()},this.time);
			return false;
			}
		else return true;
		};
	this.pause=function() {
		if (!this.complete) return true;
		if (this.state=="pause") return false;
		this.state="pause";
		this.enableAllControlsBut("pause");
		clearInterval(this.intervalId);
		return false;
		};
	this.stop=function() {
		if (!this.complete) return true;
		if (this.state=="stop") return false;
		this.state="stop";
		this.enableAllControlsBut("stop");
		clearInterval(this.intervalId);
		this.currentImage=0;
		this.showNext=true;
		return this.clipEffect();
		};
	this.enableAllControlsBut=function(controlName) {
		var controlElement=document.getElementById(this.controlObj.id+'_controlButtons').firstChild;
		while (controlElement) {
			if (controlElement.firstChild.id.indexOf(controlName)!=-1) controlElement.firstChild.className="active"
			else controlElement.firstChild.className="";
			controlElement=controlElement.nextSibling;
			};
		return;
		};
	this.showControl=function() {
		var thisId=this.controlObj.id;
		var hs='';
		hs+='<ul id="'+thisId+'_controlButtons">';
		hs+='<li><a id="'+thisId+'_prev" href="#" title="Mostra la foto precedente"><span>Precedente</span></a></li>';
		hs+='<li><a id="'+thisId+'_next" href="#" title="Mostra la foto successiva"><span>Successiva</span></a></li>';
		hs+='<li><a class="active" id="'+thisId+'_stop" href="#" title="Ferma la presentazione di tutte le foto"><span>Stop</span></a></li>';
		hs+='<li><a id="'+thisId+'_play" href="#" title="Avvia/Riprendi la presentazione di tutte le foto"><span>Play</span></a></li>';
		hs+='<li><a id="'+thisId+'_pause" href="#" title="Sospendi la presentazione di tutte le foto"><span>Pause</span></a></li>';
		hs+='</ul>';
		hs+='<p id="'+thisId+'_controlInfo">Immagine '+(this.currentImage+1)+' di '+this.images.length+'</p>';
		this.controlObj.innerHTML=hs;
		var thisObj=this;
		document.getElementById(thisId+"_prev").onclick=function() {
			if (thisObj.state=="play") {
				thisObj.pause();
				if (!confirm("Per utilizzare questa funzione la presentazione verrą messa in pausa.\nContinuare?")) {
					thisObj.play();
					return false;
					};
				};
			return thisObj.prevPhoto();};
		document.getElementById(thisId+"_next").onclick=function() {
			if (thisObj.state=="play") {
				thisObj.pause();
				if (!confirm("Per utilizzare questa funzione la presentazione verrą messa in pausa.\nContinuare?")) {
					thisObj.play();
					return false;
					};
				};
			return thisObj.nextPhoto();};
		document.getElementById(thisId+"_stop").onclick=function() {return thisObj.stop()};
		document.getElementById(thisId+"_play").onclick=function() {return thisObj.play()};
		document.getElementById(thisId+"_pause").onclick=function() {return thisObj.pause()};
		};

	var photoStyle=document.createElement("LINK");
	photoStyle.setAttribute("type","text/css");
	photoStyle.setAttribute("rel","stylesheet");
	photoStyle.setAttribute("media","all");
	photoStyle.setAttribute("href","style/photoStyle.css");
	document.getElementsByTagName("HEAD")[0].appendChild(photoStyle);
	return this;
	};
//]]>