$(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();
            $('.products-list').offset({
                left: ((right+ (width / 2)) - (widthpro / 2))
            }).css({
                'opacity': 1
            })
        } else {
            $('.products-list').hide();
        }
    })

    $('#products-list cufon').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 / 2)) - (widthpro / 2))
            }).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(){
        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(){
        $('#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();
    })

    $('.product_image .others a').live('click', function() {

        $('.product_image .image').height($('.product_image .image img').height());
        $('.product_image .image img').remove();

        attr = $(this).attr('rel');
        image = $('<img />');
        image.attr('src', attr).css({
            'opacity' : 0.3
        });

        $('.product_image .image').append(image).css({
            'height' : 'auto'
        }).find('img').animate({
            'opacity' : 1
        })

        return false;
    })

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

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

  

})
