// JavaScript main site

var GET = "";
var idVideoActual="";
var urlHashActual = "";
var posBackgroundActual = 410;
var kioscoActual = "futbol";
var heightInitMenuLateral = 0;
var imgBack = new Image();
var returnBackAction = function(){};
var imgPreloadStyle = '<div style="width: 250px; margin-left: 10px; margin-top: 10px; font:normal 11px verdana;"><img align="absmiddle" src="img/ajax-loader.gif" border="0"/> Cargando contenido...</div>';

function posActionBack(kiosco){
    var res;
    switch (kiosco) {
        case "futbol":
            res = 2990;
            posBackgroundActual = 2990;
            $("#futbol").css({"display":"none"});
            break;
        case "musica":
            res = 5100;
            posBackgroundActual = 5100;
            $("#musica").css({"display":"none"});
            break;
        default:
        break;
    }
    kioscoActual = kiosco;
    return res;
}

function animationActionBack(){
    switch (kioscoActual) {
        case "futbol":
            $("#futbol").css({"display":"block"});
            break;
        case "musica":
             $("#futbol").css({"display":"none"});
            break;
        default:
        break;
    }
}

function get(){
	var temp, arrayTemp = [];
	var get = window.location.search;
	get = get.substring(1);
	var aux = get.split("&");
	for(var i=0; i<aux.length ; i++){
		temp = aux[i].split("=");
		arrayTemp[temp[0]] = temp[1];
	}
	return arrayTemp;
}

function loadBlur(){
    try{
        Pixastic.process(document.getElementById("demoimage"), "blurfast", {
                amount : 0.3
        });
    }catch(e){}
}

function resetBlur() {
    try{
	Pixastic.revert(document.getElementById("demoimage"));
        }catch(e){}
}

function llamarModal(template,urlArg){
    //$.colorbox({html:"Hola como estas?"});
    cerrarContenedorSecciones(true);
    var url = "templates/"+template;
   // alert(url);
    $.colorbox({href:url,top:10});
    getContent(urlArg);

    loadBlur();
    
}

function esconderElementosHome(){
    if($("#namesectionsite").val() == "./"){
        $("#kiosco1").css("display","none");
        $("#kiosco5").css("display","none");
        $("#kiosco6").css("display","none");
    }
}

function mostrarElementosHome(){
    if($("#namesectionsite").val() == "./"){
        $("#kiosco1").css("display","block");
        $("#kiosco5").css("display","block");
        $("#kiosco6").css("display","block");
    }
}

function llamarModalCompleja(template, mensajeArg, campoArg){
    esconderElementosHome();
    cerrarContenedorSecciones(true);
    if(arguments[3] && arguments[3] == true){
        loadBlur();
        $("#cboxOverlay").css("background","#000000");
    }
    
    var mensaje = mensajeArg;
    var campo = campoArg;
    
    $("#contentvalidation").html(mensajeArg);
    
    //var url = "templates/contentGeneral.html";
    var url = (arguments[4]) ? arguments[4]+template : "templates/"+template;
    $.colorbox({href:url,top:10, onComplete:function(){

            //alert("ha terminado de cargar la modal");
            $("#contenedormensaje").html($("#contentvalidation").html());
            if(campo != ""){
                $("#"+campo).focus();
            }

            if(arguments[3] && arguments[3] == true){
                $("#cboxOverlay").css("background","#000000");
            }
           /* $.get('templates/test.html', function(data) {
              $('#contentModalFloat').html(data);
            });*/
    }});
}

