jq(document).ready(function() {

    jq('.product-quick-view a.colorSwatch').live('click', function(e) {
        e.preventDefault();
        jq('#main-image img').attr('src', jq(this).attr('rev'));
    });

    jq('.altview').live('click', function(e) {
        e.preventDefault();
        jq('#main-image img').attr('src', jq(this).attr('rev'));
    });
    
    jq('.prodgrid-item, .products-featured-list .item').hover(
        function(){jq('.quick-view-button', this).fadeIn('slow'), jq('.link-compare', this).fadeIn('slow')},
        function(){jq('.quick-view-button', this).hide(), jq('.link-compare', this).hide()}
    );

    jq('.quick-view-button').fancybox({
        padding: 0,
        autoDimensions: true, 
        onComplete: function() {
            controlCartButton('0');
        }
    });

    jq('#compare-popup').click(function(){
        var offset = jq('.page').position();
        //jq('.block-compare-popup').css("left", (offset.left+750)+"px");
        jq('.block-compare-popup').animate({
                height: 'toggle'
            }, 400, function() {
                //jq('.block-compare-popup').show();
            });
    });

    jq('.helpful-yes').click(function(e){
        e.preventDefault();
        var link = jq(this);
        jq.getJSON(
            jq(this).attr('href'),
            function(response) {
                if (response.type == 'success') {
                    var question = jq(link).closest('li.record');
                    var helpful = jq('.helpful', question);
                    var total = jq('.total', question);
                    helpful.text(parseInt(helpful.text()) + 1);
                    total.text(parseInt(total.text()) + 1);
                    jq('strong.hidden', question).removeClass('hidden');
                } else {
                    alert(response.message);
                }
            }
        );
    });

    jq('.helpful-no').click(function(e){
        e.preventDefault();
        var link = jq(this);
        jq.getJSON(
            jq(this).attr('href'),
            function(response) {
                if (response.type == 'success') {
                    var question = jq(link).closest('li.record');
                    var total = jq('.total', question);
                    total.text(parseInt(total.text()) + 1);
                    jq('strong.hidden', question).removeClass('hidden');
                } else {
                    alert(response.message);
                }
            }
        );
    });

});
