function pop(a,w,h,t){
	if (t==undefined) t="_blank";
	var left = (screen.width - w) / 2;
	var top = ((screen.height - (h + 28)) / 2);
	property="width="+w+",height="+h+",top="+top+",left="+left+",resizable,scrollbars=yes";
	var vPopup = window.open(a,t,property);
	if (vPopup == undefined) alert("No se pudo abrir la ventana.\nAsegúrate de no tener un bloqueador de ventanas habilitado.");
	vPopup.focus();
}


function traspasarParametros(so){
	var vParams = traerParametro();
	if (vParams != -1){
		var aParams = vParams.split("&");
		for (var i = 0; i<aParams.length; i++) {
			var aParamSplit = aParams[i].split("=");
			so.addVariable(aParamSplit[0], aParamSplit[1]);
		}
	}
}
		
		
function traerParametro(nombre){
	var strURL = String(document.location);
	var listaSplit = strURL.split("?")
	if(listaSplit.length > 1) {
		var params = listaSplit[1];
		var buscamos = nombre + "=";
		if (params.length > 0) {
			if (nombre == undefined) return(params);
			i = params.indexOf(buscamos);
			if (i != -1) {
				i += buscamos.length;
				j = params.indexOf("&", i);
				if (j == -1)
				j = params.length;
				return (params.substring(i,j));
			}else{
				return -1
			}
		}else{
			return -1
		}
	}else{
		return -1
	}
}


// REDIMENSIONAR VENTANA AL CENTRO --------------------------
function resizeWin(w, h) {
	window.resizeTo(w, h);
	window.moveTo((screen.width - w) / 2, (screen.height - (h + 28)) / 2);
}




function mostrarFotos(){
	var sTotal = traerParametro("fotos");
	if (sTotal == -1) sTotal = 0;
	var nTotal = Number(sTotal);
	
	//var nTotal = 12;
	this.aFotos = [];
	for (var i = 0; i<nTotal; i++){
		var sNumero = (i<9)?"0"+String(i+1):String(i+1);
		this.aFotos.push(sNumero+".jpg");
	}
	
	var vNroFoto = traerParametro("foto");
	if (vNroFoto == -1) vNroFoto = 0;
	vNroFoto = Number(vNroFoto);
	
	this.mostrarFoto(vNroFoto);
}


function avanzarFoto(nCantidad){
	this.mostrarFoto(this.nFotoActual + nCantidad);
}

function mostrarFoto(nFoto){
	nFotoTentativa = Math.max(0,Math.min(this.aFotos.length-1, nFoto));
	if (nFotoTentativa == this.nFotoActual) return;
	
	this.nFotoActual = nFotoTentativa;
	var prefijoRutaFoto = traerParametro("urlFoto");
	this.cargarFoto(prefijoRutaFoto + "_" + this.aFotos[this.nFotoActual]);
}

function cargarFoto(urlFoto){
	var vNumeros = document.getElementById("div_numeros");
	vNumeros.innerHTML = ("Cargando imagen " + (this.nFotoActual+1) + "...");
	
	document.getElementById("div_foto").innerHTML = "<img id='img_foto' onLoad='fotoCargada(this);' >"; 
	var vFoto = document.getElementById("img_foto");
	vFoto.src = urlFoto;
}

function fotoCargada(vFoto){
	this.actualizarNumeros();
	/*vAncho = vFoto.width+50;
	vAlto = vFoto.height+125;
	this.resizeWin(vAncho, vAlto);*/
}

function actualizarNumeros(){
	var vNumeros = document.getElementById("div_numeros");
	var vFlechaI = document.getElementById("flecha_izquierda");
	var vFlechaD = document.getElementById("flecha_derecha");
	vNumeros.innerHTML = (this.nFotoActual+1) + " / " + this.aFotos.length;
	vFlechaI.onClick = (this.nFotoActual==0)?null:"avanzarFoto(-1);";
	vFlechaI.style.cursor = (this.nFotoActual==0)?"default":"pointer";
	vFlechaD.onClick = (this.nFotoActual >= this.aFotos.length-1)?null:"avanzarFoto(1);";
	vFlechaD.style.cursor = (this.nFotoActual >= this.aFotos.length-1)?"default":"pointer";
	
	//alert(vFlechaD.onClick);
}


// ROLL OVER

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}