function llamarModalPreview(template, tituloArg, file, css){
    var StyleModal = {};
    var widthm = 0;
    var heightm = 0;
    var type = "";
    switch (css) {
        case "f":
                widthm = 235;
                heightm = 525 ;
                type = "facebook";

            break;
        case "t":
                widthm = 185;
                heightm = 240;
                type = "twitter";
            break;
    }
    StyleModal = {width:widthm+"px", height: heightm+"px"};
    
    $("#cboxOverlay").css("background","#000000");
    if(arguments[2] && arguments[2] == true){
        loadBlur();
        $("#cboxOverlay").css("background","#000000");
    }
    var titulo = tituloArg;
    $("#contentvalidation").html(titulo);
    
    var url = (arguments[4]) ? arguments[4]+template : "templates/"+template;
    $.colorbox({href:url,top:10, width:widthm+45,height:heightm+80, onComplete:function(){
            $("#contenedormensaje").html($("#contentvalidation").html());
            if(arguments[2] && arguments[2] == true){
                $("#cboxOverlay").css("background","#000000");
            }
            $("#contentimg").html('<img src="files/avatares_feriasyfiestas/'+type+'/'+file+'" border="0" />');
            $("#contentModalFloat").css(StyleModal);
            $("#tituloavatar").html(titulo);

            $('#linkdescarga').click(function() {
                reloadFrame('files/avatares_feriasyfiestas/'+type+'/'+file);
            });
    }});
}

//llamarModalSimple('feriasyfiestas_mosaico.html',1,'templates/',true);

function llamarModalSimple(template){
    var actionBlock = (arguments[3] && arguments[3] == true) ? false : true ;
    if(actionBlock == true){
        esconderElementosHome();
        cerrarContenedorSecciones(true);
    }

    var arg = (arguments.length > 1 && arguments[1] == true) ? 1 : 0;
    loadBlur();
    //var url = "templates/contentGeneral.html";
    var url = (arguments[2] && arguments[2] != "") ? arguments[2]+template : "templates/"+template;
    //alert(url);
    $.colorbox({href:url,top:10, onComplete:function(){
            if(arg == 1){
                $("#cboxOverlay").css("background","#000000");
            }
    }});
}

function cerrarModal(){
    try{
   $.colorbox.close();
   }catch(e){e}
}

function cerrarContenedorSecciones(){
    var redireccionar = (arguments[0] && arguments[0] == true) ? true : false;
    if(redireccionar == false){
        window.location.href = "#";
    }    
    animarContent('marcoGeneralContentSite',400,0,0,function(){ $('#activadorContentSite').html(""); });
}

function getContent(urlArg){

    if(urlArg == "aguilatv"){
       yt.listThumbs("thumbs"); 
    }
    
    try{
        $("#contentSectionExt").remove();
    }catch(e){}
    $("#submenu").css("display","block");

    $('#activadorContentSite').html(imgPreloadStyle);
    var arg = (arguments[1] != undefined) ? arguments[1]  : "" ;
    $.ajax({
        type: "GET",
        data: {},
        url: urlArg,
        success: function(datos){
            //alert(datos);
            //$("#contentModalFloat").html(datos)
            
            if(arg != ""){
                $("#"+arg).html(datos);
            }else{
                //$("#contentSite").html(datos);
                $("#activadorContentSite").html(datos);
            }
            //$.colorbox({html:datos});
            //alert(datos);
        },
        statusCode: {
            404: function() {
              alert('page not found');
            }
        }
    });
}

function getContentHash(urlArg){
     try{
        $("#contentSectionExt").remove();
    }catch(e){}
    $("#submenu").css("display","block");
    window.location.href = "#"+urlArg;
    $('#activadorContentSite').html(imgPreloadStyle);
}

function getContentAux(urlArg){

     try{
        $("#contentSectionExt").remove();
    }catch(e){}

    if(urlArg == "aguilatv"){
       yt.listThumbs("thumbs");
    }
    window.location.href = "#"+urlArg;
    $('#activadorContentSite').html(imgPreloadStyle);
    var arg = (arguments[1] != undefined) ? arguments[1]  : "" ;
    $.ajax({
        type: "GET",
        data: {},
        url: urlArg,
        success: function(datos){
            //alert(datos);
            //$("#contentModalFloat").html(datos)

            if(arg != ""){
                $("#"+arg).html(datos);
            }else{
                //$("#contentSite").html(datos);
                $("#activadorContentSite").html(datos);
            }
            //$.colorbox({html:datos});
            //alert(datos);
        },
        statusCode: {
            404: function() {
              alert('page not found');
            }
        }
    });
}

