var lastOpen = false;
var fixedMenu = false;
var lastAct = false;
var lastMoveFlecha = false;
var lastChangeView = false;
var openMe = false;
var espera = false;
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "";
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
var busquedaLong =false;
var tooltips = Array();

if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}


function blurLink(theObject)	{	
	if(theObject.blur)theObject.blur();
}

function buscadorCronologia() {
	ano = document.getElementById('buscadorInput').value;
	if ( ano == (ano*1) &&  ano.length == 4 ) {
		if ( anos[ano] == (anos[ano]*1)  ) {
			document.getElementById('noencontrado').style.display='none';
			window.location='/index.php?id='+anos[ano]; 
		} else {
			document.getElementById('noencontradocadena').innerHTML = ano
			document.getElementById('noencontrado').style.display='';
		}
	} else {
		alert(busquedaLong);
		document.getElementById('noencontrado').style.display='none';
		
	}

	return false;
}

function windowOpenImg(url,w,h) {
	if ( w > 700 ) { w = 700; } 
	if ( h > 530 ) { h = 530; } 
 	window.open(url,'imgZoom','status=0,resizable=1,scrollbars=1,toolbars=0,location=0,directories=0,menubar=0,left=10,top=10,width='+w+'height='+h);
}


function customOnLoad() { 
        BrowserDetect.init();
        //alert(BrowserDetect.browser + " " +BrowserDetect.version);
        if (BrowserDetect.browser != 'safari') {
                //convert();
        }
        if (openMe != false) {
                moveFlecha(openMe,'menu',0,true);
lastChangeView = openMe;
        }
                window.onresize=redimension;
}

function redimension() {
	if (espera) { return; }
        if (lastMoveFlecha) {
	  	if ( lastMoveFlecha != 55 ) {
		  moveFlecha(lastMoveFlecha,'menu',1,true);
		}
        }
}


function encima(id) {
        if ( id != lastOpen ) {
                document.getElementById("flecha"+id).className="flecha_der";
        }
}

function fuera(id,force) {
        if ( id != lastOpen ) {
                document.getElementById("flecha"+id).className="flecha_vacia";
        }
}

function pinchar(id) {
        if ( document.getElementById("submenu"+id).style.display=='none' ) 
            { 
                document.getElementById("submenu"+id).style.display='block';
                document.getElementById("flecha"+id).className="flecha";
                if ( lastOpen != false ) 
                 { 
                    pinchar(lastOpen);  
                 }
                lastOpen = id;
            }
           else {
                document.getElementById("submenu"+id).style.display='none';
                document.getElementById("flecha"+id).className="flecha_vacia";
                lastOpen = false;
           }
}

function changeView (id) {
        if ( document.getElementById('submenu'+id).style.display != 'none' ) {
                document.getElementById('submenu'+id).style.display = 'none';
                hideFlecha(0);
                lastChangeView = false;
		fixedMenu = false;
        } else {
                document.getElementById('submenu'+id).style.display = '';
                if ( lastChangeView ) { 
                        changeView(lastChangeView);
                }

                moveFlecha(id,'menu',0,true);
                lastChangeView = id;
        }

	return false;
}

function moveFlecha(id,tag,act,fixed) {
	espera = true;
        if (fixed == true) { fixedMenu = id; }

        lastAct=act;

        document.getElementById('flecha').style.top = (findPosY(tag+id)+7) +'px';
        document.getElementById('flecha').style.left = (findPosX(tag+id)-15) + 'px';
        document.getElementById('flecha').style.display = '';

        if (id == 55 && document.getElementById('masprado'+id).style.display != '') { 
		document.getElementById('masprado'+id).style.display = ''; 
	}

	if (act == 1 ) {
                document.getElementById('flecha').src="/fileadmin/templates/prado/main/iconos/fderN.gif";
        } else {
                document.getElementById('flecha').src="/fileadmin/templates/prado/main/iconos/fabaN.gif";
        }
        lastMoveFlecha = id;
	espera = false;
}

