var
	sdLeft    = 0,
	sdRight   = 1,
	sdUp      = 2,
	sdDown    = 3,
	slideDivs = new Array();
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TSlideDiv = function( 
			name, speed, direction, 
			left, top, width, heigth, 
			offset, onOpen, onClose )
{
	this.name      = name
	this.speed     = speed;
	this.interval  = 20;
	this.direction = direction;
	this.timer     = null;
	this.left      = left;
	this.top       = top;
	this.width     = width;
	this.height    = heigth;
	this.offset    = offset;
	this.opened    = false;
	this.onOpen    = onOpen;
	this.onClose   = onClose;
	
	slideDivs[slideDivs.length] = this;
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.open = function( onEnd )
{
	switch ( this.direction )
	{
		case sdLeft  :
		case sdUp    :
			document.getElementById("div" + this.name ).style.display = "";
			this.slide( -1, onEnd );
			break;
		case sdRight :
		case sdDown  :
			document.getElementById("div" + this.name ).style.display = "";
			this.slide( 1, onEnd );
	}
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.close = function( onEnd )
{
	switch ( this.direction )
	{
		case sdLeft  :
		case sdUp    :
			this.slide( 1, onEnd );
			break;
		case sdRight :
		case sdDown  :
			this.slide( -1, onEnd );
	}
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.toggle = function()
{
	if ( this.opened ) 
		this.close();
	else
		this.open();
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.initialize = function()
{
	var
		div  = document.getElementById("div" + this.name ),
		div1 = document.getElementById( this.name + "Inner"),
		div2 = document.getElementById( this.name + "InnerBg");
	
	if ( this.height == 0 )	
	{	
		div.style.height = div1.offsetHeight + "px";

		if ( this.direction == sdDown )
		{
			div1.style.top   = (-div1.offsetHeight + this.offset) + "px";
			if ( div2 )
				div2.style.top   = (-div1.offsetHeight + this.offset) + "px";
		}
		else if ( this.direction == sdUp )
		{
			div1.style.top   = (div1.offsetHeight - this.offset) + "px";
			if ( div2 )
				div2.style.top   = (div1.offsetHeight - this.offset) + "px";
		}
	}
	
	if ( this.width == 0 )	
	{	
		div.style.height = div1.offsetWidth + "px";

		if ( this.direction == sdLeft )
		{
			div1.style.left   = (-div1.offsetWidth + this.offset) + "px";
			if ( div2 )
				div2.style.left   = (-div1.offsetWidth + this.offset) + "px";
		}
		else if ( this.direction == sdRight )
		{
			div1.style.left   = (div1.offsetWidth - this.offset) + "px";
			if ( div2 )
				div2.style.left   = (div1.offsetWidth - this.offset) + "px";
		}
	}

	if ( this.offset )
		div.style.display = "";
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.reposition = function( scrWidth )
{
	if ( document.getElementById("div" + this.name ) ) 
	{
		if ( scrWidth > siteWidth )
			document.getElementById("div" + this.name ).style.left = (((scrWidth - siteWidth) / 2) + this.left ) + "px";
		else
			document.getElementById("div" + this.name ).style.left = this.left + "px";
	}
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.slide = function( step, onEnd )
{
	if ( document.readyState && document.readyState != "complete")
		return;
		
	if ( onEnd == null )
		onEnd = "";

	var 
		divParent = document.getElementById("div" + this.name ),
		divChild  = document.getElementById( this.name + "Inner"),
		divBackgr = document.getElementById( this.name + "InnerBg");
		
	if ( divParent && divChild  )
	{
		var
			exec,
			doAgain   = false,
			x         = parseInt( divChild.style.left ),
			y         = parseInt( divChild.style.top );
			
		if ( step > 0 )
			step = this.speed;
		else
			step = -this.speed;
			
		this.stopTimer();
	
		exec = ", \"" + onEnd + "\"";
		
		if ( this.direction == sdLeft )
		{
			if ( step < 0 && x + step > 0 )
			{
				divChild.style.left = x + step + "px";
				if ( divBackgr )
					divBackgr.style.left = x + step + "px";
				
				doAgain = true;
			}
			else if ( step > 0 && x + step < parseInt( divParent.style.width ) - this.offset )
			{
				divChild.style.left = x + step + "px";
				if ( divBackgr )
					divBackgr.style.left = x + step + "px";
				
				doAgain = true;
			}
			else if ( step < 0 )
			{
				divChild.style.left = "0px";
				if ( divBackgr )
					divBackgr.style.left = "0px";
				
				this.opened = true;
				
				if ( this.onOpen )
					this.onOpen( this );
				
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 0 );
					
			}
			else
			{
				divChild.style.left = parseInt( divParent.style.width ) - this.offset + "px";
				if ( divBackgr )
					divBackgr.style.left = parseInt( divParent.style.width ) - this.offset + "px";
					
				if ( this.offset == 0 )
					divParent.style.display = "none";
				
				this.opened = false;
				
				if ( this.onClose )
					this.onClose( this );
					
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
		}
		else if ( this.direction == sdRight )
		{
			if ( step > 0 && x + step < 0 )
			{
	 			divChild.style.left = x + step + "px";
				if ( divBackgr )
					divBackgr.style.left = x + step + "px";
				
				doAgain = true;
			}
			else if ( step < 0 && x + step > -parseInt( divParent.style.width ) + this.offset )
			{
				divChild.style.left = x + step + "px";
				if ( divBackgr )
					divBackgr.style.left = x + step + "px";
				
				doAgain = true;
			}
			else if ( step > 0 )
			{
				divChild.style.left = "0px";
				if ( divBackgr )
					divBackgr.style.left = "0px";
					
				this.opened = true;
				
				if ( this.onOpen )
					this.onOpen( this );
				
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
			else 
			{
				divChild.style.left = -parseInt( divParent.style.width ) + this.offset + "px";
				if ( divBackgr )
					divBackgr.style.left = -parseInt( divParent.style.width ) + this.offset + "px";
					
				if ( this.offset == 0 )
					divParent.style.display = "none";
				
				this.opened = false;
				
				if ( this.onClose )
					this.onClose( this );
					
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
		}
		else if ( this.direction == sdUp )
		{
			if ( step < 0 && y + step > 0 )
			{
				divChild.style.top = y + step + "px";
				if ( divBackgr )
					divBackgr.style.top = y + step + "px";
				
				doAgain = true;
			}
			else if ( step > 0 && y + step < parseInt( divParent.style.height ) - this.offset )
			{
				divChild.style.top = y + step + "px";
				if ( divBackgr )
					divBackgr.style.top = y + step + "px";
				
				doAgain = true;
			}
			else if ( step < 0 )
			{
				divChild.style.top = "0px";
				if ( divBackgr )
					divBackgr.style.top = "0px";
				
				this.opened = true;
				
				if ( this.onOpen )
					this.onOpen( this );
				
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
			else
			{
				divChild.style.top = parseInt( divParent.style.height ) - this.offset + "px";
				if ( divBackgr )
					divBackgr.style.top = parseInt( divParent.style.height ) - this.offset + "px";
					
				if ( this.offset == 0 )
					divParent.style.display = "none";
				
				this.opened = false;
				
				if ( this.onClose )
					this.onClose( this );
					
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
		}
		else if ( this.direction == sdDown )
		{
			if ( step > 0 && y + step < 0 )
			{
				divChild.style.top = y + step + "px";
				if ( divBackgr )
					divBackgr.style.top = y + step + "px";
				
				doAgain = true;
			}
			else if ( step < 0 && y + step > -parseInt( divParent.style.height ) + this.offset )
			{
				divChild.style.top = y + step + "px";
				if ( divBackgr )
					divBackgr.style.top = y + step + "px";
				
				doAgain = true;
			}
			else if ( step > 0 )
			{
				divChild.style.top = "0px";
				if ( divBackgr )
					divBackgr.style.top = "0px";
				
				this.opened = true;
				
				if ( this.onOpen )
					this.onOpen( this );
				
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
			else 
			{
				divChild.style.top = -parseInt( divParent.style.height ) + this.offset + "px";
				if ( divBackgr )
					divBackgr.style.top = -parseInt( divParent.style.height ) + this.offset + "px";
					
				if ( this.offset == 0 )
					divParent.style.display = "none";
				
				this.opened = false;
				
				if ( this.onClose )
					this.onClose( this );
					
				if ( onEnd != "")
					this.timer = setTimeout( onEnd, 1 );
			}
		}

		if ( doAgain )		
			this.timer = setTimeout( this.name + ".slide(" + step + exec + ");", this.interval );
	}
}
//-------------------------------------------------------------------------------------------------
TSlideDiv.prototype.stopTimer = function()
{
	if ( this.timer )
		clearTimeout( this.timer );
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

