
addLoader(setup)
var oGallery=null
function setup() {
	var o=$("content")
	if (o) {
		var a=$b("a")
		a.id="clist"
		o.appendChild (a)
		a.href="javascript:showList()"
		
		var a=$b("div")
		a.id="glist"
		o.appendChild (a)
		a.className="hide"
		
		var a=$b("a")
		o.appendChild(a)
		a.className="galbtn"
		a.id="phprev"
		a.href="javascript:photoPrev()"
		
		var a=$b("a")
		o.appendChild(a)
		a.className="galbtn"
		a.id="phnext"
		a.href="javascript:photoNext()"
		
		var d=$b("div")
		o.appendChild(d)
		d.id="media"
		
		var d=$b("div")
		o.appendChild(d)
		d.id="contatore"
		
		var d=$b("div")
		o.appendChild(d)
		d.id="dida"
		
		var d=$b("div")
		o.appendChild(d)
		d.id="scroller"
		
		var d1=$b("div")
		d.appendChild(d1)
		d1.id="aleft"
		
		var a=$b("a")
		d1.appendChild(a)
		a.href="#"
		
		var d1=$b("div")
		d.appendChild(d1)
		d1.id="cscroll"
		
		var d2=$b("div")
		d1.appendChild(d2)
		d2.id="iscroll"
		
		var d1=$b("div")
		d.appendChild(d1)
		d1.id="aright"
		
		var a=$b("a")
		d1.appendChild(a)
		a.href="#"
		
		oGallery=new clGallerySimple("/interno/gallery2.php","/img/gallery2","scroller","iscroll","media",["dida"],6,70,2,"clist","glist")
		oGallery.loader()
	}
}


function gallery_loaded(modo,xData,url,info) {
	if(modo) {
		oGallery.reader(xData)
	}
}
function showList() {sc($("glist"),"","hide")}
function getGal(id) {oGallery.getGal(id)}
function mostra(v) {oGallery.setLista(v)}
function photoPrev() {oGallery.skipPhoto(-1)}
function photoNext() {oGallery.skipPhoto(1)}
function showPhoto() {oGallery.showPhoto("mainphoto")}
function closePhoto() {oGallery.hidePhoto("mainphoto")}
function cambia(a) {
	var o=document.getElementById("l"+a)
	if (o) {if (o.className!="c"+a) {document.location=a+".asp"}}
}
function hime(id) {oGallery.hime(id)}
function moveme(v) {oGallery.moveme(v)}
function doPlay() {oGallery.doPlay()}

