var arr_img_gal = new Array();
var arr_img = new Array();
var tamanio = 0;
var contador = 0;
var id_intervalo = 0;

$(document).ready(function()
{
    $('#gallery-1 a').lightBox();
    $('#gallery-2 a').lightBox();
    $('#gallery-3 a').lightBox();
    $('#gallery-4 a').lightBox();

    $('.closeOnMouseOver').live('mouseover',arrancarTimer);

    $( "#tabs" ).tabs();

    /************ Menú Desplegable / Menu HOrizontal *********/
    $("#menu_horizontal>div").mouseover(function(event){
        $("#menu_horizontal>div>ul").hide();
        var a =$(this).offset();
        $(this).find("ul").stop().toggle().css("left",a.left);
    });

    $("#menu_horizontal>div").mouseout(function(event){
        event.stopPropagation();
        $(this).find("ul").hide();
    });
    $("#menu_horizontal>div>ul").mouseout(function(event){
        event.stopPropagation();
        $(this).hide();
    });


    /***************  Acordeón Página Ingreso *************************/
    $(".FormularioOculto").bind("click", function(event){
        event.stopPropagation();
    });

    $(".ContenedorIngreso").bind("click", function(){
        if($(this).find(".FormularioOculto").css("display")=="none"){
            $(".FormularioOculto").slideUp("slow");
            $(this).find(".FormularioOculto").slideDown("slow");
        } else{
            $(this).find(".FormularioOculto").slideUp("slow");
        }
    });


    /********************Acordeón Eventos*****************************/
    $(".dia").bind("click", function(){
        if($(this).children().css("display")=="none"){
            $(".programa").hide();
            $(this).children().slideDown("slow");
        } else{
            $(this).children().slideUp();
        }
    });

    /**************** Animación PseudoAcordeón Directiva ********************/
    $(".boton").bind("click", function(){
        $(".directivo").hide();
        $(this).parent().parent().show();
        $(".DatosDirectiva").slideUp();
        $(".boton2").fadeOut();
        $(".boton").fadeIn();
        $(this).parent().parent().find("img").fadeIn("fast");
        $(this).parent().find(".boton2").fadeIn();
        $(this).hide();
        $(this).parent().find(".DatosDirectiva").slideDown();
    });

    $(".boton2").bind("click",function(){
        $(".directivo").show();
        $(this).hide();
        $(this).parent().find(".boton").fadeIn();
        $(this).parent().parent().find("img").fadeOut("fast");
        $(this).parent().find(".DatosDirectiva").slideUp();
        $("#ColumnaCentral-1.ContenidoQuienes*div").show();
    });



    /**************** Animación Galeria ********************/
    $(".album").bind("click", function(){
        if($(this).find(".album-1").css("display")=="none"){
            $(".album").hide();
            $(this).show();
            $(this).find(".album-1").slideDown("fast");
            $(this).attr("title","Haga click para ver los demás álbumes");
        }else{
            $(".album").slideDown();
            $(this).find(".album-1").slideUp("slow");
            $(this).attr("title","Haga click para ver las fotos");
        }
    });


    /********* Acordeón de Directivas Secciones de Especialidad********************/
    $(".secciones").bind("click",function(){
        $(".DatosSecciones").slideUp();
        $(this).find(".DatosSecciones").slideDown();
    });


    /************************ Acordeones en Publicaciones **********************/
    $(".li-publicacion").bind("click", function(){
        $(".toggle").slideUp();
        $(this).find(".toggle").slideDown();
    });

    $(".meses").bind("click", function(event){
        $(".meses>.toggle2").slideUp();
        $(this).children().slideDown();
        event.stopPropagation();
    });
    $(".toggle2").bind("click", function(event){
        event.stopPropagation();
    });

    $(".toggle>li>a").bind("click", function(event){
        event.stopPropagation();
    });


    /*****************  Cartelera Informativa ****************************/
    $("#slider").anythingSlider({
        pauseOnHover: false,
        theme:'cs-portfolio',
        themeDirectory: BASE_URL + '/js/anythingslider/css/theme-{themeName}.css',
        delay:7000
    });



    /*****************  Curvy Corners ****************************/
    var opciones = {
        tl: {
            radius: 8
        },
        tr: {
            radius: 8
        },
        bl: {
            radius: 8
        },
        br: {
            radius: 8
        },
        antiAlias: true
    }

    var opciones2 = {
        tl: {
            radius: 5
        },
        tr: {
            radius: 5
        },
        bl: {
            radius: 0
        },
        br: {
            radius: 0
        },
        antiAlias: true
    }

    var opciones3 = {
        tl: {
            radius: 0
        },
        tr: {
            radius: 0
        },
        bl: {
            radius: 5
        },
        br: {
            radius: 5
        },
        antiAlias: true
    }

    $(".curvy").corner(opciones);
    $(".curvy_top").corner(opciones2);
    $(".curvy_bottom").corner(opciones3);


    /***** Inicio Noticias Columna Izquierda *******/
    noticia1();



    /***** Inicio Mini Galeria Columna Derecha *******/
    $("#GaleriaColDer>img").each(function(index){
        arr_img_gal[index-1]=$(this);
    });
    startMiniGallery(arr_img_gal);

});

function startMiniGallery(arr){
    tamanio = arr.length;
    galeria();
}

var contAlbum =0;
function MostrarAlbum(){
    $(arr_img[contAlbum]).show(500).delay(0,function(){
        contAlbum++;
        if(contAlbum<arr_img.length)
            MostrarAlbum();
        else{
            alert(contAlbum);
            contAlbum=0;
        }
    });

}

function galeria(){
    var imagen = arr_img_gal[contador];

    $(imagen).fadeIn(1000).delay(3000).fadeOut(1000,galeria);

    contador++;

    if(contador>=tamanio)
        contador=0;
}

function noticia1(){
    $('#noticia1').fadeIn(1000).delay(2500).fadeOut(500,noticia2);
}

function noticia2(){
    $('#noticia2').fadeIn(1000).delay(2500).fadeOut(500,noticia3);
}

function noticia3(){
    $('#noticia3').fadeIn(1000).delay(2500).fadeOut(500,noticia4);
}

function noticia4(){
    $('#noticia4').fadeIn(1000).delay(2500).fadeOut(500,noticia5);
}

function noticia5(){
    $('#noticia5').fadeIn(1000).delay(2500).fadeOut(500,noticia1);
}

function galeria1(){
    $('#img1').fadeIn(1000).delay(2500).fadeOut(galeria2);
}

function galeria2(){
    $('#img2').fadeIn(1000).delay(2500).fadeOut(galeria3);
}

function galeria3(){
    $('#img3').fadeIn(1000).delay(2500).fadeOut(galeria1);
}

function filtrarCaracteres(ob){
    var texto = $(ob).val();
    texto = texto.replace(/\W/,'');
    $(ob).val(texto);
}

/**
 * funcion que desaparece un elemneto de la pagina al pasarle el mouse
 * por encima :-)   ( manuel )
 */
function closeOnMouseOver(objeto){
    $(objeto).hide('blind',1000);
    clearInterval(id_intervalo);
    id_intervalo = 0;
}
/**
 * funcion que arranca un timer pa llamar a la funcion closeOnMouseOver dentro de
 * un tiempo establecido
 */
function arrancarTimer(){
    if ( id_intervalo == 0 ){
        var objeto = this;
        id_intervalo = setInterval(function(){
            closeOnMouseOver(objeto)
        },3000);
    }
}
