/*
* SCROLL CLASS
* © Copyright Paul Woods - 15/08/08
* http://www.woodscreativemedia.com
* v1.1.0a
*/
function Wcm_Scroll_Object()
{
	/* Optional Parameters */
	this.fps = 25; // Frames per second

	/* Scroll up */
	this.ScrollUp = function(target,distance)
	{
		var obj 		= document.getElementById(target);
		this.loc 		= obj.scrollTop;
		this.loc 		= this.loc-distance;
		if (this.loc < 0) {
			this.loc = 0;
		}
		this.target		= target;
		this.InitialiseTimer();
	}
	
	/* Scroll down */
	this.ScrollDown = function(target,distance)
	{
		var obj 		= document.getElementById(target);
		this.loc 		= obj.scrollTop;
		this.loc 		= this.loc+distance;
		this.target		= target;
		this.InitialiseTimer();
	}
	
	/* Scroll to Top */
	this.ScrollTop = function(target)
	{
		var obj 		= document.getElementById(target);
		this.loc 		= 0;
		this.target		= target;
		this.InitialiseTimer();
	}
	
	/* Scroll Div action function */
	this.ScrollAction = function()
	{
		var obj 				= document.getElementById(myobject.target);
		myobject.current_pos	= obj.scrollTop;
		myobject.inertia 		= parseInt((myobject.loc-myobject.current_pos)/4);

		obj.scrollTop += myobject.inertia;
		myobject.new_position = obj.scrollTop;
		
		/* Compare the old scroll position to the new position, if they are the same
		then the movement is complete so Clear() the interval */
		if (myobject.old_position == myobject.new_position) {
			obj.scrollTop 	= myobject.loc;
			/* Force loc to match scroll value */
			myobject.loc	= obj.scrollTop;
			myobject.ClearTimer();
		}

		myobject.old_position = obj.scrollTop;
	}
	
	/* Initialise the timer */
	this.InitialiseTimer = function()
	{
		this.status	= "moving";
		myobject 	= this;
		timer		= 1000/this.fps; // Get the real FPS
		/* Start a new interval if one does not already exist */
		if (!this.newint) {
			this.newint = setInterval(myobject.ScrollAction,timer);
		}
	}
	
	/* Clear the timer when done */
	this.ClearTimer = function()
	{
		myobject.status = "stopped";
		clearInterval(myobject.newint);
		myobject.newint = false;
		
	}
}
var Scroller = new Wcm_Scroll_Object();