function clGallerySimple(inSrc,imgFold,idScroller,idScrollerInt,idEleMed,inArAtt,nScrollEle,wScrollEle,scrollTime,cListaID,gListaID,fcallShow) {
	this.xsrc=inSrc	
	this.baseImg=imgFold
	this.scroller=idScroller
	this.scrollerIn=idScrollerInt
	this.eleMed=idEleMed
	this.arrAtt=inArAtt
	this.nEleScroll=nScrollEle
	this.wEleScroll=wScrollEle
	this.scrollTime=scrollTime
	this.xDoc=null
	
	this.cLista=-1
	this.cListaEle=cListaID
	this.gListaEle=gListaID
	this.vLista=new Array()
	this.vIndici=new Array()
	
	this.x_tipo=""
	this.kfiltro=""
	this.vFiltro=new Array()
	this.vFiltroG=new Array()
	this.vIndiciG=new Array()
	this.cImg=0
	this.nt=0
	this.nc=0
	this.nd=0
	this.noFilterTxt=""
	this.allGeneri=""
	this.playing=false
	this.ntm=0
	this.ptm=0
	
	this.callShow=(fcallShow==undefined)?null:fcallShow
	
	this.doPlay=function doPlay() {
		if(this.playing) {
			this.playing=false
			clearInterval(this.ptm)
		} else {
			this.playing=true
			this.ptm=setInterval("oGallery.skipPhoto(1)",this.scrollTime*1000)
		}
	}
	
	this.buildPrw=function buildPrw() {
		clearTimeout(this.ntm)
		clearInterval(this.ptm)
		var n=this.vLista.length
		var vGL=this.xDoc.getElementsByTagName("GLS")[0].getElementsByTagName("GL")
		
		var o=document.getElementById(this.scrollerIn)
		o.style.left="0px"
		var tr=o.getElementsByTagName("table")
		var tt
		if (tr.length==0) {
			var t=document.createElement("table")
			o.appendChild(t)
			var tb=document.createElement("tbody")
			t.appendChild(tb)
			tt=document.createElement("tr")
			tb.appendChild(tt)
		} else {
			tt=tr[0].getElementsByTagName("tr")[0]
			var td=tt.getElementsByTagName("td")
			for(var i=td.length-1;i>=0;i--) {td[i].parentNode.removeChild(td[i])}
		}
		var tr=o.getElementsByTagName("table")
		tr[0].setAttribute("width",n*this.wEleScroll)
		var o=document.getElementById(this.scroller)
		var tr=o.getElementsByTagName("a")
		for(var i=tr.length-1;i>=0;i--) {tr[i].parentNode.removeChild(tr[i])}
		
		
		for (var i=0;i<n;i++) {
			var tr=document.createElement("td")
			var a=document.createElement("a")
			a.setAttribute("href","javascript:hime("+i+")")
			tr.appendChild(a)
			var ti=document.createElement("img")
			ti.setAttribute("alt","")
			ti.setAttribute("src",this.baseImg+"/small/"+vGL[this.vLista[i]].getAttribute("id")+".jpg")
			a.appendChild(ti)
			tt.appendChild(tr)
		}
		
		if (n>this.nEleScroll) {
			this.nt=n
			this.nt=(this.nt-(this.nt%this.nEleScroll))/this.nEleScroll
			var o=document.getElementById("aleft")
			var tr=document.createElement("a")
			tr.setAttribute("href","javascript:moveme(1)")
			o.appendChild(tr)
			var o=document.getElementById("aright")
			var tr=document.createElement("a")
			tr.setAttribute("href","javascript:moveme(-1)")
			o.appendChild(tr)
		}  else {
			this.nt=0
		}
		this.hime(0)
	}
	
	this.hime=function hime(id) {
		var o=document.getElementById(this.scrollerIn)
		var tr=o.getElementsByTagName("td")
		if (this.cImg<tr.length) {tr[this.cImg].className=""}
		if (id>-1&&id<tr.length) {
			tr[id].className="hi";
			this.cImg=id;
			var v=(id-(id%this.nEleScroll))/this.nEleScroll
			//alert(this.nc-(-v))
			this.moveme(-(this.nc-(-v)))
			this.buildMed()
		} else {
			this.buildMed()
		}
	}
	
	this.moveme=function moveme(v) {
		if ((this.nt!=0)&&(v!=0)) {
			this.nc+=v
			if (this.nc<(-this.nt)) {this.nc=-this.nt}
			if (this.nc>0) {this.nc=0}
			
			//alert(this.nc+"*"+this.nd+"*"+this.nt)
			
			this.nd=this.nc*this.nEleScroll*this.wEleScroll
			clearTimeout(this.ntm)
			this.ntm=setTimeout("oGallery.domoveme()",10)
		}
	}
	this.domoveme=function domoveme() {
		var o=document.getElementById(this.scrollerIn)
		var l=o.style.left.replace(/px/,"")*1
		if (l!=this.nd) {
			var df=Math.abs(this.nd-l)
			var spt=1
			if(df>50) {spt=2}
			if(df>100) {spt=3}
			if(df>150) {spt=4}
			if (df>250) {spt=10}
			if (l<this.nd) {
				l+=spt
			} else {
				l-=spt
			}
			o.style.left=l+"px"
			this.ntm=setTimeout("oGallery.domoveme()",10)
		} else {
			clearTimeout(this.ntm)
		}
	}
	
	this.buildMed=function buildMed() {
		var vGL=this.xDoc.getElementsByTagName("GLS")[0].getElementsByTagName("GL")
		//alert((vGL.length>0)+"*"+(this.cImg<this.vLista.length))
		if ((vGL.length>0)&&(this.cImg<this.vLista.length)) {
			var src=vGL[this.vLista[this.cImg]].getAttribute("id")
			var t=$(this.eleMed)
			if (t) {t.style.backgroundImage="url("+this.baseImg+"/med/"+src+".jpg)"}
			if (this.callShow) {
				this.callShow(vGL[this.vLista[this.cImg]])
			} else {
				for (var i=0;i<this.arrAtt.length;i++) {
					var t=$(this.arrAtt[i])
					if (t) {t.innerHTML=vGL[this.vLista[this.cImg]].getAttribute(this.arrAtt[i])}
				}
			}		
			var t=$("contatore")
			if (t) {t.innerHTML=(this.cImg+1)+"/"+this.vLista.length}
			
			
		} else {
			var t=$(this.eleMed)
			if (t) {t.style.backgroundImage="none"}
			
			if (this.callShow) {
				this.callShow(null)
			} else {
				for (var i=0;i<this.arrAtt.length;i++) {
					var t=$(this.arrAtt[i])
					if (t) {t.innerHTML=""}
				}
			}
			
			var t=$("contatore")
			if (t) {t.innerHTML=""}
		}		
	}
	
	this.changeFilterG=function changeFilterG(id,modo) {
		var cambiato=false
		if(modo) {
			var j=this.vIndiciG.indice(id)
			if(j==-1) {
				this.vIndiciG[0]=id
				cambiato=true
			}
		} else {
			if(id==-1) {
				cambiato=true
				this.vIndiciG=new Array()
			} else {
				var j=this.vIndiciG.indice(id)
				if(j!=-1) {
					cambiato=true
					this.vIndiciG[0]=id
				}
			}
		}
		if (cambiato) {
			var o=document.getElementById("fkwordsg")
			if (o) {
				var as=o.getElementsByTagName("a")
				if(as.length!=0) {
					as[0].className=(this.vIndiciG.length==0)?"lista":""
					for(var i=0;i<this.vFiltroG.length;i++) {
						var j=this.vIndiciG.indice(i)
						as[i+1].href=(j!=-1)?("javascript:removeallG()"):("javascript:addmeG("+i+")")
						as[i+1].className=(j!=-1)?"lista":""
					}
				}
			}
/*ricostruisco la lista dei filtri per genere*/
			var s=document.getElementById("fkwords")
			if (s) {
				s.innerHTML=""
				var a=document.createElement("a")
				a.setAttribute("href","javascript:removeall()")
				a.className="lista"
				a.appendChild(document.createTextNode(this.noFilterTxt))
				s.appendChild(a)
//alert(this.vIndiciG.length)
				if (this.vIndiciG.length==0) {
					this.vIndici=new Array()
					for(var i=0;i<this.vFiltro.length;i++) {
						s.appendChild(document.createElement("br"))
						var a=document.createElement("a")
						a.setAttribute("href","javascript:addme("+i+")")
						a.id="ff"+i
						a.appendChild(document.createTextNode(this.vFiltro[i][0]+" ("+(this.vFiltro[i][1]+"").split(",").length+")"))
						s.appendChild(a)
					}
				} else {
					this.vIndici=new Array()
					//alert(this.vFiltro[1])
					var appo=(this.vFiltroG[this.vIndiciG[0]][1]+"").split(",")
					for(var i=0;i<this.vFiltro.length;i++) {
						var ok=0
						var appof=(this.vFiltro[i][1]+"").split(",")
						for(j=0;j<appo.length;j++) {
							if (appof.indice(appo[j])!=-1) {ok++}
						}
						if (ok!=0) {
							s.appendChild(document.createElement("br"))
							var a=document.createElement("a")
							a.setAttribute("href","javascript:addme("+i+")")
							a.id="ff"+i
							a.appendChild(document.createTextNode(this.vFiltro[i][0]+" ("+ok+")"))
							s.appendChild(a)
						}
					}
				}
			}
			this.buildLista()
		}
	}
	
	this.changeFilter=function changeFilter(id,modo) {
		var cambiato=false
		if(modo) {
			var j=this.vIndici.indice(id)
			if(j==-1) {
				this.vIndici[this.vIndici.length]=id
				cambiato=true
			}
		} else {
			if(id==-1) {
				cambiato=true
				this.vIndici=new Array()
			} else {
				var j=this.vIndici.indice(id)
				if(j!=-1) {
					cambiato=true
					var appo=new Array()
					for (var i=0;i<this.vIndici.length;i++) {appo[i]=this.vIndici[i]}
					var k=0
					this.vIndici=new Array()
					for(var i=0;i<appo.length;i++) {if (i!=j) {this.vIndici[k]=appo[i];k++}}
				}
			}
		}
		if (cambiato) {
			var o=document.getElementById("fkwords")
			if (o) {
				var as=o.getElementsByTagName("a")
				as[0].className=(this.vIndici.length==0)?"lista":""
				for(var i=1;i<as.length;i++) {
					var k=as[i].id.replace("ff","")*1
					var j=this.vIndici.indice(k)
					
					as[i].href=(j!=-1)?("javascript:removeme("+k+")"):("javascript:addme("+k+")")
					as[i].className=(j!=-1)?"lista":""
				}
			}
			this.buildLista()
		}
	}
	
	this.buildLista=function buildLista() {
		var Lista=new Array()
		var cGLS=$t(this.xDoc,"GLS")
		if (cGLS.length>0) {
			var sGLS=$t(cGLS[0],"GL")
			for (i=0;i<sGLS.length;i++) {Lista[Lista.length]=i}
			for(var i=0;i<this.vIndiciG.length;i++) {
				var appo=(this.vFiltroG[this.vIndiciG[i]][1]+"").split(",")
				for(var j=0;j<Lista.length;j++) {if(appo.indice(Lista[j])==-1) {Lista[j]=-1}}
			}
			for(var i=0;i<this.vIndici.length;i++) {
				var appo=(this.vFiltro[this.vIndici[i]][1]+"").split(",")
				for(var j=0;j<Lista.length;j++) {if(appo.indice(Lista[j])==-1) {Lista[j]=-1}}
			}
			this.vLista=new Array()
			for(var i=0;i<Lista.length;i++) {if (Lista[i]!=-1) {this.vLista[this.vLista.length]=Lista[i]}}
			this.cImg=0
			this.buildPrw()
		}
	}
	
	this.mostraLista=function mostraLista() {
		this.vLista=new Array()
		var cGLS=$t(this.xDoc,"GLS")
		if (cGLS.length>0) {
			var sGLS=$t(cGLS[0],"GL")
			for (i=0;i<sGLS.length;i++) {this.vLista[this.vLista.length]=i}
			this.cImg=0
			this.buildPrw()
		}
	}
	
	this.setLista=function setLista(v) {
		var Lista=new Array()
		var cGLS=$t(this.xDoc,"GLS")
		if (cGLS.length>0) {
			var sGLS=$t(cGLS[0],"GL")
			for (i=0;i<sGLS.length;i++) {Lista[Lista.length]=i}
			var tutti=false
			for(var i=0;i<v.options.length;i++) {
				if(i>0&&v.options[i].selected) {
					var appo=(this.vFiltro[v.options[i].value][1]+"").split(",")
					for(var j=0;j<Lista.length;j++) {
						if(appo.indice(Lista[j])==-1) {Lista[j]=-1}	
					}
				}
			}
			this.vLista=new Array()
			for(var i=0;i<Lista.length;i++) {if (Lista[i]!=-1) {this.vLista[this.vLista.length]=Lista[i]}}
			this.cImg=0
			this.buildPrw()
		}
	}
	
	
	this.reader=function reader(xData) {
		if (this.cLista==-1) {
			var x=$t(xData,"GSS")
			if (x.length!=0) {
				var xs=$t(x[0],"GS")
				var o=$(this.gListaEle)
				if (o) {
					for (var i=0;i<xs.length;i++) {
						var a=$b("a")
						a.id="gl"+xs[i].getAttribute("id")
						o.appendChild(a)
						a.href="javascript:getGal('"+xs[i].getAttribute("id")+"')"
						a.appendChild($ct(getSafExx(xs[i].getAttribute("nome"))))
					}
					if (xs.length>0) {this.getGal(xs[0].getAttribute("id"))}
				}
			}
		} else {
			this.xDoc=xData
			this.buildLista()
		}
	}
	this.getGal=function getGal(id) {
		var o=$(this.cListaEle)
		sc($("gl"+this.cLista),"","hide")
		this.cLista=id
		var oo=$("gl"+this.cLista)
		if (oo) {
			o.innerHTML=oo.innerHTML
			sc(oo,"hide","")
			sc($(this.gListaEle),"hide","")
			callAction(new Array("G",gallery_loaded,this.xsrc,"signature="+(new Date()).getTime()+""+Math.floor(1000 * Math.random())+"&id="+id))
		}
	}
	this.skipPhoto=function skipPhoto(v) {
		var nv=this.cImg+v
		if (nv<0) {nv=this.vLista.length-1}
		if (nv>=this.vLista.length) {nv=0}	
		this.hime(nv)
	}

	this.loader=function loader(filtro) {
		callAction(new Array("G",gallery_loaded,this.xsrc,"signature="+(new Date()).getTime()+""+Math.floor(1000 * Math.random())))
	}
	
	this.showPhoto=function showPhoto(pid) {
		var o=$(pid)
		if (o) {
			var gGLS=$t(this.xDoc,"GLS")
			if (gGLS.length>0) {
				var sGLS=$t(gGLS,"GL")
				var src=sGLS[this.vLista[this.cImg]].getAttribute("id")
				o.style.backgroundImage="url("+this.baseImg+"/big/"+src+".jpg)"
				o.className=""
			}	
		}
	}
	
	this.hidePhoto=function hidePhoto(pid) {
		var o=$(pid)
		if (o) {o.className="hide"}
	}
}

Array.prototype.indice=function(v,c) {
	var r=-1
	if (arguments.length==1) {
		for(var i=0;i<this.length;i++) {if (this[i]==v) {return i}}
	} else {
		for(var i=0;i<this.length;i++) {if (this[i][c]==v) {return i}}
	}
	return r
}



