/*
Plugin Name: AutoScroll
Version: 0.2 (20/01/2009)
Plugin URI: http://www.deambulando.com/2009/01/20/autoscroll/
Description: Scroll 
Author: Chema Garrido
Author URI: http://www.garridodiaz.com/

License information
Copyright 2009
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt
*/


	var scrollCount;//count scroll in pixels
	var scrollJump;//jump in pixels
	var scrollJumpMin;//minimal jump in pixels
	var maxScroll;//max scroll
	var x; //coordinate X
	var y; // coordinate Y
   
   scrollJumpMin=20;//we need to set up a minimal jump cuz in other case sometimes is really slow the case (when the page is small for example)
   
   function scrollDown(tiempo){//first parameter:  time in seconds
		returnScrollOffset();//to know the scroll seted
		scrolly=y;
		returnInnerDimensions();//to know the sreen size
		scrollCount = y + scrolly;//position that we are is = screen size + scroll in y
		returnPageDimensions();//to know the maximum that we can scroll
		maxScroll = y;       
		scrollJump=((maxScroll-scrollCount)/(tiempo*1000))*20//how much we jump per time
		if (scrollJump<scrollJumpMin) scrollJump=scrollJumpMin; //if the scroll is less than the minimal we set it
		autoScroll();
	}
      
     
	function scrollUp(scro,tiempo){//first parameter: where to stop scrolling up in px, second time in seconds
		returnScrollOffset();//scroll done
		scrollCount = y;//scroll on y done, we dont need the inner position
		maxScroll = scro;//position we move       
		scrollJump=(scrollCount/(tiempo*1000))*20;//how much we jump
		if (scrollJump<scrollJumpMin) scrollJump=scrollJumpMin; //if the scroll is less than the minimal we set it
		autoScrollMinus();
	}
	
	function scrolling(scro,tiempo){//first parameter: where to stop scrolling px, second time in seconds
		scrollCount = 0;
		maxScroll = scro;       
		scrollJump=(tiempo*1000)/maxScroll;
		if (scrollJump<scrollJumpMin) scrollJump=scrollJumpMin; //if the scroll is less than the minimal we set it
		autoScroll();
   }
      
	
	function autoScroll(){//to scroll down we add
		if (scrollCount < maxScroll) {
			scrollCount+=scrollJump;
			scroll(0,scrollCount);
			timer=setTimeout("autoScroll()",1);   
		}       
	}

	function autoScrollMinus(){//to scroll up we rest
		if ( scrollCount> maxScroll) {
			scrollCount-=scrollJump;
			scroll(0,scrollCount);
			setTimeout("autoScrollMinus()",1);   
		}       
	}


	function returnInnerDimensions(){
			if (self.innerHeight) // all except Explorer
			{
				x = self.innerWidth;
				y = self.innerHeight;
			}
			else if (document.documentElement && document.documentElement.clientHeight)
				// Explorer 6 Strict Mode
			{
				x = document.documentElement.clientWidth;
				y = document.documentElement.clientHeight;
			}
			else if (document.body) // other Explorers
			{
				x = document.body.clientWidth;
				y = document.body.clientHeight;
			}
	}
	
	function returnScrollOffset(){
			if (self.pageYOffset) // all except Explorer
			{
				x = self.pageXOffset;
				y = self.pageYOffset;
			}
			else if (document.documentElement && document.documentElement.scrollTop)
				// Explorer 6 Strict
			{
				x = document.documentElement.scrollLeft;
				y = document.documentElement.scrollTop;
			}
			else if (document.body) // all other Explorers
			{
				x = document.body.scrollLeft;
				y = document.body.scrollTop;
			}
	}
	
	function returnPageDimensions(){
			var test1 = document.body.scrollHeight;
			var test2 = document.body.offsetHeight
			if (test1 > test2) // all but Explorer Mac
			{
				x = document.body.scrollWidth;
				y = document.body.scrollHeight;
			}
			else // Explorer Mac;
					 //would also work in Explorer 6 Strict, Mozilla and Safari
			{
				x = document.body.offsetWidth;
				y = document.body.offsetHeight;
			}
	}




