function downloadImage(index,size){
	if (idUsuario=="0"){showLoginPopupBox("<b>descargar de forma directa esta foto</b> ");return;}
	if(!document.getElementById("controlIframe")){return;}
	var url = "/download/"+fotos[index][0]+"/"+fotos[index][1]+"/"+size+fotos[index][4];
	document.getElementById("controlIframe").src = url;return;
}	
function showFoto(index){
	var posX = "20px"; var posY="20px";
	getPageSize();getPageScroll();
	if(document.getElementById("preloading")){document.getElementById("preloading").style.display="block";}
	if(arrayPageSize[0]>520){posX=parseInt(((arrayPageSize[0]-520)/2)+arrayPageScroll[0])+"px";}else{posX=(parseInt(posX)+arrayPageScroll[0])+"px";}
	if(arrayPageSize[3]>600){posY=parseInt(((arrayPageSize[3]-600)/2)+arrayPageScroll[1])+"px";}else{posY=(parseInt(posY)+arrayPageScroll[1])+"px";}	
	document.getElementById("nroFoto").innerHTML=(parseInt(index,10)+1);
	
	var f = "<img onerror=\"this.src='/images/clearpixel.gif';\" onload=\"hidePreload();\" src=\"/store/galerias/"+fotos[index][0]+"/"+fotos[index][1]+"/480x360_"+fotos[index][4]+"\" border=0 width=480 height=360>";
	document.getElementById("popupFoto").innerHTML=f;
	document.getElementById("popup480x360").href="javascript:downloadImage("+index+",'480x360_');";
	document.getElementById("popup800x600").href="javascript:downloadImage("+index+",'800x600_');";
	document.getElementById("popup1027x768").href="javascript:downloadImage("+index+",'1024x768_');";		
	document.getElementById("sumillatitulopop").innerHTML=fotos[index][2];
	document.getElementById("sumillapop").innerHTML=fotos[index][3];
	cPhoto = index;
	document.getElementById("coverDiv").style.width=arrayPageSize[0]+"px";
	document.getElementById("coverDiv").style.height=arrayPageSize[1]+"px";
	document.getElementById("coverDiv").style.display="block";
	document.getElementById("fotoGallery").style.width="536px";
	document.getElementById("fotoGallery").style.height="auto";
	document.getElementById("fotoGallery").style.marginTop=posY;
	document.getElementById("fotoGallery").style.marginLeft=posX;

	document.getElementById("fotoGallery").style.display="block";
}
function closeFoto(){
	closeEpp();
	if(document.getElementById("fotoGallery")){document.getElementById("fotoGallery").style.display="none";}
	if(document.getElementById("coverDiv")){document.getElementById("coverDiv").style.display="none";}
}
function hideLayer(obj){
	obj.style.display="none";
}
function nextPhoto(offset){
	if(((parseInt(offset)+parseInt(cPhoto))>=fotos.length)||((parseInt(offset)+parseInt(cPhoto))<0)){return;}
	cPhoto=parseInt(cPhoto)+offset;showFoto(cPhoto);
	showPaginador(Math.ceil((cPhoto+1)/pagsize));
	//if(cPhoto==0){document.getElementById("popupPrev").style.display="none";}else{document.getElementById("popupPrev").style.display="block";}
	//if((cPhoto+1)==fotos.length){document.getElementById("popupNext").style.display="none";}else{document.getElementById("popupNext").style.display="block";}
}
function hidePreload(){
	if(document.getElementById("preloading")){document.getElementById("preloading").style.display="none";}
}
function sendPhoto(){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();	
	var posX = "20px"; var posY="20px";
	document.getElementById("controlIframe").src="/control/control_galerias_epp.asp?idFoto="+fotos[cPhoto][1];
	document.getElementById("control").style.height="auto";
	document.getElementById("control").style.width="auto";
	document.getElementById("control").style.position="absolute";
	if(arrayPageSize[0]>450){posX=parseInt(((arrayPageSize[0]-450)/2)+arrayPageScroll[0])+"px";}else{posX=(parseInt(posX)+arrayPageScroll[0])+"px";}
	if(arrayPageSize[3]>210){posY=parseInt(((arrayPageSize[3]-210)/2)+arrayPageScroll[1])+"px";}else{posY=(parseInt(posY)+arrayPageScroll[1])+"px";}	
	document.getElementById("control").style.top=posY;
	document.getElementById("control").style.left=posX;
	document.getElementById("control").style.zIndex=200;
	document.getElementById("controlIframe").style.display="block";
	document.getElementById("control").style.display="block";
}
function closeEpp(){
	if(!document.getElementById("controlIframe")){return;}
	if(!document.getElementById("control")){return;}
	document.getElementById("control").style.height="0px";
	document.getElementById("control").style.width="0px";
	document.getElementById("control").style.position="absolute";
	document.getElementById("control").style.top="0px"
	document.getElementById("control").style.left="0px";
	document.getElementById("control").style.display="none";
	document.getElementById("controlIframe").src="/blank.htm";
	document.getElementById("controlIframe").style.display="none";	
}		
function move2Page(){
	return;
}
function showFotos(idg){
	if(fotos.length==0){
		return;
	}
	var html="";
	var opendiv = false;
	for (var i=0;i<fotos.length;i++){	
		if (((i%pagsize)==0)||i==0){
			cpag++;
			if(opendiv){html+="</div><div style=\"clear:both;\"></div>";}
			html+="<div id=\"pag_"+cpag+"\" style=\"display:none;\">";opendiv = true;
		}
		html+=getFotoDiv(i);			
	}
	if(opendiv){html+="</div><div style=\"clear:both;\"></div>";}
	html+="<div id=paginador></div>";
	document.write(html);
	tpag = cpag;
	document.getElementById("paginade_div").innerHTML="Página 1 de "+tpag;
	showPaginador(1);
}
function getFotoDiv(index){
	if(index>fotos.length){return "";}
	var html =	"<div class=\"galContainer\" onclick=\"showFoto('"+index+"');\">\n";
	html+=			"\t<div class=foto>\n"
	html+=				"\t\t<img  class=ima src=\"/store/galerias/"+fotos[index][0]+"/"+fotos[index][1]+"/144x106_"+fotos[index][4]+"\" alt border=0 width=144 height=106 />\n";
	html+=			"\t</div>\n"
	html+=		"</div>\n"
	return html;html=null;
}
function showPaginador(pagcatual){
	var html="";
	if(document.getElementById("paginade_div")){document.getElementById("paginade_div").innerHTML="Página "+pagcatual+" de "+cpag;}
	for (var i=tpag;i>0;i--){
		if(pagcatual==i){
			html+="<div class=numpag style=\"background-color:#ff6600;;\" onclick=\"showPaginador('"+i+"');\">"+i+"</div>";
			document.getElementById("pag_"+i).style.display="block";
		}else{
			html+="<div class=numpag onclick=\"showPaginador('"+i+"');\">"+i+"</div>";
			document.getElementById("pag_"+i).style.display="none";
		}
	}
	html+="<div style=\"clear:both;\"></div>";
	document.getElementById("paginador").innerHTML=html;
	if(document.getElementById("paginador_sup")){document.getElementById("paginador_sup").innerHTML=html;}
	html=null;
	return;
}
// Galerías
function showGalleries(idg){
	if(galerias.length==0){
		return;
	}
	var html = "";
	var opendiv = false;
	for (var i=0;i<galerias.length;i++){	
		if (((i%pagsize)==0)||i==0){
			cpag++;
			if(opendiv){html+="</div><div style=\"clear:both;\"></div>";}
			html+="<div id=\"pag_"+cpag+"\" style=\"display:none;\">";opendiv = true;
		}	
		html+=getGalleryDiv(i);
	}
	if(opendiv){html+="</div><div style=\"clear:both;\"></div>";}
	html+="<div id=paginador></div>";
	document.write(html);
	tpag = cpag;
	document.getElementById("paginade_div").innerHTML="Página 1 de "+tpag;
	showPaginador(1);	
}
function getGalleryDiv(index){
	//gdate="+fecs[i][0];
	if(index>galerias.length){return "";}
	var gdate = galerias[index][1].substring(0,7).replace("-","")
	var html =	"<div class=\"galContainer\" onclick=\"document.location.href='/galerias.asp?idGaleria="+galerias[index][0]+"&gdate="+gdate+"'\">";
	html+=		"	<div class=galSubtitulo>"+galerias[index][1]+" - "+galerias[index][3]+" fotos</div>"
	html+=		"	<div class=foto>"
	html+=		"		<a href=\"/galerias.asp?idGaleria="+galerias[index][0]+"&gdate="+gdate+"\">";
	html+=		"			<img src=\"/store/galerias/"+galerias[index][0]+"/"+galerias[index][4].toString().replace("/","/144x106_")+"\" alt=\"\" border=0 width=144 height=106>";
	html+=		"		</a>"		
	html+=		"	</div>"
	html+=		"	<div class=galTitulo>"+galerias[index][2]+"</div>"
	html+=		"</div>"
	return html;html=null;
}
function showFecs(cgdate){
	var meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	if(cgdate==null){cgdate=fecs[0][0];}
	var tyear="*";
	var html="<div id=\"galmeses_div\">";
	html+="<div class=divmenu ";if(cgdate==""){html+="style=\"background-color:#ff6600;\" ";};html+="onclick=\"document.location.href=estaPagina;\">";
	html+="Últimas Galerías"
	html+="</div>";						
	for(var i=0;i<fecs.length;i++){
		if(tyear!=fecs[i][0].substring(0,4)){
			tyear=fecs[i][0].substring(0,4);
			html+="<div class=divmenu id=\""+fecs[i][0].substring(0,4)+"\" onclick=\"showGMeses(this.id);\">";
			html+="<img id=image_"+fecs[i][0].substring(0,4)+"\" src=\"/images/plus.gif\"> "
			html+=tyear
			html+="</div>";
		}	
		var url = estaPagina+"?gdate="+fecs[i][0];
		html+="<div ";if(cgdate==fecs[i][0]){html+="style=\"background-color:#ff6600;\" ";};html+="onclick=\"document.location.href='"+url+"';\" class=divsubmenu cgyear=\""+fecs[i][0].substring(0,4)+"\" id=\""+fecs[i][0]+"\" style=\"display:none;\">";
		html+=meses[parseInt(fecs[i][0].substring(4,6),10)-1];
		html+="</div>";
	}
	html+="</div>";
	document.write(html);
	showGMeses(cgdate.substring(0,4));
}
function showGMeses(cgyear){
	var sdivs = document.getElementById("galmeses_div").getElementsByTagName("DIV");
	for(var i=0;i<sdivs.length;i++){if(sdivs[i].getAttribute("cgyear")!=null){if(sdivs[i].getAttribute("cgyear")==cgyear){if(sdivs[i].style.display=="block"){sdivs[i].style.display="none";}else{sdivs[i].style.display="block";}}}}
}