var scrollRef = null;  
var ie4=document.all&&!document.getElementById;
var ns4=document.layers;
var DOM2=document.getElementById;
var opera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false


if (document.layers) {
	visible = 'show';
	hidden = 'hide';
}
else if (document.all) {
	visible = 'visible';
	hidden = 'hidden';
}
else if (DOM2) {
	visible = "visible";
	hidden = "hidden";	
}
 
	
function scrollObj(win)
{
	this.id = win;
	this.scrollwindow = null;
	this.contentwindow = null;
	this.nav1 = null;
	this.nav2 = null;
	this.timerID = 0
	this.scrollPosX = 0;
	this.scrollPosY = 0;
	this.slowSpeed = 5;
	this.stepSpeed = 5;
	this.maxWidth = 624;
	this.maxHeight = 275;
	this.maxDisplayX = 624;
	this.maxDisplayY = 275;		
	this._d = null;
	
	this.initWindows 	= scrollObj_initWindows;
	this.ScrollLeft		= scrollObj_ScrollLeft;
	this.ScrollRight	= scrollObj_ScrollRight;
	this.ScrollUp 		= scrollObj_ScrollUp;
	this.ScrollDown 	= scrollObj_ScrollDown;
	this.initScroll   	= scrollObj_initScroll;
	this.doubleSpeed  	= scrollObj_doubleSpeed;
	this.resetSpeed		= scrollObj_resetSpeed;
	this.stopScroll		= scrollObj_stopScroll;
}


function scrollObj_initWindows(cntId,nStep,nav1ID,nav2ID) {
	
	this._d = document;
	
	if(this._d.getElementById){  
		this.scrollwindow	= this._d.getElementById(this.id);		
		this.contentwindow	= this._d.getElementById(cntId);
		this.nav1			= this._d.getElementById(nav1ID);
		this.nav2			= this._d.getElementById(nav2ID);
	} else if(this._d.all){
		this.scrollwindow	= this._d.all[this.id];
		this.contentwindow	= this._d.all[cntId];		
		this.nav1			= this._d.all[nav1ID];		
		this.nav2			= this._d.all[nav2ID];		
	} else if(this._d.layers){
		this.scrollwindow	= this._d[this.id];
		this.contentwindow	= this._d[cntId];		
		this.nav1			= this._d[nav1ID];		
		this.nav2			= this._d[nav2ID];		
	}
	
	this.maxWidth 	= this.contentwindow.offsetWidth;
	this.maxDisplayX = this.scrollwindow.style.width;
	this.maxDisplayX = this.maxDisplayX.replace ("px", "");

	
	this.maxHeight 	= this.contentwindow.offsetHeight;
	this.maxDisplayY = this.scrollwindow.style.height;
	this.maxDisplayY = this.maxDisplayY.replace ("px", "");
	
	
	
	if (this.maxHeight < this.maxDisplayY) {	
		//alert(this.maxHeight + ' ' + this.maxDisplayY);
		if (this.nav1)
			this.nav1.style.visibility = hidden;
		if (this.nav2)
			this.nav2.style.visibility = hidden;
	}
	
	
	this.scrollwindow.style.left 	= this.scrollPosX + "px";
	this.scrollwindow.style.top 	= this.scrollPosY + "px";
	
	this.slowSpeed 	= nStep;	
	this.stepSpeed 	= this.slowSpeed;
}

function scrollObj_ScrollLeft(){

	scrollRef = this;
	
	if(this.timerID) {
      	clearTimeout(this.timerID);
	}
	
	this.scrollPosX = this.scrollPosX + this.stepSpeed;	
	if (this.scrollPosX > 0)
	{
		this.scrollPosX = 0;
		this.scrollwindow.style.left  = this.scrollPosX + "px"
	}
	else
	{
		this.scrollwindow.style.left  = this.scrollPosX + "px"
		this.timerID = setTimeout("DoTimeOut('left')", 10);		
	}
}

function scrollObj_ScrollRight(){
	
	scrollRef = this;
	
	if(this.timerID) {
      	clearTimeout(this.timerID);
	}

	this.scrollPosX = this.scrollPosX - this.stepSpeed;	
	
	if (this.scrollPosX <  (this.maxDisplayX - this.maxWidth))
	{
		if (this.maxWidth < this.maxDisplayX)
			this.scrollPosX = 0;
		else		
			this.scrollPosX = (this.maxDisplayX - this.maxWidth);
			
		this.scrollwindow.style.left  = this.scrollPosX + "px"
	}
	else
	{
		this.scrollwindow.style.left  = this.scrollPosX + "px"
		this.timerID = setTimeout("DoTimeOut('right')", 10);
	}
}	
		

function scrollObj_ScrollUp(){

	scrollRef = this;

	if(this.timerID) {
      	clearTimeout(this.timerID);
	}
			
	this.scrollPosY = this.scrollPosY + this.stepSpeed;	
		
	if (this.scrollPosY > 0)
	{
		this.scrollPosY = 0;
		this.scrollwindow.style.top  = this.scrollPosY + "px"
	}
	else
	{
		this.scrollwindow.style.top  = this.scrollPosY + "px"
		this.timerID = setTimeout("DoTimeOut('up')", 10);		
	}
}

function scrollObj_ScrollDown(){

	scrollRef = this;

	if(this.timerID) {
      	clearTimeout(this.timerID);
	}
		
	this.scrollPosY = this.scrollPosY - this.stepSpeed;	

	if (this.scrollPosY <  (this.maxDisplayY - this.maxHeight))
	{
		if (this.maxHeight < this.maxDisplayY)
			this.scrollPosY = 0;
		else
			this.scrollPosY = (this.maxDisplayY - this.maxHeight);
			
		this.scrollwindow.style.top  = this.scrollPosY + "px"
	}
	else
	{
		this.scrollwindow.style.top  = this.scrollPosY + "px"
		this.timerID = setTimeout("DoTimeOut('down')", 10);
	}	
}	

function DoTimeOut(dir)
{
	
	if (scrollRef) {
		if (dir == 'left'){
			scrollRef.ScrollLeft();
		} else if (dir == 'right'){
			scrollRef.ScrollRight();
		} else if (dir == 'up'){
			scrollRef.ScrollUp();
		} else if (dir == 'down'){		
			scrollRef.ScrollDown();
		}
	}
}		

function scrollObj_initScroll(dir) {

	if (dir == 'left'){
		this.ScrollLeft();
	} else if (dir == 'right'){
		this.ScrollRight();
	} else if (dir == 'up'){
		this.ScrollUp();
	} else if (dir == 'down'){		
		this.ScrollDown();
	}
						
	return;
}

function scrollObj_doubleSpeed() {
  	this.stepSpeed = this.slowSpeed * 2;
}

function scrollObj_resetSpeed() {
  	this.stepSpeed = this.slowSpeed;
}

function scrollObj_stopScroll () {
	if(this.timerID) {
      	clearTimeout(this.timerID);
	}
	this.stepSpeed = this.slowSpeed;
	scrollRef = null;
}