function move(kiosco){
   //alert("width: "+$("html").css("width"));
   var position = posActionBack(kiosco);
   
   $("#canvas").animate({'background-position' :-(position)+'px bottom'},500,'linear',function(){
       var posBack = $(this).css("background-position");
       var arraytemp = posBack.split('px');
       //alert(arraytemp[0]);
       posBackgroundActual = -(arraytemp[0]);
       //alert(posBackgroundActual);
       animationActionBack();
       
   });
   //$("#canvas").css("bottom","30px");
}

function loadSectionPost(section){
    if(section != ""){

        var argCerrar = (arguments[1] != undefined) ? arguments[1]  : true ;
        if(argCerrar == true){
            cerrarModal();
        }
       //window.location.href = "#"+section;

       if(section.indexOf("?") != -1){
            if(section.indexOf("st=1") == -1){
                window.location.href = window.location.href+"&st=1";
                return false;
                //section = section+"?st=1";
            }
        }else{
            if(section.indexOf("st=1") == -1){
                window.location.href = window.location.href+"?st=1";
                return false;
                //section = section+"&st=1";
            }
        }
        
        $('#contentArticulosPrincipal').html(imgPreloadStyle);
        var arg = (arguments[1] != undefined) ? arguments[1]  : "" ;

        animarContent('marcoGeneralContentSite',600,getHeightSectionAnimate(section),1,function(){
            if(arg != ""){
                getContent(section, arg);
            }else{
                getContent(section);
            }
        });
        
    }
}

function getHeightSectionAnimate(section){
    var sDownload = new RegExp(/musica\/download/gi);
    var sKaraoke = new RegExp(/musica\/karaoke/gi);
    var height = 600;

    $("#contentSite").css("margin","8px 50px 10px 60px");

    if(section.indexOf("musica/download") !=  -1){
        height = 465;
    }else if(section.indexOf("musica/karaoke") !=  -1){
        height = 380;
    }else if(section.indexOf("chicas/streaming") != -1){
        height = 570;
    }else if(section.indexOf("feriasyfiestas/descargas") != -1){
        height = 490;
    }else if(section.indexOf("articulos/list_eventemplate_ff") != -1){
        height = 520;
    }else if(section.indexOf("articulos/list_eventemplate") != -1){
        height = 520;
    }else if(section.indexOf("musica/camisetas") != -1){
        height = 520;
        $("#contentSite").css("margin","8px 10px 10px 10px");
    }else if(section.indexOf("chicas/jhoannadiaz") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("chicas/lauragamboa") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("chicas/carolinalandaeta") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("chicas/melissaporras") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("chicas/realidadaumentada") != -1){
        height = 540;
    }else if(section.indexOf("chicas/galeria") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("chicas/descargas") != -1){
        height = 440;
        $("#contentSite").css("margin","16px 16px 16px 16px");
    }else if(section.indexOf("cantaconelsabordelaalegria") != -1){
        height = 510;
    }else if(section.indexOf("feriasyfiestas/fotomural") != -1){

        var navegador = navigator.userAgent.toLowerCase();
        if( navegador.search(/iphone|ipod|android|ipad/) > -1 ){
            window.location.href = 'http://www.cervezaaguila.com/fotomural/';
        }


        $("#contentSite").css("margin","0 0 0 0");
        height = 580;
    }else if(section.indexOf("musica/playas?") != -1){
        $("#contentSite").css("margin","8px 8px 8px 8px");
        height = 490;
    }else if(section.indexOf("musica/playacartagena") != -1){
        $("#contentSite").css("margin","8px 8px 8px 8px");
        height = 550;
    }else if(section.indexOf("musica/playasantamarta") != -1){
        $("#contentSite").css("margin","8px 8px 8px 8px");
        height = 550;
    }else if(section.indexOf("feriasyfiestas/reydelcarnaval") != -1){
        height = 580;
    }else if(section.indexOf("feriasyfiestas/frasechelitodecastro") != -1){
         $("#contentSite").css("margin","5px 5px 5px 5px");
    }

    return height;
}

