
// -------------------------------------------------------------
// DOM is ready
// -------------------------------------------------------------
$(document).ready(function() {
	scrollOnClick();
	if ($("#lastposting").length) { lastPosting(); }
});

// -------------------------------------------------------------
// Scrollable products
// -------------------------------------------------------------
function scrollOnClick() {
	
	var inview = 4   // Number of products in viewable area
	var prods = 16   // Total number of products within scrollable area
	var speed = 700  // Scroll speed in milliseconds
	var width = 150  // Width of one product
	var width2 = 10  // Width of one dot
	
	var jump = (width*inview)   // Jump distance for products
	var jump2 = (width2*inview) // Jump distance for dots
	
	var maxright = (width*prods)-(width*inview)
	
	$('#scrollable_wrap .dots').width(prods*width2);
	$('#scrollable_wrap .dots ul').width(prods*width2);
	
	$('#scrollable_wrap #move_left').mouseup(function(event) {
		event.preventDefault();
		if (scrollLeftPx()<0) {
			$('#scrollable_wrap #scrollable ul').animate({ left: '+='+jump }, speed);
			$('#scrollable_wrap .dots span').animate({ left: '-='+jump2 }, speed);
		}
	});
	$('#scrollable_wrap #move_right').mouseup(function(event) {
		event.preventDefault();
		if (scrollLeftPx()>(-maxright)) {
			$('#scrollable_wrap #scrollable ul').animate({ left: '-='+jump }, speed);
			$('#scrollable_wrap .dots span').animate({ left: '+='+jump2 }, speed);
		}
	});
	
	$('#scrollable_wrap #move_left').click(function(event) { event.preventDefault(); });
	$('#scrollable_wrap #move_right').click(function(event) { event.preventDefault(); });
	
}
function scrollLeftPx() {
	var pos = $('#scrollable_wrap #scrollable ul').position();
	return pos.left-40; // -40 to take into account the left arrow button
}


/////////////////////////////////////////////////////////
// Last posting dates
/////////////////////////////////////////////////////////
function lastPosting() {
	$("#lastposting_table").hide();
	$("#lastposting_link").bind("click",function(e){
		$('#lastposting_table').toggle();
		e.preventDefault();
	});
}


 




