function slider($that, pageSize) {
	var $scrollable = $that.find('.scroll-container ul');
	var pageWidth   = $scrollable.find('li:first').outerWidth();
	var pageNum     = $scrollable.find('li').length;
	var $prev       = $that.find('.prev a');
	var $next       = $that.find('.next a');

	$scrollable.css('left', 0);
	$prev.hide();
	
	$prev.click(function() {
		if (parseInt($scrollable.css('left'))<0) { 
			if ($scrollable.queue()==0) {
				$scrollable.animate({left: '+='+(pageWidth*pageSize)});
				
				if (parseInt($scrollable.css('left'))>=(-pageWidth*pageSize)) {
					$next.show('slow');
					$prev.hide('slow');
				} else {
					$next.show('slow');
				}
			}
		}
	});
	
	$next.click(function() {
		if (parseInt($scrollable.css('left'))>=(-pageWidth*(pageNum-pageSize-1))) {
			if ($scrollable.queue()==0) {
				$scrollable.animate({left: '-='+(pageWidth*pageSize)});
				
				if (parseInt($scrollable.css('left'))<=(-pageWidth*(pageNum-2*pageSize))) {
					$next.hide('slow');
					$prev.show('slow');
				} else {
					$prev.show('slow');
				}
			}
		}
	});
}

function sliderAuto($that, pageSize) {
	var $prev       = $that.find('.prev a');
	var $next       = $that.find('.next a');
	var $scrollable = $that.find('.scroll-container ul');
	
	slider($that, pageSize);
	
	$that.mouseover(function() {
		$that.addClass('mouseover');
	});
	
	$that.mouseout(function() {
		$that.removeClass('mouseover');
	});
	
	function click($that, $prev, $next, $scrollable) {
		if ($that.hasClass('mouseover')) return;
		
		if ($next.css('display')!='none') { 
			$next.click();
		} else {
			$prev.hide('slow');
			$next.show('slow');
			$scrollable.animate({left: 0});
		}
	}
		
	window.setInterval(function() { click($that, $prev, $next, $scrollable); }, 4000);
}