function loadSectionHash(section){
    //alert(section);
    try{
        if(section.indexOf("chicas/jhoannadiaz") != -1 || section.indexOf("chicas/lauragamboa") != -1 || section.indexOf("chicas/carolinalandaeta") != -1 || section.indexOf("chicas/melissaporras") != -1){
            ultimoPerfilVisitado = section;
        }
    }catch(e){}

     window.location.href = "#"+section;
    $('#activadorContentSite').html(imgPreloadStyle);

    /*if(section != ""){
        try{
        cerrarModal();
        }catch(e){}
        
        //$('#marcoGeneralContentSite').html('<div style="width: 250px; margin: 0 auto; margin-top: 260px; font:bold 12px verdana;"><img align="absmiddle" src="img/ajax-loader.gif" border="0"/> Cargando contenido...</div>');
        var arg = (arguments[1] != undefined) ? arguments[1]  : "" ;
        
        animarContent('marcoGeneralContentSite',400,600,1,function(){
            if(arg != ""){
                getContent(section, arg);
            }else{
                getContent(section);
            }
        });
    }*/
}
function loadSectionHashTwo(section){
    if(section != ""){
        $('#contentArticulosPrincipal2').html('<div style="width: 250px; margin: 0 auto; margin-top: 260px; font:bold 12px verdana;"><img align="absmiddle" src="img/ajax-loader.gif" border="0"/> Cargando contenido...</div>');
        animarContent('marcoGeneralContentSite2',400,600,1,function(){
                getContentHash(section);
        });
    }
}

function loadSectionFiltroPost(section, capa){
    $('#contentArticulosPrincipal').html('<div style="width: 250px; margin: 0 auto; margin-top: 260px; font:bold 12px verdana;"><img align="absmiddle" src="img/ajax-loader.gif" border="0"/> Cargando contenido...</div>');
    getContent(section, capa);
}

function animarContent(id, vel, argHeight, argOpacity, funcion){
    /*$('#'+id).animate({
        height: ['toggle', 'swing'],
        opacity: 'toggle'
      }, vel, 'linear', funcion());*/

    if(argOpacity != 0){
        $('#'+id).css({display:"block"});
    }

    $('#'+id).animate({
        height: [argHeight, 'swing'],
        opacity: argOpacity
      }, vel, 'linear', function(){
           funcion();
           if(argOpacity == 0){
            $('#'+id).css({display:"none"});
           }
      });

}

function cerrarModalPromo(id, vel, argHeight, argOpacity){

    if(argOpacity == 1){
        $('#'+id).css({"display":"block"});
        $('ul#vallas').innerfade({
            speed: 1000,
            timeout: 10000,
            type: 'sequence',
            containerheight: '115px'
        });

    }

    $('#'+id).animate({
        /*width: ['toggle', 'swing'],*/
        height: [argHeight, 'swing'],
        opacity: argOpacity
      }, vel, 'linear', function(){
          if(argOpacity == 0){
            $('#'+id).css({"display":"none"});
          }
      });
      
}

function setCheckboxDisplay(el){
    var objWrap;
    objWrap = document.getElementById(el.id+"Wrap");
    if(el) {
        if(el.checked) objWrap.className = "styledCheckboxWrap wrapChecked";
        else  objWrap.className = "styledCheckboxWrap";
    }
}

function initTooltipBalon(){
    $('#tooltiphome').animate({
        bottom: [90, 'swing'],
        opacity: 0
      },1, 'linear',function(){
          $('#tooltiphome').css({display:"none"});
      });

    $('#balonhome').mouseover(function() {
        /*var nombre = $(this).attr("name");
        $(this).attr("src", "imagenes/roll/"+nombre+".jpg");*/
        $('#tooltiphome').css({display:"block"});
         $('#tooltiphome').animate({
            bottom: [78, 'swing'],
            opacity: 1
          },350, 'linear',function(){
              
          });

    });
    $('#balonhome').mouseout(function() {
       /* var nombre = $(this).attr("name");
        $(this).attr("src", "imagenes/normal/"+nombre+".jpg");*/

         $('#tooltiphome').animate({
            bottom: [90, 'swing'],
            opacity: 0
          },350, 'linear',function(){
              $('#tooltiphome').css({display:"none"});
          });

    });
}

