//copyright LeAMIX arts; leamix@bk.ru

var step = 1;
var stepDelay = 15;
var waiting = 2000;
var stop = false;

var Bus = new Object();

	Bus.makeMove = function()
	{
		this.leftSpace += step;
		SLdiv.left = this.leftSpace + 'px';        
    	moving = setTimeout('moveOut()', stepDelay);
	}
	
	Bus.click = function()
	{
		if (stop == false)
	    { 
	        stop = true;
	        clearTimeout(moving);
	    }
	    else
	    {
	        stop = false;
	        moveOut();
	    }	
	}
	
	Bus.close = function()
	{
		clearTimeout(moving);
    	SLdiv.display = "none";
    	moving = null;
		Bus = null;
	}
	
function initSlide() 
{   
	SLdiv = getObject('bus_container').style;
	SLimg = getObject('bus_image');

	Bus.width = SLimg.width;
	Bus.leftSpace = -SLimg.width;
    moveOut();
}

function moveOut()
{
	var clWidth = document.body.clientWidth;
	
    if ((Bus.leftSpace + Bus.width) < clWidth) 
    {
        Bus.makeMove();
    }
    else
	{
		if ((SLimg.width > 0) && (Bus.leftSpace <= clWidth))
		{
			SLimg.width -= step;
			SLdiv.clientWidth -= step;                
			Bus.makeMove();
		}
		else
		{
			Bus.leftSpace = -Bus.width;
			SLdiv.left = '-' + Bus.width + 'px';
			SLimg.width = Bus.width;
			SLdiv.clientWidth = Bus.width; 
			moving = setTimeout('moveOut()', waiting);
		}
	}    
}
