function GetXmlHttpObject(){
	var xmlHttp=null;
	try {
	  xmlHttp=new XMLHttpRequest();
	}catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	return xmlHttp;
}	
// 0	1	2					3				4			5	  6		7									8
//["1","2","Aereopuerto Cusco","Cielos Rasos","Cielos Rasos","0","17","/store/galerias/1/118/{type}1.jpg","6"]
function showGaleria(idg,idc,ide){
	if ((idg==null)||(idg==undefined)){idg="0";};if((idc==null)||(idc==undefined)){idc="0";};if((ide==null)||(ide==undefined)){ide="0";};
	if (idc!="0"){
		index=-1;
		for (var i=0;i<gals.length;i++){if(gals[i][1]==idc){idg=gals[i][0];index=i;break};}
		if(index==-1){index=0;idg=gals[0][0];ccat=gals[0][1];}
	}else if (ide!="0"){
		index=-1;for (var i=0;i<gals.length;i++){if(gals[i][6]==ide){idg=gals[i][0];ccat=gals[i][1];index=i;break};}
		if(index==-1){index=0;idg=gals[0][0];ccat=gals[0][1];}		
	}else{
		if (idg==""){
			if(ccat=="0"){
				ccat=gals[0][1];idg=gals[0][0];index=0;
			}else{
				for (var i=0;i<gals.length;i++){if(gals[i][1]==ccat){idg=gals[i][0];index=i;break};}
			}	
		}else{
			for (var i=0;i<gals.length;i++){if(gals[i][0]==idg){ccat=gals[i][1];index=i;break};}
		}
		if(index==-1){index=0;idg=gals[0][0];ccat=gals[0][1];}
	}
	// Generar el menú de galerias
	var html = ""
	html+="<div id=gals>";
	html+="<table cellspacing=0 cellpadding=0 width=200 style=\"table-layout:fixed;\">"
	html+="<col width=70><col width=5><col width=130>"
	for (var i=0;i<gals.length;i++){
		if(gals[i][1]==ccat){
			if(gals[i][0]!=idg){
				html+="<tr>"
				html+="<td valign=top><img style=\"cursor:pointer;\" onclick=\"showGaleria('"+gals[i][0]+"');\" class=Marcoimagen src=\""+gals[i][7].replace("{type}","_wml01_")+"\" border=0></td>";
				html+="<td></td>";
				html+="<td valign=middle>"
				html+="	<span onclick=\"showGaleria('"+gals[i][0]+"');\" class=click>"
				html+=		gals[i][2]
				html+="	</span>"
				html+="</td>"
				html+="</tr>"
			}
		}
	}
	html+="</table>"
	html+="</div>"
	var scat = "";
	var stotal = 0;
	html+="<div id=subgals>"
	for (var i=0;i<gals.length;i++){
		if(gals[i][1]!=ccat){
			if(scat!=gals[i][1]){
				stotal+=1;
				scat=gals[i][1];
				html+="<div onclick=\"showGaleria('"+gals[i][0]+"');\" class=click2>";
				html+=gals[i][3]
				html+="</div>";
			}
		}
	}
	html+="</div>";
	if (document.getElementById("galerias_menu")){document.getElementById("galerias_menu").innerHTML=html;}
	html=null;
	// galeria ----------------------------------------------------------------------------------------------------------
	html = "<table width=600 cellpadding=0 cellspacing=0 border=0 style=\"table-layout:fixed;\">";
	html+= "<tr>";
	html+= "	<td valign=top align=left>"
	html+= "	<div class=categoria>"+gals[index][3]+"</div><div class=titulo>"+gals[index][2]+"</div>";
	html+= "	<div style=\"clear:both;\"></div>";
	html+= "	</td>";
	html+= "<tr>";
	html+= "	<td valign=top align=center style=\"padding:10px;border:1px solid #e0e0e0;\" id=mainimage>"
	html+= "	<div id=loading style=\"width:580px;padding-top:100px;padding-bottom:100px;text-align:center;\">"
	html+= "	<img src=\"/images/iconos/ajax-loader_orange.gif\" border=0>";
	html+= "	</div>";
	html+= "	<a href=\""+gals[index][7].replace("{type}","_wml05_")+"\" class=highslide onclick=\"return hs.expand(this);\">";
	html+= "		<img id=mainPhoto onload=\"showLoading();opacity('mainPhoto', 0, 100, 500);\" border=0 src=\""+ gals[index][7].replace("{type}","_wml03_")+"\">";
	html+= "	</a><br>";
	html+=		gals[index][2];
	html+= "	</td>";
	html+= "<tr>";
	html+= "</table>";
	if (document.getElementById("galerias_detalle")){document.getElementById("galerias_detalle").innerHTML=html;}
	html=null;	
	getFotos(idg);
}
function showLoading(accion){
	if(!document.getElementById("loading")){return;}
	if(accion==null){document.getElementById("loading").style.display="none";}else{document.getElementById("loading").style.display="block";}
}
function showFoto(index){
	if(index>fotos.length){return;}
	var html ="<div id=loading style=\"width:580px;padding-top:100px;padding-bottom:100px;text-align:center;\">"
		html+="<img src=\"/images/iconos/ajax-loader_orange.gif\" border=0>";
		html+="</div>";
		html+="<a href=\"/store/galerias/"+fotos[index][0]+"/"+fotos[index][1]+"/_wml05_"+fotos[index][4]+"\" class=highslide onclick=\"return hs.expand(this);\">";
		html+="<img id=mainPhoto onload=\"showLoading();opacity('mainPhoto', 60, 100, 1000);\" border=0 src=\"/store/galerias/"+fotos[index][0]+"/"+fotos[index][1]+"/_wml03_"+fotos[index][4]+"\">";
		html+="</a>";
		html+=fotos[index][2];
	if(document.getElementById("mainimage")){document.getElementById("mainimage").innerHTML=html;};html=null;
	for (var i=0;i<fotos.length;i++){
		if(index==i){
			document.getElementById("img_"+i).className ="imgsel"; 
		}else{
			document.getElementById("img_"+i).className ="";
		}
	}		
}
//["12","154","Mall Aventura Plaza Trujillo 01","","mall_aventura_plaza_trujillo6.jpg"],
function showFotos(){
	if(fotos.length<1){return;}
	var html="";
	for (var i=0;i<fotos.length;i++){
		if(i==0){
			html+="<img class=\"imgsel\" "; 
		}else{
			html+="<img ";
		}
		html+="title=\"pulse está imagen para ampliarla\" id=\"img_"+i+"\" src=\"/store/galerias/"+fotos[i][0]+"/"+fotos[i][1]+"/_wml02_"+fotos[i][4]+"\" border=0 onclick=\"showFoto('"+i+"');\">\n";
	}
	if(document.getElementById("galerias_menu_barra")){document.getElementById("galerias_menu_barra").innerHTML=html;}
	html=null;
}
function getFotos(idg){
	var dNow = new Date(); 
	if(idg==null){return;}
	xmlHttpF=GetXmlHttpObject();
	if(xmlHttpF==null){return;}
	xmlHttpF.onreadystatechange=function(){
		if(xmlHttpF.readyState==4){
			var responseTxt = unescape(xmlHttpF.responseText);
			responseTxt = responseTxt.replace(/\+/gi," ");
			eval("fotos = new Array("+responseTxt+");");
			showFotos();
		}	
	}
	var url = "/control/control_galerias.asp?idg="+idg+"&timer="+dNow;
	xmlHttpF.open("GET",url,true);
	xmlHttpF.send(null);
}
function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function shiftOpacity(id, millisec) {
	if(document.getElementById(id).style.opacity == 0) {opacity(id, 0, 100, millisec);} else {opacity(id, 100, 0, millisec);}
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	changeOpac(0, imageid);
	document.getElementById(imageid).src = imagefile;
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}
function currentOpac(id, opacEnd, millisec) {
	var currentOpac = 100;
	if(document.getElementById(id).style.opacity < 100) {currentOpac = document.getElementById(id).style.opacity * 100;}
	opacity(id, currentOpac, opacEnd, millisec)
}	
