document.writeln("<link rel='stylesheet' type='text/css' href='/EstilosEsconde.css'>");
if (navigator.appName == "Konqueror")
   document.writeln("<link rel='stylesheet' type='text/css' href='/Estilos_Konqueror.css'>");
if (navigator.appName == "Opera")
   document.writeln("<link rel='stylesheet' type='text/css' href='/Estilos_Opera.css'>");

function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      if (oldonload)
      {
        oldonload();
      }
      
      func();
    }
  }
}

function getPosition(obj)
{
   if(!obj)
      return false;

   var left = 0;
   var top = 0;

   if(obj.offsetParent)
   {
      left += parseInt(obj.offsetLeft);
      top += parseInt(obj.offsetTop);
   }

   return {x:left, y:top, w: obj.offsetWidth, h: obj.offsetHeight};
}

function muestra_capa(p)
{
   this.id = 'capa_' + (p.id ? p.id : guis.length);
   guis[this.id] = this;
   
   p.amover = ( typeof p.amover != 'undefined' ) ? p.amover : 'left';
   p.posIni = ( typeof p.posIni != 'undefined' ) ? p.posIni : 910;
   p.posFin = ( typeof p.posFin != 'undefined' ) ? p.posFin : 0;
   p.multip = ( typeof p.multip != 'undefined' ) ? p.multip : 1.2;
   p.cuanto = ( typeof p.cuanto != 'undefined' ) ? p.cuanto : (p.posIni / 200);
   p.minimo = ( typeof p.minimo != 'undefined' ) ? p.minimo : 0;

   this.capa_mostrada = 0;
   this.capa     = p.capa[this.capa_mostrada];
   this.psombra  = p.sombra;
   this.amover   = p.amover;
   this.posIni   = p.posIni;
   this.posFin   = p.posFin;
   this.multip   = p.multip;
   this.cuanto   = p.cuanto;
   this.minimo   = p.minimo;
   this.accion   = p.accion;
   this.style    = {opacity: 1};
   
   this.p = [];
   this.p = p;
   
   if(this.posIni > this.posFin)
      this.cuanto = Math.abs(this.cuanto) * -1;

   this.temporizador = false;

   if(!this.capa)
      return false;

   if(!this.capa.style)
      return false;

   this.opacidad = function(x)
   {
      if(typeof x != 'undefined' )
      {
         if(typeof this.capa.style['opacity'] != 'undefined')
            this.capa.style['opacity'] = x;
         else if(typeof this.capa.style['MozOpacity'] != 'undefined')
            this.capa.style['MozOpacity'] = x;
         else if(typeof this.capa.style['KHTMLOpacity'] != 'undefined')
            this.capa.style['KHTMLOpacity'] = x;
         else if(typeof this.capa.style['filter'] != 'undefined')
            this.capa.style['filter'] = "alpha(opacity=" + Math.round(x * 100) + ")";
         else
         {
            // Para navegadores sin opacidad
            this.style.opacity = x;
            if(this.style.opacity > .5)
               this.capa.style['visibility'] = 'visible';
            else
               this.capa.style['visibility'] = 'hidden';
         }
      }
      else
      {
         if(typeof this.capa.style['opacity'] != 'undefined')
            return parseFloat(this.capa.style['opacity']);
         if(typeof this.capa.style['MozOpacity'] != 'undefined')
            return parseFloat(this.capa.style['MozOpacity']);
         if(typeof this.capa.style['KHTMLOpacity'] != 'undefined')
            return Math.round(this.capa.style['KHTMLOpacity'].match(/\d+/)) / 100;
         if(typeof this.capa.style['filter'] != 'undefined')
            return Math.round(this.capa.style['filter'].match(/\d+/)) / 100;

         // Para navegadores sin opacidad
         return this.style.opacity;
      }
   };
   
   this.mueve = function()
   {
      var pos = this.amover == 'opacity' ?
                  this.opacidad() :
                  parseFloat(this.capa.style[this.amover]);

      var final = false;
      if(pos != this.posFin)
      {
         var pos_to = 0;
         
         if((this.posIni > this.posFin && (pos + this.cuanto) > this.posFin) ||
            (this.posIni < this.posFin && (pos + this.cuanto) < this.posFin) )
         {
            pos_to = pos + this.cuanto;
            this.cuanto *= this.multip;
            
            if(Math.abs(this.cuanto) < Math.abs(this.minimo))
            {
               this.cuanto = Math.abs(this.minimo);
               if(this.posIni > this.posFin)
                  this.cuanto *= -1;
            }
         }
         else
         {
            pos_to = this.posFin;
            final = true;
            window.clearInterval(this.temporizador);
         }

         if(this.amover == 'opacity')
            this.opacidad(pos_to);
         else
            this.capa.style[this.amover] = pos_to + 'px';
      }
      else
      {
         window.clearInterval(this.temporizador);
         final = true;
      }
      
      if(final)
      {
         if(typeof this.accion != 'undefined')
         {
            for(var i in this.accion)
            {
               if(typeof this.accion[i] == 'string' )
               {
                  if(typeof this[this.accion[i]] == 'function' )
                     this[this.accion[i]]();
                  else
                     eval(this.accion[i]);
               }
               else if(typeof this.accion[i] == 'function' )
                  this.accion[i]();
            }
         }
         else
         {
            delete guis[this.id];
            delete this;
         }
      }
   };

   /*
      Intercambia los valores iniciales y vuelve a empezar
      accion: ida_y_vuelta
   */
   this.ida_y_vuelta = function()
   {
      var l = this.posIni;
      this.posIni = this.posFin;
      this.posFin = l;
      this.cuanto = this.p.cuanto;
      
      if(this.posIni > this.posFin)
         this.cuanto = Math.abs(this.cuanto) * -1;

      this.activa();
   };
   
   /*
      Cambia la capa a la siguiente
      accion: conmuta_capa
   */
   this.conmuta_capa = function()
   {
      if(!this.accion[this.accion.length - 1].match('ida_y_vuelta') ||
         this.posIni == this.p.posFin)
      {
         this.capa.style.visibility = 'hidden';
         
         if(this.capa_mostrada == this.p.capa.length - 1)
            this.capa_mostrada = 0;
         else
            this.capa_mostrada++;
         
         this.capa = this.p.capa[this.capa_mostrada];
      }
   };
   
   this.activa = function()
   {
      var posOrig = getPosition(this.capa);

      if(this.accion != 'nada')
      {
         if(this.amover == 'opacity')
            this.opacidad(this.posIni);
         else
            this.capa.style[this.amover] = parseFloat(this.posIni) + 'px';
      }

      this.capa.style['visibility'] = 'visible';

      var this_id = this.id;
      if(this.accion != 'nada')
      {
         this.temporizador = window.setInterval(function()
         {
            guis[this_id].mueve();
            return true;
         }, 50);
      }

      if(typeof this.psombra != 'undefined' &&
         typeof this.capa_sombra == 'undefined')
      {
         var zInd = -1;
         if(typeof this.capa.style.zIndex != 'undefined' &&
            this.capa.style.zIndex.length > 0 )
            zInd = this.capa.style.zIndex - 1;

         this.capa_sombra = this.capa.cloneNode(true);
         this.capa_sombra.style.zIndex = zInd;
         this.capa_sombra.style.color = '#aaa';
         this.capa_sombra.style.position = 'absolute';
         this.capa_sombra.style.display = 'block';

         this.capa_sombra.style.top = '' + (posOrig.y + 5) + 'px';
         this.capa_sombra.style.left = '' + (posOrig.x + 5) + 'px';

         this.capa_sombra.style.visibility = 'hidden';
         this.capa.parentNode.appendChild(this.capa_sombra);
         
         this.psombra['id'] = this.id + '_sombra';
         this.psombra['capa'] = [this.capa_sombra];
         this.psombra['posIni'] =
            typeof this.psombra['posIni'] != 'undefined' ?
               this.psombra['posIni'] : 0.;
         this.psombra['posFin'] =
            typeof this.psombra['posFin'] != 'undefined' ?
               this.psombra['posFin'] : 1.;
         this.psombra['amover'] =
            typeof this.psombra['amover'] != 'undefined' ?
               this.psombra['amover'] : 'opacity';
         this.psombra['cuanto'] =
            typeof this.psombra['cuanto'] != 'undefined' ?
               this.psombra['cuanto'] : 0.03;
         this.psombra['multip'] =
            typeof this.psombra['multip'] != 'undefined' ?
               this.psombra['multip'] : 1.;
         this.sombra = new muestra_capa(this.psombra);
      }

      return false;
   };
   
   this.activa();

   return this;
}


