// JavaScript Document

// Función para recoger variables del URL
	function getUrlVars(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for (var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
			}
		return vars;
		}

// Función para escribir el html que cargará la imagen o el flash
	function writePix() 
	{
		var hash = getUrlVars();
		var project = hash['pro'];
		var prox = hash['prox'];
		var pix = hash['p'];
		var flash = hash['f'];
		var video = hash['v'];
		if (typeof prox == "undefined") {
			var ancho = hash['w'];
			var alto = hash['h'];
			}
		var galeria = hash['g'];
		var imagen = hash['imagen'];		
		if (typeof imagen != "undefined") {	
			var ancho = hash['w'];
			var alto = hash['h'];
			document.write('<img src=recursos/imgs/'+imagen+' width='+ancho+' height='+alto+' style="cursor:pointer">')
			window.parent.document.getElementById("loadpix").style.width=ancho+'px';
			window.parent.document.getElementById("container").style.width=ancho+'px';
			window.parent.document.getElementById("loadpix").style.height=alto+'px';
			window.parent.document.getElementById("container").style.height=alto+'px';				
			window.parent.document.getElementById("container").style.overflown='hidden';
			window.parent.document.getElementById("container").style.display='block';			
			window.parent.document.getElementById("container").style.position='absolute';
			var newX = findPosX(window.parent.document.getElementById("form"));
			var newY = findPosY(window.parent.document.getElementById("form"));
			var x = window.parent.document.getElementById("container");
			x.style.top = newY -80 +'px';
			x.style.left = newX -140 + 'px';
			}
		else 
			{
			document.write('<div onClick=javascript:hidePix() id=loader>');
			if (typeof pix != "undefined") {
				if (typeof prox != "undefined") {
					document.write('<img src=recursos/proyectos/'+prox+'/imgs/'+pix+' id="full">');
					ancho = document.getElementById("full").width+8
					alto = document.getElementById("full").height+8
					window.parent.document.getElementById("loadpix").style.width=ancho+'px';
					window.parent.document.getElementById("container").style.width=ancho+'px';
					window.parent.document.getElementById("container").style.overflown='hidden';
					window.parent.document.getElementById("container").style.display='block';			
					window.parent.document.getElementById("container").style.position='absolute';				
					var newX = findPosX(window.parent.document.getElementById("proyectos"));
					var newY = findPosY(window.parent.document.getElementById("proyectos"));
					var x = window.parent.document.getElementById("container");
					x.style.top = 130 +'px';
					x.style.left = newX + 250 + 'px'	
					}
				else {
					if (galeria == "1") {
						document.write('<img src=recursos/proyectos/'+project+'/imgs/galeria/'+pix+' width='+ancho+' height='+alto+'>');
						}
					else {
						document.write('<img src=recursos/proyectos/'+project+'/imgs/'+pix+' width='+ancho+' height='+alto+'>');
					   }
					}
				}
			else {
			    document.write('<div class=noflash>');
   				document.write('Este sitio requiere tener instalado el Reproductor de Flash.<br/><a href=#>Clic aqui para descargarlo.</a><br/><br/>');
				document.write('This site requires to have the Flash Player installed.<br/><a href=#>Clic here to download.</a>');
			    document.write('</div>');
				if (typeof video != "undefined") {
					var so = new SWFObject('recursos/swf/videoplayer.swf', 'plano', ancho, alto, '9', '#FFFFFF'); 
					so.addVariable('ruta', project);
					so.addParam('wmode','transparent');
					so.write('loader');
					}
				else {
					var so = new SWFObject('recursos/proyectos/'+project+'/swf/'+flash, 'plano', ancho, alto, '9', '#FFFFFF'); 
					so.addParam('wmode','transparent');
					so.write('loader');
					}
				}
			document.write('</div>');
			if (typeof hash['l'] != "undefined") {
				var leyenda = decodeURIComponent(hash['l']);
				alto = parseInt(alto)+8+25; //+25 por leyenda
				window.parent.document.getElementById("loadpix").style.height=alto+'px';
				window.parent.document.getElementById("container").style.height=alto+'px';			
				document.write('<div id=leyenda>'+leyenda+'</div>');			
				}
			}
		}
		
// Función para ocultar PopUp
	function hidePix(){
		window.open('about:blank','loadpix')
		window.parent.document.getElementById("container").style.display='none';
		}
		
// Función para mostrar y redimensionar PopUp
	function showPix(w,h) {
		ancho=w+8;
		alto =h+8;
		document.getElementById("loadpix").style.width=ancho+'px';
		document.getElementById("loadpix").style.height=alto+'px';					
		document.getElementById("container").style.width=ancho+'px';
		document.getElementById("container").style.height=alto+'px';
		document.getElementById("container").style.overflown='hidden';
		document.getElementById("container").style.display='block';			
		document.getElementById("container").style.position='absolute';
		}

// Función para mostrar y redimensionar PopUp (BackButton)
	function reSize() {
		var hash = getUrlVars();
		var imagen = hash['imagen'];
		var w = hash['w'];
		var h = hash['h'];
		if (typeof imagen != "undefined") {
			var ancho = parseInt(hash['w']);
			var alto = parseInt(hash['h']);
			}
		else {
			var ancho = parseInt(hash['w'])+8;
			var alto = parseInt(hash['h'])+8;			
			}
		var leyenda = hash['l'];
		if (typeof leyenda != "undefined") {
			alto = alto+25		
			}
		window.parent.document.getElementById("loadpix").style.width=ancho+'px';
		window.parent.document.getElementById("loadpix").style.height=alto+'px';					
		window.parent.document.getElementById("container").style.width=ancho+'px';
		window.parent.document.getElementById("container").style.height=alto+'px';
		}
		
// Función para posicionar el PopUp
	function setLyr(obj,lyr,posX,posY) {
		var newX = findPosX(document.getElementById(obj));
		var newY = findPosY(document.getElementById(obj));
		var x = document.getElementById(lyr);
		x.style.top = newY + posY + 'px';
		x.style.left = newX + posX + 'px';
		}

// Función para encontrar posición X de un objeto
	function findPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
				}
			}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
		}
	
// Función para encontrar posición Y de un objeto
	function findPosY(obj) {
		var curtop = 0;
		var printstring = '';
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
				curtop += obj.offsetTop
				obj = obj.offsetParent;
				}
			}
		else if (obj.y)
			curtop += obj.y;
			//window.status = printstring;
		return curtop;
		}
		
// Funcion para mostrar titulo y departamentos a los que pertenece un plano 
    function showNum(titulo,dpto) {
        document.getElementById("num_titulo").innerHTML=titulo;
        document.getElementById("num_dpto").innerHTML=dpto;    
        document.getElementById("num").style.display='block';
        }
        
// Funcion para ocultar titulo y departamentos a los que pertenece un plano 
    function hideNum() {
        document.getElementById("num").style.display='none';
        }        
        
        
     
