//var doneInit=false;
var timer = 0;
var delay = 5; //msec
var scrollOffset = 20; //pixel
var docBody;
var posTimer = 0;
var scrollx = '';
var scrolly = '';
var myWidth = 0, myHeight = 0;
var loaded = false;

function init(){
	docBody = document[getDocElName()];
	doneInit = true;
	loaded = true;
	//goLeft(0);
}


function saveScrollCoordinates() { 
  scrollx = (document.all)?document.body.scrollLeft:window.pageXOffset; 
  scrolly = (document.all)?document.body.scrollTop:window.pageYOffset; 
  window.status = scrollx+'/'+scrolly;
  posTimer = setTimeout(saveScrollCoordinates,100);
  //alert(scrollx);
} 

function getWindowSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}

function goDown(targetYPos) {
	var y = docBody.scrollTop;
	if (y<targetYPos){
		window.scrollBy(0, scrollOffset);
		timer = setTimeout('goDown('+targetYPos+')', delay);
	}
	else clearTimeout(timer);
	return false;
}

function goUp(targetYPos) {
	var y = docBody.scrollTop;
	if (y>targetYPos){
		window.scrollBy(0, -scrollOffset);
		timer = setTimeout('goUp('+targetYPos+')', delay);
	}
	else clearTimeout(timer);
	return false;
}
// go right

function goRight(targetXPos) {
		clearTimeout(timer);
		doGoRight(targetXPos);	
}

function doGoRight(targetXPos) {
	//if(loaded==true) {	
		docBody = document[getDocElName()];		
		var x = docBody.scrollLeft;	
		if (x<targetXPos){			
			sBy = (x-targetXPos)*.2;
			window.scrollBy(-sBy, 0);
			timer = setTimeout('doGoRight('+targetXPos+')', delay);
			if(-sBy<1) {
				clearTimeout(timer);
				return false;
			}
		}
		else clearTimeout(timer);
} //}

function goLeft(targetXPos) {
		docBody = document[getDocElName()];		
		var x = docBody.scrollLeft;
		if (x>targetXPos){
			sBy = (x-targetXPos)*.2;		
			window.scrollBy(-sBy, 0);
			timer = setTimeout('goLeft('+targetXPos+')', delay);
			if(sBy<1) {
				clearTimeout(timer);
				return false;
			}		
		}
		else clearTimeout(timer);
}

function getDocElName(){
	return (document.compatMode && document.compatMode == "CSS1Compat") ? "documentElement" : "body";
}
var doneInit=true;