var Sidebars = Array();

// function to update the side bars
function Update() {
	NeedsUpdate = false;
	if(Sidebars.length > 0) for(i = 0; i < Sidebars.length; i++) {
		if(Sidebars[i].Update()) NeedsUpdate = true;
	}
	
	if(NeedsUpdate)
		window.setTimeout("Update()", 40);
		
}

function Sidebar(n,w) {
	// define local variables:
	this.name			= n				// name of the elements
	this.isMouseInCnt	= false;		// content mouse in
	this.isMouseInHdl	= false;		// handle mouse in
	this.Width			= w;			// DIV width
	this.Position		= -this.Width;	// DIV position
	this.inSpeed		= 30;			// # pixels for scroll in each frame 
	this.outSpeed		= 30;			// # pixels for scroll in each frame
	
	// add yourself to the sidebars:
	Sidebars[Sidebars.length] = this;
	
	// declare functions:
	this.State	= Sidebar_State;
	this.Update	= Sidebar_Update; 
}

function Sidebar_State(n, s) {
	if(n = 0)	this.isMouseInCnt = s;
	else		this.isMouseInHdl = s;

	if((this.Position == 0) | (this.Position == -this.Width)) {
		window.setTimeout("Update()", 50);
	}
}

function Sidebar_Update() {
	// check if the mouse is still within our DIVs:
	isMouseIn = (this.isMouseInCnt | this.isMouseInHdl); 

	// retrieve handles to DIVs:
	ContentElement	= document.getElementById(this.name);
	HandleElement	= document.getElementById(this.name + "-handle");
	
	// scroll the DIV:
	if(isMouseIn && this.Position < 0) {				// scroll in
		this.Position += this.inSpeed;
		if(this.Position > 0) this.Position = 0;
		ContentElement.style.zIndex	= 10; // bring element to front								
		ContentElement.style.left		= this.Position + "px";
		HandleElement.style.left		= this.Position + this.Width + "px";
	} else if(!isMouseIn && this.Position > -this.Width) {	// scroll out
		this.Position -= this.outSpeed;
		if(this.Position < -this.Width) this.Position = -this.Width;				
		if(this.Position == -this.Width) ContentElement.style.zIndex	= 0; // push element to back				
		ContentElement.style.left	= this.Position + "px";
		HandleElement.style.left	= this.Position + this.Width + "px";
	}
	
	// check if we have more animation frames:
	if(this.Position == 0 | this.Position == -this.Width) return false
	else return true;
}