function initMenuLi(){

   $('#submenudescargas').animate({
        height: [0, 'swing'],
        opacity: 0
      },1, 'linear',function(){
        $("#submenudescargas").hide();
     });

     $("#menudescargas, #submenudescargas").mouseover(function(){

         $("#submenudescargas").show();
         $('#submenudescargas').animate({
            height: [30, 'swing'],
            opacity: 1
          },100, 'linear',function(){
         });
     });

     $("#menudescargas").click(function(){
         $("#submenudescargas").show();
         $('#submenudescargas').animate({
            height: [30, 'swing'],
            opacity: 1
          },100, 'linear',function(){
         });
     });

     $("#menudescargas, #submenudescargas").mouseout(function(){

         $.timer(4000, function(timer) {
            timer.stop();
            $('#submenudescargas').animate({
                height: [0, 'swing'],
                opacity: 0
              },100, 'linear',function(){
                $("#submenudescargas").hide();
             });

            
            });
     })
}

function cerrarLogin(){
 $('#actionlogin').animate({
        top: [30, 'swing'],
        opacity: 0
      },350, 'linear',function(){
          $("#actionlogin").hide();
     });
    return false;
}

function cerrarRegistro(){
    $('#actionregistro').animate({
        top: [30, 'swing'],
        opacity: 0
      },350, 'linear',function(){
          $("#actionregistro").hide();
     });
    return false;
}

function validarEdad(){

  $("#submitButton").css({"display":"none"});
  $("#submitPrecarga").css({"display":"block"});

  var dia = $("#dia").val();
  var mes = $("#mes").val();
  var anno = $("#anyo").val();

  var urlActualSite = $.cookie("urlcurrentsite");

    var numPreForma = (anno >= "00" && anno <= "19") ? "20" : "19";

  var variables = {
        'data[User][year]' : numPreForma+""+anno,
        'data[User][month]' : mes,
        'data[User][day]' : dia
    }

    $.ajax({
        type: "POST",
        data: variables,
        url: "users/validate_age",
        success: function(datos){
 
            datos = datos.replace(new RegExp('\\n','g'),'');
            if(datos == "mensaje=1"){
                if(!$.cookie("validadoredad")){
                    //alert("se ha creado la cookie");
                    var date = new Date();
                    date.setTime(date.getTime() + (30 * 60 * 1000));
                    //date.setTime(date.getTime() + (10*1000));
                    $.cookie("validadoredad", "ok",{expires:1});

                }else{
                    //alert("la cookie ya está creada");
                }

                //alert($.cookie("urlcurrentsite"));
                //window.location.href = "./"+urlHashActual;
                GET = get();
                //alert(GET["return"]);
                var tempLocation = window.location.href.split("?return=");
                //alert(tempLocation[1]);
                window.location.href = tempLocation[1];

            }else if(datos == "mensaje=0"){
                $("#submitButton").css({"display":"block"});
                $("#submitPrecarga").css({"display":"none"});

                llamarModalCompleja('validacion.html',"Debes ser mayor de edad para ingresar al sitio.","anyo",true);
                //alert("Debes ser mayor de edad para ingresar al sitio");
            }else if(datos == "mensaje=2"){
                $("#submitButton").css({"display":"block"});
                $("#submitPrecarga").css({"display":"none"});

                //alert("Digite uan fecha válida");
                llamarModalCompleja('validacion.html',"Digita una fecha válida.","anyo", true);
            }else{
                //alert("nada");
            }

            

            //$("#contentModalFloat").html(datos)

            /*if(arg != ""){
                $("#"+arg).html(datos);
            }else{
                $("#contentSite").html(datos);
            }*/
            //$.colorbox({html:datos});
            //alert(datos);
        },
        statusCode: {
            404: function() {
              alert('page not found');
            }
        }
    });

}


function cerrarRecordarContrasena(){
    $("#loginRecordar").css({"display":"none"});
    $("#loginValidacion").css({"display":"block"});
}

function abrirRecordarContrasena(){
    $("#loginRecordar").css({"display":"block"});
    $("#loginValidacion").css({"display":"none"});
}


/* funciones generales*/
function validar_email(valor){
        // creamos nuestra regla con expresiones regulares.
        var filter = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
        // utilizamos test para comprobar si el parametro valor cumple la regla
        if(filter.test(valor))
           return true;
        else
           return false;
}

