﻿$(document).ready(function() {
    $("#navizq").css("opacity", "0");
    $("#navder").css("opacity", "0");
    $("#sliderexitos .contenedor-casoimagen img").each(function(){ $(this).css({marginTop: "-" + $(this).height()/2 + "px", marginLeft: "-" + $(this).width()/2 + "px"}); });

    var slider = $("#sliderexitos");

    var li_core = $(slider).find("li").get(0);

    var li_ancho = $(li_core).width();
    var cantidadElementos = $(slider).find("li");
    
    $(slider).find("li").each(function(i){ $(this).css("left",i*li_ancho+"px") });

    $("#navizq").bind("load", function(event) { event.preventDefault(); });

    var primerExito = true;
    $("#sliderexitos li").hover(function() {
        if (primerExito) $("#navizq,#navder").animate({ opacity: 0.4 }, 300);
    }, function() {
        if (primerExito) {$("#navizq,#navder").animate({ opacity: 0 }, 200); primerExito = false;}
    })
    
    $("#navizq,#navder").hover(function() {
        $(this).animate({ opacity: 0.4 }, 300);
    }, function() {
        $(this).animate({ opacity: 0 }, 200);
    })

    $("#navder").click(function() {
        if ($(slider).css("left") == (-1 * (cantidadElementos.length * li_ancho - li_ancho) + "px")) {
            $(slider).animate({ left: "0px" }, 750);
        }
        else
            $(slider).animate({ left: "-=" + li_ancho + "px" }, 550);
    });

    $("#navizq").click(function() {
        if ($(slider).css("left") == "0px")
            $(slider).animate({ left: (-1 * (cantidadElementos.length * li_ancho - li_ancho) + "px") }, 750);
        else
            $(slider).animate({ left: "+=" + li_ancho + "px" }, 550);
    });
});