﻿var posicX = 0;
var posicY = 0;
var aumento = 0;
var innerHeight;
var innerWidth;

$(document).ready(function() {

    if (leerParametro('tipo') == '1') {
        $("#dvBuscadorSimple").css("display", "none");
        $("#dvBuscadorAvanzado").css("display", "block");
    }

    $(".imgFachadas").mouseover(function() {
        var ruta;
        ruta = this.src;
        //alert(ruta.indexOf('ARCHIVOS_VIDEOS'));
        if (ruta.substr(ruta.lastIndexOf('/') + 1, ruta.length) != 'imgSinFachada.png' && ruta.indexOf('ARCHIVOS_VIDEOS') == -1) {
            aumento = 2;
            ruta = ruta.substr(0, ruta.length - 7) + 'gra.jpg';
            mostrarFachada(ruta);
        }

    });

    $(".imgFachadas").mouseout(function() {
        ocultar();
    });

    var IE = document.all ? true : false
    if (!IE) document.captureEvents(Event.MOUSEMOVE)

    document.onmousemove = posicRatonXY;

    function posicRatonXY(e) {
        if (typeof (window.innerHeight) == 'number') {
            innerHeight = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            innerHeight = document.documentElement.clientHeight;
        } else if (document.body && document.body.clientHeight) {
            innerHeight = document.body.clientHeight;
        }
        if (typeof (window.innerWidth) == 'number') {
            innerWidth = window.innerWidth;
        } else if (document.documentElement && document.documentElement.clientWidth) {
            innerWidth = document.documentElement.clientWidth;
        } else if (document.body && document.body.clientWidth) {
            innerWidth = document.body.clientWidth;
        }
        if (IE) {
            posicX = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
            posicY = event.clientY + document.documentElement.scrollTop + document.body.scrollTop
        }
        else { posicX = e.pageX; posicY = e.pageY };
        if (posicX < 0) { posicX = 0 };
        if (posicY < 0) { posicY = 0 };
        posicionarAumento(aumento);
        return true
    }

});

function posicionarAumento(aumento) {

    if (aumento == 1) {
          document.getElementById("aumento").style.left = posicX - 385 + "px";
          document.getElementById("aumento").style.top = posicY - 250 + "px";
    }
    else if (aumento == 2){
            document.getElementById("aumento").style.left = posicX - 610 + "px";
            document.getElementById("aumento").style.top = posicY - 200 + "px";
    }
}

   function centradoVertical(imagen,modulo) {
       if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
           var ieversion = new Number(RegExp.$1);

           if (ieversion >= 8) {
               if (modulo == 'ML') {
                   imagen.style.margin = ((105 - imagen.height) / 2) + 'px 0px 0px 0px';
               }
               else {
                   imagen.style.margin = ((98 - imagen.height) / 2) + 'px 0px 0px 0px';
               }
               
           }
           else if (ieversion >= 6) {
           
//             Hack para ie 6 para max-height y max-width
               imagenLogo = new Image();
               imagenLogo.src = imagen.src;

               if (imagenLogo.width > imagenLogo.height) {
                   imagen.width = 100;
               } else {
                   imagen.height = 90;
               }
          
           }

       }
       else {
           if (modulo == 'ML') {
               imagen.style.margin = ((105 - imagen.height) / 2) + 'px 0px 0px 0px';
           }
           else {
               imagen.style.margin = ((98 - imagen.height) / 2) + 'px 0px 0px 0px';
           }
           
       }


   }

   function mostrar(ruta) {
       if (ruta) {
           var contenedor = document.getElementById("aumento");
           contenedor.innerHTML = "<img src='" + ruta + "'/>";
           contenedor.style.display = "block";
       }
       
   }

   function mostrarFachada(ruta) {
       var contenedor = document.getElementById("aumento");
       contenedor.innerHTML = "<img src='" + ruta + "'/>";
       contenedor.style.display = "block";
   }
   
   
   
   function ocultar() {
       var contenedor;
       contenedor = document.getElementById("aumento");
       contenedor.style.display = "none";

   }


   function cambiaTamano(agrandar) {
       guardarEstadoMapa();

       if ($("#dvGMap").attr("class") == 'pequeno' || agrandar == true) {
           $("#dvGMap").attr("class", "grande");

           $("#spanReducir").css("display", "inline");
           $("#spanAgrandar").css("display", "none");
           
        }
        else if ($("#dvGMap").attr("class") == 'grande' || agrandar == false) {
        $("#dvGMap").attr("class", "pequeno");
        $("#spanReducir").css("display", "none");
        $("#spanAgrandar").css("display", "inline");
    }
        
    refrescarMapa();
    cargarEstadoMapa();

}

function leerParametro(nombre) {
    var regexS = "[\\?&]" + nombre + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var tmpURL = window.location.href;
    var results = regex.exec(tmpURL);
    if (results == null)
        return "";
    else
        return results[1];
}
   