function redireccionar(url){
    window.location.href = url;
}

function reloadFrame(url){
   
    var frame = document.getElementById("framedownload");
    frame.src = "download.php?f="+url;
}

function modalShareFacebook(url){
    var popup;
    try{
        if(!(popup = window.open (url, "sharedfacebook","location=0,status=0,scrollbars=0,width=650,height=300"))){
            throw "ErrPop"
        }
    }catch(err){
        if(err=="ErrPop"){
            msj = "¡El bloqueo de popups esta activo!, desabilite esta opcion de su navegador y vuelva a ejecutar la acción."
            alert(msj)
        }else{
            msj="Hubo un erro en la página.nn"
            msj+="Descripción del error: " + err.description + "nn"
            alert(msj)
        }
    }
    return;
}

function modalShareFacebookShort(urlArg, title){
    var popup;
    
    var url = 'http://www.facebook.com/sharer.php?u='+encodeURIComponent(urlArg)+'&t='+title;

    try{
        if(!(popup = window.open (url, "sharedfacebook","location=0,status=0,scrollbars=0,width=700,height=500"))){
            throw "ErrPop"
        }
    }catch(err){
        if(err=="ErrPop"){
            msj = "¡El bloqueo de popups esta activo!, desabilite esta opcion de su navegador y vuelva a ejecutar la acción."
            alert(msj)
        }else{
            msj="Hubo un erro en la página.nn"
            msj+="Descripción del error: " + err.description + "nn"
            alert(msj)
        }
    }
    return;
}

function modalShareTwitterShort(msg){

    var urlMsg = msg;
    var url = 'http://twitter.com/intent/tweet?status='+encodeURIComponent(urlMsg);

    var popup;
    try{
        if(!(popup =window.open (url, "sharedtwitter","location=0,status=0,scrollbars=0,width=700,height=500"))){
            throw "ErrPop"
        }
    }catch(err){
        if(err=="ErrPop"){
            msj = "¡El bloqueo de popups esta activo!, desabilite esta opcion de su navegador y vuelva a ejecutar la acción."
            alert(msj)
        }else{
            msj="Hubo un erro en la página.nn"
            msj+="Descripción del error: " + err.description + "nn"
            alert(msj)
        }
    }
    return;
}


function initScrollto(){
    $.easing.elasout = function(x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
        if (a < Math.abs(c)) {a=c;var s=p/4;}
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    };

    //resets the page
    /*$('div.wrapper').scrollTo( 0 );
    $.scrollTo( 0 );*/
    //irScrollTo('first');

    // click function
    $('#btn_one').click(function(){
            $('.nav').fadeOut("slow").fadeIn("slow");
            $.scrollTo(this.hash, 1500, {easing:'swing'});
    });

    $('#btn_two').click(function(){
            $('.nav').fadeOut("slow").fadeIn("slow");
            $.scrollTo(this.hash, 1500, {easing:'swing'});
    });

    $('#btn_three').click(function(){
            $('.nav').fadeOut("slow").fadeIn("slow");
            $.scrollTo(this.hash, 1500, {easing:'swing'});
            //$.scrollTo(this.hash, 1500, { easing:'elasout' });
    });
}

function irScrollTo(capa){
    //$.scrollTo("#"+capa, 1500, { easing:'swing' });
    $.scrollTo("#"+capa, 1500, {easing:'swing'});
    //$("#contenedorWrapper").scrollTo("#"+capa, 1500, { easing:'swing' });
}

function initCarruselVallas(){
    $('ul#vallas').innerfade({
        speed: 1000,
        timeout: 10000,
        type: 'sequence',
        containerheight: '115px'
    });
}

function initCloseContentgeneral(){
    $(document).keyup(function(event) {
        if (event.keyCode == '27') {
            animarContent('marcoGeneralContentSite',400,0,0,function(){})
        }
    });
}

