$(document).ready(function(){
    //desborde de menu
    var menu = $("#menu-header_menu");
    var max_width = $("#menu-header_menu").width();
    var first_level_item = "", rest = "";
    var new_width = 0;
    var total_width = 0;
    
    function mouseOver()
    {
        total_width = 0;
        new_width = $(this).children("ul").children("li").each(function(){
            total_width += $(this).width();
            });
        first_level_item = $(this).children("ul.sub-menu");
        first_level_item.css("width", total_width);
        rest = first_level_item.width() - $(this).width() - 10;
        if(first_level_item.width() > (max_width/2))
        {
            first_level_item.css("left", rest*-1);
        }
    }
    function mouseOut()
    {
        total_width = 0;
    }
    
    // when bind
    //menu.children("li.menu-item").bind('mouseover', mouseOver).bind('mouseout', mouseOut);
    
    // then to unbind
    menu.children("li.menu-item").click(function(e) {
    //e.preventDefault();
    //menu.children("li.menu-item").unbind("mouseover", mouseOver).unbind("ouseout", mouseOut);
    });
    
    $(".sub-menu li a").hover(function(){
        if($(this).parents(".sub-menu").length==1){
            $(".sub-menu li a").removeClass("active");
            $(this).addClass("active");
        }
    }, function(){
        
    });
    
    //Mujeres
    $("#next_product").bind("click",function(){
        $("#next_product").unbind("click");
        //alert("next_product");
        prevProduct();
    });
    $("#prev_product").bind("click",function(){
        $("#prev_product").unbind("click");
        //alert("prev_product");
        nextProduct();
    });
    
    $("#product_slider").attr("len",$("#product_slider").children("li").length);
    
    function prevProduct()
    {
        if($("#product_slider").attr("len")>1)
        {
            var wid= $("#product_slider").children("li:visible").width();
            var p = $("#product_slider").position();
            $("#product_slider").stop().animate({"left":p.left-wid-0},1000,"linear",function(){
                $("#product_slider").attr("len",$("#product_slider").attr("len")-1);
                if($("#product_slider").attr("len")==3)
                {
                    $("#next_product").hide();
                }
                else
                {
                    $("#next_product").show();
                    $("#prev_product").show();
                }
                $("#next_product").bind("click",function(){
                    $("#next_product").unbind("click");
                    prevProduct();
                });
            });
        }
    }
    
    function nextProduct()
    {
        if($("#product_slider").attr("len")<$("#product_slider").children("li").length)
        {
            var wid= $("#product_slider").children("li:visible").width();
            var p = $("#product_slider").position();
            $("ul#product_slider").stop().animate({"left":p.left+wid+0},1000,"linear",function(){
                $("#product_slider").attr("len",$("#product_slider").attr("len")*1+1);
                if($("#product_slider").attr("len")==$("#product_slider").children("li").length)
                {
                    $("#prev_product").hide();
                }
                else
                {
                    $("#prev_product").show();
                    $("#next_product").show();
                }
                $("#prev_product").bind("click",function(){
                    $("#prev_product").unbind("click");
                    nextProduct();
                });
            });
        }
    }
    
});
