$().ready(function(){

	/*
	 *		Scroller using jQueries .animate to slide a <div>, allowing different elements along its width to be viewed.
	 *		
	 *		by Ricky Stevens - 14/06/2009
	*/

	// preset variables
	var viewPortHeight = 600;		// height of #viewport
	var scrollDistance = 400;		// amount to scroll
	var animationSpeed = 200;		// speed to scroll at


	// slide down function trigger
	$('.scrollDown').click(function(){

		// define height of all elements, and get current location on page
		var viewheight = $('#viewPort').height();
		var lft = parseInt($('#viewPort').css('top').split('px'));

		// execute if slider is not on the top item
		if(viewheight > viewPortHeight) {

			// check to see if slider is within 1 scroll of the bottom
			if((lft - viewPortHeight) > (viewPortHeight - viewheight)) {
				$('#viewPort').animate({top: (lft-scrollDistance)+'px'}, animationSpeed);
			}else{
				$('#viewPort').animate({top: (viewPortHeight - viewheight)+'px'}, animationSpeed);
			}

		}

		return false;

	});
	
	// slide down function trigger
	$('.scrollUp').click(function(){

		// get sliders current location		
		var lft = parseInt($('#viewPort').css('top').split('px'));

		// check to see if slider is within 1 scroll of the top
		if((lft + scrollDistance) <= 0) {
			// scroll default amount
			$('#viewPort').animate({top: (lft+scrollDistance)+'px'}, animationSpeed);
		} else {
			// scroll top top of window
			$('#viewPort').animate({top: '0px'}, animationSpeed);
		}

		return false;

	});

	// slide to top function trigger
	$('.scrollTop').click(function(){

		$('#viewPort').animate({top: '0px'}, (animationSpeed + 100));

		return false;

	});
	
});
