$(document).ready(function(){

    $('.products-list, .products-liste').mouseleave(function(){
        $('#products-list').removeClass('active');
        $('.products-list').hide();
    })
    $('.products-list').mouseover(function(){
        $('#products-list').addClass('active')
        $('.products-list').show();
    })
    $('#products-list').mouseover(function(){
        $(this).toggleClass('active');
        if($(this).hasClass('active')){
            $('.products-list').css({
                'opacity': 0
            }).show();
            width = $(this).width();
            right = $(this).offset().left
            widthpro = $('.products-list').width();
            rightlist = $('#products-list').offset().left;
            $('.products-list').offset({
                left: (rightlist)
            }).css({
                'opacity': 1
            })
        } else {
            $('.products-list').hide();
        }
    })

    $('#products-list cufon, #products-list cufon canvas').mouseover(function(){
        $('#products-list').toggleClass('active');
        if($('#products-list').hasClass('active')){
            $('.products-list').css({
                'opacity': 0
            }).show();
            width = $('#products-list').width();
            right = $('#products-list').offset().left
            widthpro = $('.products-list').width();
            $('.products-list').offset({
                left: ((right+ (width / 5)) - (widthpro / 5))
            }).css({
                'opacity': 1
            })
        } else {
            $('.products-list').hide();
        }
    })

    $('.carte').click(function(){
        $(this).toggleClass('active');
        if($(this).hasClass('active')){
            $('.small_cart').show();
        } else {
            $('.small_cart').hide();
        }
    })

    if($('.small_cart .shopping_cart .products').length > 0){
        var element = $(".small_cart .shopping_cart .products").jScrollPane({
            animateScroll: true,
            autoReinitialise: true
        });

        var apiJsP = element.data('jsp');
    }

    $('.small_cart .shopping_cart .remove').live('click', function(){
        var theid, msg;
        theid = $(this).parent('li').attr('rel');
        $('#notific, #notific .load').show();
        $.ajax({
            type: "GET",
            cache: false,
            url: "/cart/ajax/produto/remove/"+theid+"/",
            success: function(msg){
                $('#notific .content').html(msg);
                $('#notific .load').hide();
                $('#notific .content').show();
            }
        });
    })

    $('.small_cart .cart-links .empty').live('click', function(){
        var msg;
        $('#notific, #notific .load').show();
        $.ajax({
            type: "GET",
            cache: false,
            url: "/cart/ajax/produto/empty/",
            success: function(msg){
                $('#notific .content').html(msg);
                $('#notific .load').hide();
                $('#notific .content').show();
            }
        });
    })

    $('#notific .continue').live('click', function() {
        $('#notific, #notific .content').fadeOut();
    })

    $('.bar, #footer').width($(window).width());

    $(window).resize(function() {
        $('.bar, #footer').width($(window).width());
    })

    $('#wishlist').hover(function(){
        position  = $(this).position();
        left = position.left;
        newleft = left + 230;
        $('.addbutton').append('<div class="hover"><p>Em breve</p></div>');
        $('.hover').css({
            top: 28,
            left: newleft
        })
    }, function() {
        $('.hover').remove();
    })

  

})
