﻿$(document).ready(function () {

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Carrusel software
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    $('#carruselgenerico')
	        .cycle({
	            fx: "scrollHorz",
	            speed: 'slow',
	            timeout: 5000,
	            next: '#arrowright2',
	            prev: '#arrowleft2',
	            pause: 1
	        });


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//Carrusel de banners de cabecera
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $('#contbanners')
	.cycle({
	    fx: "scrollHorz",
	    speed: 'slow',
	    timeout: 10000,
	    pager: '#bannernavegador',
	    next: '#arrowright',
	    prev: '#arrowleft',
	    pause: 1
	});



    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //divs icos
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $("li.ico").mouseover(function () {
        $("div#div" + this.id).show();
    })

    $("li.ico").mouseout(function () {
        $("div#div" + this.id).hide();
    })


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Efectos del menu de secciones
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $("div#menusecciones ul li").mouseover(function () {
        $(this).find("a").css({ color: "#000" });
        $(this).animate({ height: '32px' }, { queue: false, duration: 250 });
        $(this).find(":first").animate({ height: '32px' }, { queue: false, duration: 250 });
        $("div#sub" + this.id).css({ display: "block" });
    })

    $("div#menusecciones ul li").mouseout(function () {
        var idbody = $('body').attr('id');
        var idboton = $(this).attr('id');

        idbody = idbody.replace(/body_/, "");
        idboton = idboton.replace(/btn_/, "");

        if (idbody != idboton) {
            $(this).animate({ height: '64px' }, { queue: false, duration: 250 })
            $(this).find(":first").animate({ height: '64px' }, { queue: false, duration: 250 });
            $(this).find("a").css({ color: "#fff" });
        }
        $("div#sub" + this.id).css({ display: "none" });


    })


    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //carrusel noticias Portada
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    $('#carruselnoticias')
	        .cycle({
	            fx: "scrollUp",
	            speed: 'slow',
	            timeout: 3000,
	            pause: 1
	        });

    $("div.carruselnoticia").mouseover(function () {
        $(this).animate({ height: '140px' }, { queue: false, duration: 250 });
        $("#carruselnoticias").animate({ height: '140px' }, { queue: false, duration: 250 });
    })

    $("div.carruselnoticia").mouseout(function () {
        $("#carruselnoticias").animate({ height: '26px' }, { queue: false, duration: 250 });
        $("div.carruselnoticia").animate({ height: '26px' }, { queue: false, duration: 250 });
    })




    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //carrusel pie de página de portada
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    $("div.btnlineasempresa").mouseover(function () {
        $("div.btnlineasempresa").removeClass('selected');
        $(this).addClass('selected');
        $("div.infolineasempresa").hide();
        $("div#info" + this.id).show();
    })

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Efectos de trayectoria
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $(".aniotrayectoria li").mouseover(function () {
        $(".aniotrayectoria li").animate({ height: '20px', width: '100px' }, { queue: false, duration: 500 });
        $(".aniotrayectoria li a").css({ color: '#0C5896' });
        MM_altura = $(this).attr('height');
        $(this).animate({ height: MM_altura, width: '640px' }, { queue: false, duration: 500 });
        $(this).find("a").css({ color: '#ededed' });
    })


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Efectos del menu de perfil de usuario
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $("div#pestanausuario ul li").mouseover(function () {
        $(this).animate({ height: '26px' }, { queue: false, duration: 250 });
        $(this).find(":first").animate({ height: '26px' }, { queue: false, duration: 250 });
    })

    $("div#pestanausuario ul li").mouseout(function () {
        var clase = $(this).attr('class');
        if (clase != 'selected') {
            $(this).animate({ height: '52px' }, { queue: false, duration: 250 })
            $(this).find(":first").animate({ height: '52px' }, { queue: false, duration: 250 });
        }
    })

});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CArrusel del portfolio
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function CarruselPortfolio() {

    // FOTOS ARRIBA
    //Botones thumbs superior
    $('.PortFolioDetalle').each(function () {
        var scroller = $(this).find(".ScrollerPortFolioDetalleInterior")
        $(this).find('.thumbCarruselSup').click(function () {
            var numThumb = $(this).attr("id").split("_")[1]                       
            scroller.stop().scrollTo(scroller.find('.fotoSup_' + numThumb), 1200);   
            return false;
        });
    });


    // THUMBS ABAJO          
    
    //Pag actual
    var PagThumb = 1;
    //Total de paginas
    var numThumPag = $("[id^= 'cont_thumb']").size()
    var ThumbActiva = $(".thumbCarrusel:first")
    var OpacityThumbs = 0.6

    ThumbActiva.addClass("Thumbselected")

    $("#btThumbsPrev").click(function () {
        CambiaPagThumbs(PagThumb - 1)       
        return false;
    });

    $("#btThumbsNext").click(function () {
        CambiaPagThumbs(PagThumb + 1)       
        return false;
    });

    CompruebaNavegacionThumbs()

    function CambiaPagThumbs(pag) {
        //Comprobamos si estamos dentro de los limites para desplazarnos        
        if (pag >= 1 && pag <= numThumPag) {           
            $('#ContThumbs').stop().scrollTo($('#cont_thumb_' + pag), 1200);
            PagThumb = pag
            CompruebaNavegacionThumbs()
        }

    }

    //Cambia la opacidad de los botones dependiendo de la página e la que estamos.
    function CompruebaNavegacionThumbs() {
        if (PagThumb == 1) {
            $("#btThumbsPrev").animate({ opacity: 0.25 })
        } else {
            $("#btThumbsPrev").animate({ opacity: 1 })
        }

        if (PagThumb == numThumPag) {
            $("#btThumbsNext").animate({ opacity: 0.25 })
        } else {
            $("#btThumbsNext").animate({ opacity: 1 })
        }
    }

    //Botones thumbs

    $('.thumbCarrusel').click(function () {
        ThumbActiva.removeClass("Thumbselected")
        ThumbActiva = $(this)
        ThumbActiva.addClass("Thumbselected")
        var numThumb = $(this).attr("id").split("_")[1]
        $('#ScrollerPortFolioDetalle').stop().scrollTo($('#foto_' + numThumb), 1200);
        return false;
    });

}



