function setCartIndicator(num) {
    
    $('#cart-indicator .count').fadeOut(function(){$(this).text(num).fadeIn()});
}


$.fn.initBigProduct = function () {
   return this.each(function(){
       var $this = $(this);
       var $overlay = $this.find('.overlay');
       
       $this.bind('mouseenter', function(){ $overlay.fadeIn() });
       //$overlay.bind('mouseleave', function(){ $overlay.fadeOut() });
       $this.bind('mouseleave', function(){ $overlay.fadeOut() });
       
       $this.click(function(){ window.location = $(this).find('h2 a').attr('href'); });
       
       $overlay.find('.add-to-cart a').click(function(e) {
            e.stopPropagation();
            $.get($(this).attr('href'), {size: $('ul.sizing-grid li.selected').text()}, function(data) {
                $.flashMessenger('Product Added to Cart');
                setCartIndicator(data);
            });  
            return false;
       });
   });
}

$.fn.initSmallProduct = function () {
    var container = $('#featured');
    return this.each(function(){
        $(this).click(function(){
            var pid = $(this).attr('id').replace(/product-/, '');
            container.children().fadeOut();
            $.post(baseUrl + "/products/single", { id: pid, format: 'ajax' },
              function(data){
                container.html(data);
                container.children().hide().find(".image img").load(function() {$(this).closest('.big-product').fadeIn(); });
                container.find('.big-product').initBigProduct();
                initTooltips();
             });
        }); 
    });
}

function initTooltips() {
    $('.tooltip').tooltip({ 
        track: true, 
        delay: 0, 
        showURL: false, 
       // showBody: " - ", 
        fade: 250 
    });
}

var sclPaginator = Class.extend({
    init: function(pages, options) {
        this.o =  jQuery.extend({
         }, options);
        
        this.currentPage = 1;
        this.pages = $(pages);
        this.pageWidth = this.pages.css('width').replace(/[^0-9]/g, '');
        this.lastPage = this.pages.length;
    },

    next: function() {
        if(this.currentPage >= this.lastPage)
            return false;
        
        this.pages.animate({"left": "-="+this.pageWidth+"px"}, "slow");
        this.currentPage++;
        return false;
    },

    prev: function() {
        if(this.currentPage == 1)
            return false;
        
        this.pages.animate({"left": "+="+this.pageWidth+"px"}, "slow");
        this.currentPage--;
        return false;
    }
});


// Due to the unique nature of the website, the spacebar as scroll in FF screws things up. Disable it completely.
$(window).bind('keydown',function(e){
        if(e.target.tagName.toLowerCase() != 'input' && e.target.tagName.toLowerCase() != 'textarea')
            if(e.keyCode==32)
                return false;  
    }); 
