
var lat_izq_height=null;

$(document).ready(function(){
    /*
var settings={
        imageLoading:			'/res/img/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
        imageBtnPrev:			'/res/img/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
        imageBtnNext:			'/res/img/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
        imageBtnClose:			'/res/img/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
        imageBlank:				'/res/img/lightbox-blank.gif',
        txtImage:"",
        txtOf:" / "
    }
    $('.galeria4 a').lightBox(settings);
*/
    hs.showCredits = 0;
    hs.graphicsDir = '/res/img/graphics/';
    hs.align = 'center';
    hs.transitions = ['expand','fade']; // ,'crossfade',
    hs.outlineType = 'rounded-white';
    hs.fadeInOut = true;
    hs.dimmingOpacity = 0.75;

    // define the restraining box
    /*
	hs.useBox = true;
	hs.width = 640;
	hs.height = 480;
    */
    hs.captionEval = 'this.thumb.title';

    // Add the controlbar
    hs.addSlideshow({
        //slideshowGroup: 'group1',
        interval: 3000,
        repeat: false,
        useControls: true,
        fixedControls: 'fit',
        overlayOptions: {
            opacity: 1,
            position: 'bottom center',
            hideOnMouseOut: true
        }
    });

    /*
    hs.Expander.prototype.onMouseOver = function() {
        alert("hola onMouseOver");
    }

    hs.Expander.prototype.onMouseOut = function() {
        alert("hola onMouseOut");
    }

*/
    
    $('.menu-lat-pie').show();
    //reposicionarCapas();



   adaptacion();


    // alert("menu: "+$("#lat_iz .menu").height()+"  menu-lat-pie: "+$("#lat_iz .menu-lat-pie").height()+"   contenido: "+$("#contenido").height()+"   lateral: "+$("#lat_iz").height()+"  central: "+$("#central").height());


    $('#ventana-alerta-jqmodal').jqm({ 
        toTop: true
    });
    $('#ventana-info-jqmodal').jqm({ 
        toTop: true
    });

});


function adaptacion()
{
    if(lat_izq_height==null)
    {
        $("#lat_iz").height($("#lat_iz .menu").height()+$("#lat_iz .menu-lat-pie").height()); //+$("#lat_iz .menu-lat-pie .menu").height();
        lat_izq_height=$("#lat_iz").height();
    }

    if(lat_izq_height<$("#central").height())
        $("#lat_iz").height($("#central").height());
}


var contadorReposicionarCapasGaleria=0;

function reposicionarCapasItem()
{
    
    h1=$("#lat_iz").height();
    h2=$("#contenidohtml").height()+$("#navegacion-tienda").height();

    if(h2>h1)
        $("#lat_iz").height(h2);
    else if(h1>h2)
        $("#contenidohtml").height(h1-$("#navegacion-tienda").height());

//alert("reposicionarCapasItem   - lat_iz: "+$("#lat_iz").height()+"  central: "+$("#central").height()+"   contenidohtml: "+$("#contenidohtml").height()+" h1: "+h1+"   h2: "+h2);
}



function reposicionarCapasGaleria(filas)
{
    //alert($(".galeria4 .elemento").length);

    if($(".galeria4-tienda .elemento").length>0)
        gal=".galeria4-tienda";
    else if($(".galeria4 .elemento").length>0)
        gal=".galeria4";
    else
        return;
    
    elm=$(gal+" .elemento").length;
    galeriaHeight=filas * $(gal+" .elemento:first-child").height();
    $(gal).height(galeriaHeight);

    h1=$("#lat_iz").height();
    h2=$("#contenidohtml").height()+$("#navegacion-tienda").height();
    contadorReposicionarCapasGaleria++;

    if(h2>h1)
        $("#lat_iz").height(h2);
    else if(h1>h2)
        $("#contenidohtml").height(h1-$("#navegacion-tienda").height());
    
//if(contadorReposicionarCapasGaleria==20)
//alert(""+contadorReposicionarCapasGaleria+"lat_iz: "+$("#lat_iz").height()+"  central: "+$("#central").height()+"   contenidohtml: "+$("#contenidohtml").height()+" h1: "+h1+"   h2: "+h2+"   "+gal+": "+galeriaHeight +"   filas: "+filas);
    
}

function reposicionarCapas()
{

    if( $("#lat_iz").height() ==  $("#central").height())
        return ;
    //reposicionarCapasGaleria(5);
    h2=$("#central").height();
    menu_lat_pie=$(".menu-lat-pie").height()+50;
    min=400;
    if(h2<min)
    {
        h2=min;
        $("#central").height(h2);
    }
    
    h1=$("#lat_iz").height();
    $("#lat_iz").height(h1+menu_lat_pie);
    h1=h1+menu_lat_pie;
    alert("reposicionarCapasItem   - lat_iz: "+$("#lat_iz").height()+"  central: "+$("#central").height()+"   contenidohtml: "+$("#contenidohtml").height()+" h1: "+h1+"   h2: "+h2);
    if(h2>h1)
        $("#lat_iz").height(h2);
    else if(h1>h2)
        $("#central").height(h1);
    
}

function mostrarMensaje(m,t)
{
    $("#mensaje_box").text(m);
    setTimeout('$("#mensaje_box").text("");',3000);
}











function abrirModal(tipo,ht,w,h)
{
    ventana=$("#ventana-"+tipo+"-jqmodal");
    contenido_ventana=$("#ventana-"+tipo+"-jqmodal-contenido");
    if(ht!="")
        contenido_ventana.html(ht);
    $("#ventana-"+tipo+"-jqmodal-contenido > label").css("display","block");
    $("#ventana-"+tipo+"-jqmodal-contenido").show();
    if(ht!=null)ventana.jqmShow();
    ventana.css("width", w);
    ventana.css("height", "auto");
    ventana.css("margin-left", -w/2);

}

function abrirModalAlerta(ht)
{
    abrirModal("alerta",ht,350,100);
}

function abrirModalInformacion(ht)
{
    abrirModal("info",ht,350,100);
}

function abrirModalValidacionFormulario(ht)
{
    abrirModal("alerta",ht,350,100);
}

function abrirVentana(url)
{
    window.open(url,url,"");
}

function trim(str)
{
    str = str.replace(/^\s*|\s*$/g,"");
    return str;
}

function ejecutarCerrar()
{
    close();
}

/*******************************************/

jQuery.fn.formToArray = function(semantic){
    var a = [];
    var q = semantic ? ':input' : 'input,textarea,select,button';

    jQuery(q, this).each(function() {
        var n = this.name;
        var t = this.type;
        //alert(n +" "+t);
        if ( !n || this.disabled || t == 'reset' ||
            (t == 'checkbox' || t == 'radio') && !this.checked ||
            (t == 'submit' || t == 'image' || t == 'button') && this.form && this.form.clk != this ||
            this.tagName.toLowerCase() == 'select' && this.selectedIndex == -1)
            return;

        if (t == 'image' && this.form.clk_x != undefined)
            return a.push(
            {
                name: n+'_x',
                value: this.form.clk_x
            },

            {
                name: n+'_y',
                value: this.form.clk_y
            }
            );
        if (t == 'select-multiple') {
            jQuery('option:selected', this).each( function() {
                a.push({
                    name: n,
                    value: this.value
                });
            });
            return;
        }
        a.push({
            name: n,
            value: this.value
        });
    });
    return a;
};