function cierra(event)
{
   var divs = {};
   divs['cuerpo'] = document.getElementById('cuerpo_1');
   divs['foto']   = document.getElementById('foto');

   var final = "";
   var href = "";
   var go_external = false;

   if(event.target && event.target.href)
      href = event.target.href;
   else if(event.currentTarget && event.currentTarget.href)
      href = event.currentTarget.href;
   else if(event.target.nodeName == "#document")
      go_external = true;
   
   window.onunload = function(){};
   window.onbeforeunload = function(){};
   
   if(!go_external)
   {
      final = function(){ window.location.href = href; };
      
      if(divs['foto'])
         new muestra_capa({
            id: 'foto_final',
            capa: [divs['foto']],
            amover: 'left',
            multip: 1.40,
            minimo: 5,
            cuanto: 5,
            posIni: 0,
            posFin: -310,
            accion: ''});
      new muestra_capa({
         id: 'cuerpo_final',
         capa: [divs['cuerpo']],
         multip: 1.60,
         minimo: 5,
         cuanto: 5,
         posIni: 0,
         posFin: 900,
         accion: [final]});
      
      return false;
   }
}

var guis = {};

window.onbeforeunload = cierra;
window.onunload = cierra;

addLoadEvent(function()
{
   // Arreglamos el no espaciado que -no- hace el IE6 entre fieldsets (pq? quién sabe...)
   if (navigator.appName.indexOf("Explorer") > -1 && navigator.appVersion.indexOf("MSIE 6") > -1)
   {
      var fieldsets = document.getElementsByTagName('fieldset');
      for(var i = 0, length = fieldsets.length - 1; i < length; i++)
      {
         var separador = document.createElement('div');
         separador.style.display = 'block';
         separador.style.height = '1px';
         separador.style.margin = '0';
         separador.style.padding = '0';
         separador.innerHtml = "&nbsp;";
         fieldsets[i].parentNode.insertBefore(separador,fieldsets[i].nextSibling);
      }
   }

   // Vamos a por lo way :)
   var divs = [];
   divs['cabecera1'] = document.getElementById('cabecera_1');
   divs['cabecera2'] = document.getElementById('cabecera_2');
   divs['cuerpo']    = document.getElementById('cuerpo_1');
   divs['foto']      = document.getElementById('foto');

   divs['cabecera1'].style.zIndex = 10;
   divs['cabecera2'].style.zIndex = 20;
   
   new muestra_capa({
      id: 'cabecera1',
      capa: [divs['cabecera1']],
      accion: 'nada',
      sombra:{
         id: 'cabecera1',
         capa: [divs['cabecera1']],
         posIni: 0.,
         posFin: 1.,
         amover: 'opacity',
         cuanto: 0.06,
         multip: .941,
         minimo: .01,
         accion: ['ida_y_vuelta']}});
   new muestra_capa({
      id: 'cabecera2',
      capa: [divs['cabecera2']],
      accion: 'nada',
      sombra:{
         id: 'cabecera2',
         capa: [divs['cabecera2']],
         posIni: 0.,
         posFin: 1.,
         amover: 'opacity',
         cuanto: 0.06,
         multip: .941,
         minimo: .01,
         accion: ['ida_y_vuelta']}});
   new muestra_capa({
      id: 'cuerpo',
      capa: [divs['cuerpo']],
      multip: .60,
      minimo: 5,
      cuanto: 350,
      accion: ''});
   if(divs['foto'])
      new muestra_capa({
         id: 'foto',
         capa: [divs['foto']],
         amover: 'left',
         multip: .80,
         minimo: 5,
         cuanto: 60,
         posIni: -310,
         posFin:  0,
         accion: ''});

   divs['nube'] = document.getElementById('nube_textos');
   var nube = [];
   if(divs['nube'].nodeName.toUpperCase() == 'DIV')
   {
      var n = 0;
      if(divs['nube'].childNodes)
      {
         for(var j in divs['nube'].childNodes)
         {
            if(typeof divs['nube'].childNodes[j] == 'object' &&
               divs['nube'].childNodes[j].nodeType == 1  &&
               divs['nube'].childNodes[j].nodeName.toUpperCase() == 'DIV')
            {
               nube[n] = divs['nube'].childNodes[j];
               n++;
            }
         }
      }
   }

   if(typeof nube == 'object' &&
      nube.length > 0 )
      new muestra_capa({
         id: 'nube_textos',
         capa: nube,
         posIni: 0.,
         posFin: 1.,
         amover: 'opacity',
         cuanto: 0.06,
         multip: .941,
         minimo: .01,
         accion: ['conmuta_capa', 'ida_y_vuelta']});

   /*
      Cambiamos los anchors para que descarguen el cuerpo
      antes de ir a la siguiente página
   */
   var anchors = document.getElementsByTagName('a');
   var mailto = '&#109;&#97;&#105;&#108;&#116;&#111;';
   for(var i in anchors)
   {
      var href = anchors[i].href;
      var no_fer = (anchors[i].className && anchors[i].className.search(/\bnofer\b/) != -1 ? true : false);
      if(href && !href.match('mailto') && !href.match(mailto) && no_fer == false)
      {
         anchors[i].onclick = cierra;
      }
   }
   
   return false;
});


