var isNav = (navigator.appName.indexOf("Netscape") !=-1);
var myWidth = 0;
var myHeight = 0;
var myHeight2 = 0;
var myWidth2 = 0;
var IDTimer = 0;
var resizeDelay = 0;

function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try{
      if (sMethod == "GET"){
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }else{
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete){
          bComplete = true;
          fnDone(xmlhttp);
        }
      };
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function Medidas(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }else if( document.documentElement ){
    if ( document.documentElement.clientWidth || document.documentElement.clientHeight ){
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    }else if ( document.body.clientWidth || document.body.clientHeight ){
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
  }else if( document.body ){
    if( document.body.clientWidth || document.body.clientHeight ){
      //IE 4 compatible
       myWidth = document.body.clientWidth;
       myHeight = document.body.clientHeight;
     }
  }
}



function Reposicionar(){
  Medidas();
  
  var Contenido = document.getElementById("Contenido").style;
  if (Seccion == "Entrada"){
      document.body.style.overflow = "hidden";
      iW = 1600;
      iH = 1100;
      if (FE_Aa == "A" ){
//        if (myHeight != myHeight2){
        myHeight2 = myHeight;
        Contenido.width = myWidth + "px";
        Contenido.height = (myHeight-100) + "px";     
      
        NH = myHeight-100;
        NW = Math.floor((NH * iW)/iH);
      
        if (NW > myWidth){
          NW = myWidth;
          NH = Math.floor((myWidth * iH)/iW);
        }
      
        var CImgE = document.getElementById("CImgEntrada").style;
        var ImgE = document.getElementById("ImgEntrada").style;
        ImgE.width = NW + "px";
        ImgE.height = NH + "px";
      
        CImgE.width = NW + "px";
        CImgE.height = NH + "px";
        CImgE.top = "0px";
        CImgE.left = (Math.floor(myWidth/2 - NW/2))+"px";
//        }
      }else if ( FE_Aa == "a" ){
//        if (myWidth != myWidth2){
        myWidth2 = myWidth;
        Contenido.width = myWidth + "px";
        Contenido.height = (myHeight-100) + "px";     
      
//        NH = myHeight-100;
//        NW = Math.floor((NH * iW)/iH);
        NW = myWidth;
        NH = Math.floor((NW * iH)/iW);
      
/*        if (NW > myWidth){
          NW = myWidth;
          NH = Math.floor((myWidth * iH)/iW);
        }*/
      
        var CImgE = document.getElementById("CImgEntrada").style;
        var ImgE = document.getElementById("ImgEntrada").style;
        ImgE.width = NW + "px";
        ImgE.height = NH + "px";
      
        CImgE.width = NW + "px";
        CImgE.height = NH + "px";
        CImgE.top = (Math.floor(myHeight/2 - NH/2))+"px";
        CImgE.left = "0px";
//        }
      }
  }else if (Seccion == "Estudio"){
    for(i=1;i<TFotos;i++){
      var ITE = document.getElementById("ITE"+i).style;
      
      NH = myHeight-119;
      ITE.height = NH + "px";      
    }
  }
  
  Contenido.display = "block";
  Contenido.visibility = "visible";
  
  
  
/*  if (myHeight-119 < 490){
    var p = Math.floor( 490*100 / (myHeight-119) )/100;
  }else{
    var p = Math.floor( (myHeight-119)*100 / 490 )/100;
  }*/
    
   var p = (myHeight-150) / 850;
    $(".ImgCorreccion").load(function() {
      // Remove attributes in case img-element has set width and height
      $(this).removeAttr("width")
             .removeAttr("height")
             .css({ width: "", height: "" }); // Remove css dimensions as well

      new_width = Math.floor(this.width * p);
      new_height = Math.floor(this.height * p);
      
      $(this).css({ width: new_width+"px", height: new_height+"px" });
    });
}

function ReEstructurar(){
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth, screen.availHeight);

  Reposicionar();
}


function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function Posicion( X, Inc, Veces, Velocidad ){
  clearTimeout(IDTimer);
  
  self.scrollTo(X+Inc,0);
  Veces--;
  if (Veces > 0){
    IDTimer = setTimeout("Posicion("+(X+Inc)+","+Inc+","+Veces+","+Velocidad+")", Velocidad);
  }else{
    document.getElementById( ElemActual ).style.visibility = "visible";
    EnOver = false;
  }
}

function MoverInicio(){
  var Pos = 0;
  var PosActual = f_scrollLeft();
  var Veces = 20;
  var Incrementos = new Array( Veces );
  var Inc = (Pos-PosActual) / Veces;
  var Velocidad = 50;
  
  if (Inc != 0 ){
    IDTimer = setTimeout("Posicion("+PosActual+","+Inc+","+Veces+","+Velocidad+")", Velocidad);
  }
}

function PonerLoading( ID ){
  var Contenedor = document.getElementById( ID );
  var HTML = "";
  
  HTML += "<img src=\"Imagenes\/ajax-loader.gif\" width=\"16\" height=\"16\" alt=\"\" border=\"0\">";
  
  Contenedor.innerHTML = HTML;
}

function SiguienteImagenEntrada( ID ){
    var ajaxConn = new XHConn();
    var URLForm = "Include_s/SFEntrada.asp";
    var Variables = "";
    var Metodo = "GET"; //"GET" //"POST"
  
    Variables = "FE=" + ID;

    PonerLoading( "CImgEntrada" );

    ajaxConn.connect(URLForm,
                    Metodo,
                    Variables,
                    function(XML){
                      var D = XML.responseText.split("[d]")[1].split("[/d]")[0];
                      var F = XML.responseText.split("[f]")[1].split("[/f]")[0];
                      
                      document.getElementById("CImgEntrada").innerHTML = F;
                      FE_Aa = D;
                      Reposicionar();
                    }
                    );
}

