// Initialize

$(document).ready(function() 
{
	var MyToolbar = new ToolbarDrawer('toolbarDrawer', {
		openerClass: 'toolbarAction',
		openDuration: 600,
		openTransition: 'easeInOutCubic',
		closeDuration: 600,
		closeTransition: 'easeInOutCubic'
	});	
	
	$('.scroll-pane').jScrollPane({
		showArrows:true,
		scrollbarMargin:25,
		scrollbarWidth:14
	});
	
	if ($('#product_list').length > 0) 
	{
		var increment = 279;
		var count = $('.product_item').length;
		var maxLeft = -((count-3)*increment);
		var active = true;
		
		// Show or Hide left and right arrows
		function checkArrows(){
			var coordinates = $('#product_list').position();
			if (coordinates.left >= 0) { $('#leftArrow').hide(); } else { $('#leftArrow').show(); }
			if (coordinates.left <= maxLeft) { $('#rightArrow').hide(); } else { $('#rightArrow').show(); }
			active = false;
		}
		checkArrows();
		
		// Left an d right arrows actions
		$('#leftArrow').click(function(){
			if (!active) {
				active = true;
				$('#product_list').animate({ left:'+='+increment+'px' }, 'slow', function(){ checkArrows(); });
			}
		});
		$('#rightArrow').click(function(){
			if (!active){
				active = true;
				$('#product_list').animate({ left:'-='+increment+'px' }, 'slow', function(){ checkArrows(); });
			}
		});
		
		// Show product infos in list on mouse over
		$('#product_list .product_item').each(function(index, item){
			var toID = 0;
			var infosblock = $(item).find('.product_infos');
			infosblock.hide();
			$(item).bind('mouseenter', function(){
				toID = setTimeout(function(){
					infosblock.slideDown(300);
				}, 300);
			}).bind('mouseleave', function(){
				clearTimeout(toID);
				infosblock.slideUp(300);
			});
		});
		
	}
	
});

