var myWidth = 0;
var myHeight = 0;
var resizeDelay = 0;
var IE = navigator.appName.indexOf("Microsoft") != -1;
var FotoActual = -1;
var iaux = new Image();
var Timeriaux = 0;

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 HaCargado( NFoto ){
  if (iaux.height==0){
    Timeriaux = setTimeout("HaCargado("+NFoto+")");
  }else{
    clearTimeout(Timeriaux);
    var FN = document.getElementById("Foto"+NFoto).style;
    FN.display = "block"; 
    FN.visibility = "visible";
    
    var NHeight = (myHeight - (parseInt(document.getElementById("Menu").clientHeight,10)+20+20+20) );
    if (NHeight >= iaux.height){
      FN.height = "auto";
    }else{
      FN.height = (myHeight - (parseInt(document.getElementById("Menu").clientHeight,10)+20+20+20) ) + "px";
    }
  }
}


function MedidaMenu(){
  var Menu = document.getElementById("Menu");
  var Cuerpo = document.getElementById("Cuerpo");
  
  Medidas();
  
  Menu.style.width = (myWidth-20*2) + "px";
  Cuerpo.style.width = (myWidth-20*2) + "px";
  
  Cuerpo.style.paddingTop = (parseInt(Menu.clientHeight,10)+20) + "px";
  Cuerpo.style.display = "block";
  Cuerpo.style.visibility = "visible";
  
  if (FotoActual!=-1){
   if (Escalados[FotoActual-1]!="VIDEO"){
    var FN = document.getElementById("Foto"+FotoActual).style;
    if (Escalados[FotoActual-1]=="SI"){
      iaux.src = document.getElementById("Foto"+FotoActual).src;
      HaCargado(FotoActual);
//      alert(iaux.height + " -- " + FN.height );
    }else{
      FN.height = "auto";
    }
   }
  }
}

function ReEstructurar(){
//  window.moveTo(0,0);
//  window.resizeTo(screen.availWidth, screen.availHeight);
  
  MedidaMenu();

  if (window.captureEvents){
    window.captureEvents(Event.RESIZE);
    window.onresize = function(){
      MedidaMenu();
    };
  }else{
    window.onresize = function(){
      clearTimeout(resizeDelay);
      resizeDelay = setTimeout("MedidaMenu()", 200);
    }
  }
}

function NoPreview( ID ){
  document.getElementById("Pre"+ID).style.display = "none";
  document.getElementById("Pre"+ID).style.visibility = "hidden";
}
function Preview( ID ){
  document.getElementById("Pre"+ID).style.display = "block";
  document.getElementById("Pre"+ID).style.visibility = "visible";
}

function NoPreviewImagenes( ID ){
  if (!IE){
    document.getElementById("Pre"+ID).style.MozOpacity = 0;
    document.getElementById("Pre"+ID).style.opacity = 0;
    document.getElementById("Pre"+ID).style.KhtmlOpacity = 0;
  }else{
    document.getElementById("Pre"+ID).filters[0].opacity=0;
  }
}
function PreviewImagenes( ID ){
  if(!IE){
    document.getElementById("Pre"+ID).style.MozOpacity = 1;
    document.getElementById("Pre"+ID).style.opacity = 1;
    document.getElementById("Pre"+ID).style.KhtmlOpacity = 1;
  }else{
    document.getElementById("Pre"+ID).filters[0].opacity=100;
  }
}

function IrA(Idioma, Categoria, CategoriaStr, Ver, Proyecto, ProyectoStr){
  location.href="?/Idioma/" + Idioma + "/Seccion/Detalle/Categoria/" + CategoriaStr + "/"+Categoria+"/Ver/" + Ver + "/Proyecto/" + Proyecto + "/" + ProyectoStr;
}

function VS( strFoto ){
  location.href = strFoto;
}

function VerFoto( NFoto ){
  if (Escalados[NFoto-1]!="VIDEO"){
    document.getElementById("F"+FotoActual).className="Fotos";
    document.getElementById("F"+NFoto).className="FotosSeleccionado";
  
    var FA = document.getElementById("Foto"+FotoActual).style;
    FA.display = "none";
    FA.visibility = "hidden";
  
    var FN = document.getElementById("Foto"+NFoto).style;
    FN.display = "block"; 
    FN.visibility = "visible";

    if (Escalados[NFoto-1]=="SI"){
      Medidas();
    
      iaux.src = document.getElementById("Foto"+FotoActual).src;
      HaCargado(FotoActual);
//      alert(iaux.height + " -- " + FN.height );
    }else{
      FN.height = "auto";
    }
  }else{
    document.getElementById("F"+FotoActual).className="Fotos";
    document.getElementById("F"+NFoto).className="FotosSeleccionado";
  }
    FotoActual = NFoto;
}
function VerFotoAnterior(){
  if (FotoActual<=1){
    VerFoto(TFotos);
  }else{
    VerFoto(FotoActual - 1);
  }
}
function VerFotoSiguiente(){
  if (FotoActual>=TFotos){
    VerFoto(1);
  }else{
    VerFoto(FotoActual + 1);
  }
}
