

function miMenu() {
    $('ul#menu li a').hover(function () {

        /*Efectos disponibles:

        blind
        bounce
        clip
        drop
        explode
        fold
        highlight
        puff
        pulsate
        scale
        shake
        size
        slide
        transfer
                
        */
        //$(this).stop(true, true).effect("highlight", { color: '#93B28D' }, 'fast');
    });

    $('.childs-indicator').hover(function () {

        $('ul', this).first().stop(true, true).slideDown('fast');


    }, function () {

        $('ul', this).first().stop(true, true).slideUp('fast');

    });
}

function current() {
    $("#nav a").each(function () {
        if (this.href == window.location) {
            $(this).addClass("current");
            //Break;
        }
    });
}

$(document).ready(function () {

    miMenu();
    current();

    //Interceptar clic en los botones de navegacion
    $(".nav .nav-atr").click(function (event) {
        event.preventDefault();
        load_portfolio(-1);
    });

    $(".nav .nav-del").click(function (event) {
        event.preventDefault();
        load_portfolio(1);
    });



});

var portIndex = 1;

function load_portfolio(step) {
    if (step != 0) {
        var totalElements = $("#portafolio_items a").length;
        portIndex += step;
        if (portIndex > totalElements) {
            portIndex = 1;
        } else if (portIndex < 1) {
            portIndex = totalElements;
        }
    }
    window.location.hash = $('#portafolio_items a[rel="' + portIndex + '"]').attr("href");
}

//Evento cada vez que cambie el Hash tag
$(window).bind('hashchange', function () {
    onHashChange();
});

//Cuando cambia el hash
function onHashChange() {
    //Verificamos que el cambio sea por portafolio
    var port = window.location.hash;
    port = port.substring(1);
    var selected = $('#portafolio_items a[href="' + port + '"]');
    //Si el cambio fue por portafolio, procedemos a cargar
    if (selected.length > 0) {
        portIndex = selected.attr("rel") * 1;
        var loader = $("#portafolio_loader");
        if (loader.html() == "") {
            loadAndAnimate(port);
        } else {
            $("#portafolio_loader .portafolio").animate({ "left": "-920px" }, 400, "linear", function () {
                loadAndAnimate(port);
            });
        }
    }
}

//Asocia el evento clic a la galeria de imagenes
function asociateGalleryEvents() {
    var imageLinks = $(".portafolio .portafolio_left .gallery .thumbs a");
    imageLinks.click(function (event) {
        event.preventDefault();
        var selected = $(this);
        updateGalleryImage(selected);
    });
}

//Cambia la imagen grande de la galeria
function updateGalleryImage(selected) {
    if (selected.length > 0) {
        var newSrc = selected.children("img").attr("src");
        var imgDisplayWrapper = $(".portafolio .portafolio_left .gallery .imgall");
        imgDisplayWrapper.animate({ "top": "-405px" }, 200, "linear", function () {
            imgDisplayWrapper.children("img").attr("src", newSrc);
            imgDisplayWrapper.animate({ "top": "0px" }, 200, "linear");
        });
    }
}
