/*test5*/
tamGal=function(){
	var galery=document.getElementById("galeria");
	if (self.innerWidth){
		fw = self.innerWidth;
		fh = self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientWidth){
		fw = document.documentElement.clientWidth;
		fh = document.documentElement.clientHeight;
	}else if (document.body){
		fw = document.body.clientWidth;
		fh = document.body.clientHeight;
	}
	galery.style.width=fw;
	galery.style.height=fh;
}
carga=function(){
	var galery=document.getElementById("galeria");
	galery.paraMaquina=false;
	window.onresize=tamGal;
	tamGal();
	galery.onmousemove=function(e){
		if(!e){e=window.event;}

		px=Math.round(e.clientX);
		py=Math.round(e.clientY);
		if(document.mdown&&!galery.paraMaquina){
			procesa();
		}					
		oldX=px;
		oldY=py;
		var superAlt = document.getElementById("superAlt");
		superAlt.style.left=px+"px";
		superAlt.style.top=(py+sepAltTop)+"px";
		
		if(document.clipDrag){
			var clp = document.clipDrag;	
			var dsph = document.despAlt;
			var dspw = document.despAmple;
			clp.style.top = (py - dsph)+"px";
			clp.style.left = (px - dspw)+"px";
			document.isDragged = true;
		}else{
			document.isDragged = false;
		}
		try{document.selection.empty();}catch(e){}
	}
	galery.onmousedown=function(e){
		if(!e){e=window.event;}
		if(!e.srcElement){e.srcElement=e.target;}
		if(e.srcElement.capa==undefined){
			document.mdown=true;
			posicionaFoto();
		}else{
			document.clipDrag = e.srcElement;
		}
		return false;
	}
	galery.onmouseup=function(e){
		if(!e){e=window.event;}
		document.mdown=false;
		var clp = document.clipDrag;

		var dsph = document.despAlt;
		var dspw = document.despAmple;
		
		var px=Math.round(e.clientX);
		var py=Math.round(e.clientY);
		
		clp.pt = (py - dsph)+"px";
		clp.pl = (px - dspw)+"px";
		
		document.clipDrag=false;
	}
	window.$onload();
}
procesa=function(){
	contador++;
	if(contador%velocidad==0){
		posicionaFoto();
	}
}

ampliaoreduce=function(clip){
	if(clip.tipo==1){ 
		if(clip.tamany == "petit"){
			clip.tamany="gran";
			clip.src=clip.gran.src;
			clip.width=clip.gw;
			clip.height=clip.gh;
			clip.style.top = parseInt(clip.style.top) - (clip.gh/2);
			clip.style.left = parseInt(clip.style.left) - (clip.gw/2);
			clip.style.zIndex = zindex++;
			if (isFirefox)
			{
				document.getElementById("superAlt").style.zIndex = 0xFFFFFF;
				document.getElementById("superAlt").style.visibility="visible";
			}
		}else{
			clip.tamany="petit";
			clip.src=clip.petita.src;
			clip.width=clip.pw;
			clip.height=clip.ph;
			clip.style.top = parseInt(clip.style.top) + (clip.gh/2);
			clip.style.left = parseInt(clip.style.left) + (clip.gw/2);
			clip.style.zIndex = clip.zIndex0;
		}
	}
	else if(clip.tipo==2){
		var wWidth = clip.gw;
		var wHeight = parseInt(clip.gh) + 14;
		window.open('pop_video.php?mat_id='+clip.mat_id , 'video_'+clip.id, 'width=' + wWidth + ', height=' + wHeight);
	}
	else if(clip.tipo==3){
		var wWidth = 200;
		var wHeight = 14; 
		window.open('pop_audio.php?mat_id='+clip.mat_id, 'audio_'+clip.id, 'width=' + wWidth + ', height=' + wHeight);
	}
}

posicionaFoto=function(){
	if(contFotos==totalFotos){
		contFotos=0;
	}
	var galery=document.getElementById("galeria");
	var gw = fotos[contFotos][2];
	var gh = fotos[contFotos][3];
	var pw = fotos[contFotos][4];
	var ph = fotos[contFotos][5];
	var tipo = fotos[contFotos][7];
	var mat_id = fotos[contFotos][8];
	var f=document.createElement("img");
	f.nombreFotoGrande = fotos[contFotos][0];
	f.nombreFoto = fotos[contFotos][1];
	f.src=carpetaFotos+f.nombreFoto;
	f.id="f"+contFotos;
	f.gw=gw,f.gh=gh,f.pw=pw,f.ph=ph;
	f.petita = new Image(f.pw,f.ph);
	f.petita.src=carpetaFotos+f.nombreFoto;
	if (tipo==1){
		f.gran = new Image(f.gw,f.gh);
		f.gran.src=carpetaFotos+f.nombreFotoGrande;
	}
	f.capa=true;
	f.pt=f.style.top=(py-(f.ph/2))+"px";
	f.pl=f.style.left=(px-(f.pw/2))+"px";
	f.zIndex0=zindex++;
	f.style.zIndex=f.zIndex0;
	f.tamany="petit";
	f.text = fotos[contFotos][6];
	f.tipo = tipo;
	f.mat_id = mat_id;
	if (!isFirefox){
		f.alt=f.text;
		f.title=f.text;	
		f.longdesc=f.text;	
	}
	f.onmouseover=function(){
		var superAlt=document.getElementById("superAlt");
		if (isFirefox){
			superAlt.innerHTML = this.text;
			superAlt.style.visibility="visible";
		}
	}
	f.onmouseout=function(){
		var superAlt=document.getElementById("superAlt");
		superAlt.style.visibility="hidden";
	}
	f.onmousedown=function(e){
		if(!e){e=window.event;}
		if(!e.srcElement){e.srcElement=e.target;}
		this.ampliar=true;
		
		var apy = parseInt(e.srcElement.style.top);
		var apx = parseInt(e.srcElement.style.left);
		
		document.despAmple = e.clientX - apx;
		document.despAlt = e.clientY - apy;
	}
	f.onmouseup=function(e){
		if(!e){e=window.event;}
		if(!e.srcElement){e.srcElement=e.target;}
		
		if(this.ampliar==true && !document.isDragged){
			ampliaoreduce(this); 
			var superAlt=document.getElementById("superAlt");
			superAlt.style.visibility="hidden";
			if (isFirefox){
				superAlt.innerHTML = this.text;
				superAlt.style.visibility="visible";
			}
		}
		document.isDragged=false;
		this.ampliar=false;
		
		var apy = parseInt(e.srcElement.style.top);
		var apx = parseInt(e.srcElement.style.left);

		document.despAmple = e.clientX - apx;
		document.despAlt = e.clientY - apy;
	}
	f.onmousemove=function(){return false;}
	galery.appendChild(f);
	contFotos++;
}