function initSite(){
    var pathname = window.location.href
    initmenuLateral();

    //alert(pathname);

    var date = new Date();
    date =  date.setTime(date.getTime() + (30 * 60 * 1000));
    $.cookie("urlcurrentsite", pathname,{expires:date});
    //alert("inicial: "+$.cookie("urlcurrentsite"));
    
    if(arguments[0]){

    }

    $.cookie("urlactual", "ok",{expires:date});

    var t = window.location.hash;
    var g = "?return="+encodeURI(pathname);
    if(!$.cookie("validadoredad")){
        window.location.href =  "validadoredad"+g;
    }
    if(t == ""){
        animarContent('marcoGeneralContentSite',2, 0,0, function(){});
    }
    try{
    heightInitMenuLateral = $('#submenulateral').css('height').split("px");
    }catch(e){}

}

/*--------- Funciones History ---------*/

function historyInit(){

    jQuery.history.init(function(url) {
            //alert(url);

            if(url.indexOf("|") != -1){
                var arrayUrl = url.split('|');
                //alert(arrayUrl[0]+" , "+arrayUrl[1]);
                
                if(arrayUrl[0].indexOf("alertc@") != -1){
                    var temp = arrayUrl[0].split("@");
                    llamarModalSimple(temp[1],true,'',true);
                    loadSectionPost(arrayUrl[1], false);

                }

                if(arrayUrl[1].indexOf("alertc@") != -1){
                    var temp = arrayUrl[1].split("@");
                    llamarModalSimple(temp[1],true,'',true)
                    loadSectionPost(arrayUrl[0], false);

                }

            }else{
                var temp;
                if(url.indexOf("alertc@") != -1){
                    temp = url.split("@");
                    llamarModalSimple(temp[1])
                }if(url.indexOf("secext@") != -1){
                    temp = url.split("@");
                    $("#submenu").css("display","none");
                    animarContent('marcoGeneralContentSite',10,0,0,function(){});
                    loadSectionExtend(temp[1]);
                }else{
                    loadSectionPost(url);
                }
            }
           //loadTemplate(url == "" ? "index" : url);
    });
    
}

function loadSectionExtend(urlArg){
    try{
        $("#contentSectionExt").remove();
    }catch(e){}
    $("#contenedorcentral").prepend('<div id="contentSectionExt" class="contentSectionExt"><div>');
    getContentExtend(urlArg);
}

function getContentExtend(urlArg){
    $('#activadorContentSite').html(imgPreloadStyle);
    $.ajax({
        type: "GET",
        data: {},
        url: urlArg,
        success: function(datos){
                $("#contentSectionExt").html(datos);
        },
        statusCode: {
            404: function() {
              alert('page not found');
            }
        }
    });
}

function next(){
	jQuery.history.next();
}

function prev(){
	jQuery.history.prev();
}

function navegar(hash){
	window.location = hash;
}

function toogleSubmenuLateral(){
    try{
  
    var verificaHeight = $('#submenulateral').css('height').split("px");
    var valorHeight = (verificaHeight[0] < heightInitMenuLateral[0]) ? heightInitMenuLateral[0]  : 0 ;
    var valorOpacity = (verificaHeight[0] < heightInitMenuLateral[0]) ? 1 : 0 ;

        if($('#submenulateral').css("display") == "none"){
            //alert("abrir");
            $("#link_submenulateral").css({"background-position":"0 bottom"});
            $('#submenulateral').show();
            $.cookie("aguilaMenuLateral", "show");
        }else{
            //alert("cerrar");
            $("#link_submenulateral").css({"background-position":"0 top"});
            $('#submenulateral').hide();
            $.cookie("aguilaMenuLateral", "hide");
        }
    }catch(e){}

    /*$('#submenulateral').animate({
        height: [valorHeight, 'swing'],
        opacity: valorOpacity
      },350, 'linear'
    );*/
}

function initmenuLateral(){

    //alert($.cookie("aguilaMenuLateral"));

    if($.cookie("aguilaMenuLateral")){

        if($.cookie("aguilaMenuLateral") == "hide"){
            $("#link_submenulateral").css({"background-position":"0 top"});
            $('#submenulateral').hide();
           
        }else if($.cookie("aguilaMenuLateral") == "show"){

            $("#link_submenulateral").css({"background-position":"0 bottom"});
           $('#submenulateral').show();

        }

    }else{
        $("#link_submenulateral").css({"background-position":"0 bottom"});
        $('#submenulateral').show();
    }
}