function hideFlecha(act) {
	document.getElementById('masprado55').style.display = 'none'; 
//	if ( lastAct == act ) {
			if ( fixedMenu != false ) {
				document.getElementById('flecha').style.display = 'none';
				if ( lastMoveFlecha == 55 ) { return; }
				moveFlecha(fixedMenu,"menu",1);
			} else {
				document.getElementById('flecha').style.display = 'none';
			}
//	}
}


function findPosX(id) {
        obj=document.getElementById(id);
        var curleft = 0;
        if (obj.offsetParent)   {
                while (obj.offsetParent)                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosY(id) {
	obj=document.getElementById(id);
        var curtop = 0;
	if (obj.offsetParent) {
                do {
                        curtop += obj.offsetTop;
                        obj = obj.offsetParent;
                }
		while (obj.offsetParent); 

        } else if (obj.y) {
                curtop += obj.y;
	}
        return curtop;
}

function changeColor(id,mode,tag) {

        if ( mode == 1 ) {
                document.getElementById(tag+id).style.backgroundColor ="#efefef";
        } else {
                document.getElementById(tag+id).style.backgroundColor ="#c6c6c6";
                if ( id == 55 ) { document.getElementById('masprado'+id).style.display = ''; }
        }
}

function onObra (title,piso,url) {
        caption='';
        text='';
        //overlib.ov(title,caption,text);
	//overlib(title,caption,text);



        if ( document.getElementById("planoGeneral"+piso) ) {
                document.getElementById("planoGeneral"+piso).src = url;
        }
} 

function outObra () {
        if ( document.getElementById("planoGeneralB") ) {
                document.getElementById("planoGeneralB").src = "/plano/B/0/1/550/550/plano.png"; 
        }
        if ( document.getElementById("planoGeneralP") ) {
                document.getElementById("planoGeneralP").src = "/plano/P/0/1/550/550/plano.png";
        }
        if ( document.getElementById("planoGeneralS") ) {
                document.getElementById("planoGeneralS").src = "/plano/S/0/1/550/550/plano.png";
        }

        //nd();
}

function borderObrasMaestras(obj,color) {
	obj.style.border="1px solid " + color;
}
function opcityObrasMaestras(obj,value) {



	if (BrowserDetect.browser == 'firefox') {
		obj.style.MozOpacity = value;
	} else {
		obj.style.filter = "alpha(opacity:"+(value*100)+")";
		//obj.style.filter.alpha.opacity= = value * 100;
	}
}
function oscurecerBoton(id) {
        var dvBt=document.getElementById(id);
       //  alert(dvBt.style.backgroundColor);
   	dvBt.style.backgroundColor='#545454';
                // alert(dvBt.parentNode.tagName);
          
        var padre=dvBt.parentNode.tagName;
	var padreId=dvBt.parentNode.id;
        // if(padre=="TD" || padre=="DIV") {
	   if(padre=="TD" && padreId=="buscadorTDBoton") {
               document.getElementById(dvBt.parentNode.id).style.backgroundColor='#545454';
        }
}

function moverVentana()
  {
              var posLeft=(window.screen.availWidth / 2) - (650 / 2);
               var posTop=(window.screen.availHeight / 2) - (250 / 2);
              window.moveTo(posLeft, posTop);
 }

// Recoge las variables ruta de imagen y tÃÂ­tulo por GET para ponerlas en el plano
// Ex. (index.html?img=....&txt=.....
function getQueryVariable() {
      var query1 = window.location.search.substring(1);
      var queryT = query1.split("&");
      var autor =queryT[2].split("autor=");   
      autor=autor;
      var ubicacion=queryT[3].split("ubicacion=");
      ubicacion=decodeURIComponent(ubicacion[1]);
      autor=decodeURIComponent(autor[1]);
      var ruta=unescape(query1).split("&");      
      var temp="";
            for (var i=0;i<ruta.length;i++) {
               temp += ruta[i];
             } 
    temp=queryT[0].split("img=");
    var pather=temp[1];
    var titCuadro=queryT[1].split("txt=");
    titCuadro= decodeURIComponent(titCuadro[1]);
              document.getElementById('cabeceraPlano').innerHTML="<div style='font-weight:bolder !important;'>" + 
              autor +", <br><span style='font-weight:bolder !important;font-style:italic !important; '>" + titCuadro + "</span></div>" +
               "<div>" + ubicacion + "</div>";
              document.getElementById('plMuseo').src=pather;
              var posLeft=(window.screen.availWidth / 2) - (650 / 2);
               var posTop=(window.screen.availHeight / 2) - (250 / 2);
              moverVentana();
               }

function validarBusca() {
var cajaIzq=document.getElementById('buscador').value;
var mensaje='La palabra buscada debe tener al menos 3 letras';	
	
	if(document.getElementById('buscadorInputCentro')) {
		var caja=document.getElementById('buscadorInputCentro').value;
	}

	if(document.getElementById('buscadorInputCentro')) {
		if(caja.length < 3 && cajaIzq.length < 3) {
		document.getElementById('tx_indexedsearchLateral').action='';
		document.getElementById('tx_indexedsearch').action='';
		 window.alert(mensaje);
		return false;
		}
	}
	else {
		if(cajaIzq.length < 3) {
		document.getElementById('tx_indexedsearchLateral').action='';
		window.alert('La palabra buscada debe tener al menos 3 letras');
                return false;
		}
	}
}

var BrowserDetect = {
        init: function () {
                this.browser = this.searchString(this.dataBrowser).toLowerCase() || "An unknown browser";
                this.version = this.searchVersion(navigator.userAgent)
                        || this.searchVersion(navigator.appVersion)
                        || "an unknown version";
                this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function (data) {
                for (var i=0;i<data.length;i++) {
                        var dataString = data[i].string;
                        var dataProp = data[i].prop;
                        this.versionSearchString = data[i].versionSearch || data[i].identity;
                        if (dataString) {
                                if (dataString.indexOf(data[i].subString) != -1)
                                        return data[i].identity;
                        }
                        else if (dataProp)
                                return data[i].identity;
                }
        },
        searchVersion: function (dataString) {
                var index = dataString.indexOf(this.versionSearchString);
                if (index == -1) return;
                return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
        },
        dataBrowser: [
                {
                        string: navigator.vendor,
                        subString: "Apple",
                        identity: "Safari"
                },
                {
                        prop: window.opera,
                        identity: "Opera"
                },
                {
                        string: navigator.vendor,
                        subString: "iCab",
                        identity: "iCab"
                },
                {
                        string: navigator.vendor,
                        subString: "KDE",
                        identity: "Konqueror"
                },
                {
                        string: navigator.userAgent,
                        subString: "Firefox",
                        identity: "Firefox"
                },
                {               // for newer Netscapes (6+)
                        string: navigator.userAgent,
                        subString: "Netscape",
                        identity: "Netscape"
                },
                {
                        string: navigator.userAgent,
                        subString: "MSIE",
                        identity: "Explorer",
                        versionSearch: "MSIE"
                },
                {
                        string: navigator.userAgent,
                        subString: "Gecko",
                        identity: "Mozilla",
                        versionSearch: "rv"
                },
                {               // for older Netscapes (4-)
                        string: navigator.userAgent,
                        subString: "Mozilla",
                        identity: "Netscape",
                        versionSearch: "Mozilla"
                }
        ],
        dataOS : [
                {
                        string: navigator.platform,
                        subString: "Win",
                        identity: "Windows"
                },
                {
                        string: navigator.platform,
                        subString: "Mac",
                        identity: "Mac"
                },
                {
                        string: navigator.platform,
                        subString: "Linux",
                        identity: "Linux"
                }
        ]

};


customOnLoad();
