String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }

var actProduct = 0;
var productNums = 0;

$(document).ready(function(){
    $('#left_arrow img, #right_arrow img').tipTip();
    
    productNums = $('.product_table').size();
    $('#left_arrow img').click(function(){
        if ((productNums - actProduct) > 6) {
            ++actProduct;
            var i;
            for (i = 0; i < actProduct; ++i) {
                $('#product_slider .product_table:eq(' + i + ')').css('margin-left', (actProduct - i) * -105);
            }
            $('#right_arrow img').show();
            $('#first_product').html(actProduct + 1);
            $('#last_product').html(actProduct + 6);
        }
        if ((productNums - actProduct) <= 6) {
            $(this).hide();
        }
    });
    $('#right_arrow img').click(function(){
        if (actProduct > 0) {
            --actProduct;
            var i;
            for (i = 0; i <= actProduct; ++i) {
                $('#product_slider .product_table:eq(' + i + ')').css('margin-left', (actProduct - i) * -105);
            }
            $('#left_arrow img').show();
            $('#first_product').html(actProduct + 1);
            $('#last_product').html(actProduct + 6);
        }
        if (actProduct == 0) {
            $(this).hide();
        }
    });
});
