jQuery.noConflict();
var animation = 0;
jQuery('#brandlist-next').live('click', function() {
    if(animation != 1)
    {
        animation = 1;
        var brandlistcols = jQuery('.brandlist-col').length;
        var maxWidth = (brandlistcols - 1) * 930
        var maxWidth = "-" + maxWidth;
        var curWidth = jQuery('#brandlist-slide-wrapper').css('marginLeft');
        var curWidth = curWidth.substring(0, curWidth.length - 2);
        
        if(curWidth <= maxWidth)
        {
    
            jQuery('#brandlist-slide-wrapper').animate({
                marginLeft: 0
            }, 1500, function(){
                animation = 0;
            });
    
        }
        
        else
        {
            
            var newWidth = parseInt(curWidth,10) - 930;
            jQuery('#brandlist-slide-wrapper').animate({
                marginLeft: newWidth
            }, 1500, function(){
                animation = 0;
            });
        }
    }
});

jQuery('#brandlist-prev').live('click', function() {
    console.log(animation);
    if(animation != 1)
    {
        animation = 1;    
        var brandlistcols = jQuery('.brandlist-col').length;
        var maxWidth = (brandlistcols - 1) * 930
        var maxWidth = "-" + maxWidth;
        var curWidth = jQuery('#brandlist-slide-wrapper').css('marginLeft');
        var curWidth = curWidth.substring(0, curWidth.length - 2);
    
        
        if(curWidth >= 0)
        {
            jQuery('#brandlist-slide-wrapper').animate({
                marginLeft: + maxWidth
            }, 1500, function(){
                animation = 0;
            });
    
        }
        else
        {
            jQuery('#brandlist-slide-wrapper').animate({
                marginLeft: parseInt(curWidth,10) + 930
            }, 1500, function(){
                animation = 0;
            });
        }
    }
});

jQuery('.home-products-button-next').live('click', function() {
    if(animation != 1)
    {
        animation = 1;
        var brandlistcols = jQuery(this).siblings('.home-products').find('.products-grid').length;
        var maxWidth = (brandlistcols - 1) * 920
        var maxWidth = "-" + maxWidth;
        var curWidth = jQuery(this).siblings('.home-products').css('marginLeft');
        var curWidth = curWidth.substring(0, curWidth.length - 2);
        console.log("cols: " + brandlistcols)
        console.log("max: " + maxWidth)
        console.log("cur: " + curWidth)
  
        
        if(parseInt(curWidth,10) <= parseInt(maxWidth,10))
        {
    
            jQuery(this).siblings('.home-products').animate({
                marginLeft: -15
            }, 1500, function(){
                animation = 0;
            });
    
        }
        
        else
        {
            
            var newWidth = parseInt(curWidth,10) - 920;
            jQuery(this).siblings('.home-products').animate({
                marginLeft: newWidth
            }, 1500, function(){
                animation = 0;
            });
        }
    }
});

jQuery('.home-products-button-prev').live('click', function() {
    console.log(animation);
    if(animation != 1)
    {
        animation = 1;    
        var brandlistcols = jQuery(this).siblings('.home-products').find('.products-grid').length;
        var maxWidth = (brandlistcols - 1) * 920
        var maxWidth = "-" + maxWidth;
        var curWidth = jQuery(this).siblings('.home-products').css('marginLeft');
        var curWidth = curWidth.substring(0, curWidth.length - 2);
                console.log("cols: " + brandlistcols)
        console.log("max: " + maxWidth)
        console.log("cur: " + curWidth)
    
        
        if(curWidth >= -15)
        {
            jQuery(this).siblings('.home-products').animate({
                marginLeft: + maxWidth
            }, 1500, function(){
                animation = 0;
            });
    
        }
        else
        {
            jQuery(this).siblings('.home-products').animate({
                marginLeft: parseInt(curWidth,10) + 920
            }, 1500, function(){
                animation = 0;
            });
        }
    }
});


