function Scroll_moveBack()
{		
  if (count < scrollValue)
  {    		      
    speed = (scrollValue - count) / this.kStop + 1;				
	this.position = this.position + speed;

    count = count + speed;
	if (count > scrollValue)
		this.position = this.position - (count-scrollValue);
	
	object.style.left = this.position + 'px';			

  }
  else
  {			
    clearInterval(this.timer);
	this.timer = 0;
	this.itemValidate();
  }
}
		  
function Scroll_moveForvard()
{
  if (count < scrollValue)
  {    		  
    speed = (scrollValue - count) / this.kStop + 1;
	this.position = this.position - speed;		

	count = count + speed;
	if (count > scrollValue)
		this.position = this.position + (count-scrollValue);
		
	object.style.left = this.position + 'px';

  }
  else
  {		
    clearInterval(this.timer);
    this.timer = 0;
	this.itemValidate();
  }
}
		  
function Scroll_initMoveBack()
{		
  if (this.timer == 0)
  {
    if (this.visibleElement > 1)
	{
      scrollValue = this.scrollWidth;
  	  this.hideItem();
	  this.visibleElement = this.visibleElement - 1;
  	  this.showItem();
	  
	  count = 0;

	  object = document.getElementById(this.scrollBlock);
	  t = this;
      this.timer = setInterval(( function() {return t.moveBack();}), this.timeOut);
	  
	  this.itemValidate();
    }
  }
}
		  
function Scroll_initMoveForvard()
{ 
  if (this.timer == 0)
  {
    if ((this.visibleElement < this.elementCount) || (this.systimer != 0))
	{
	  scrollValue = this.scrollWidth;

      this.hideItem();
  		
		if ((this.systimer != 0) && (this.visibleElement == this.elementCount))
	  	{
	    	  this.initMoveTo(1);		
					return;
		  }
		  else
		  {
			 	  this.visibleElement = this.visibleElement + 1;			   
		  }
			
  	  this.showItem();
	  
      count = 0;
      object = document.getElementById(this.scrollBlock);      

	  t = this;
      this.timer =  setInterval(( function() { return t.moveForvard(); } ), this.timeOut); 
	  
  	  this.itemValidate();
    }
  }
}	

function Scroll_initMoveTo(elementItem)  
{
  if (this.timer == 0)
  {
    if (this.visibleElement - elementItem > 0)
	{

	  scrollValue = (this.visibleElement - elementItem) * this.scrollWidth;

	  this.hideItem();
	  this.visibleElement = elementItem;	  
	  this.showItem();

  	  count = 0;   

      object = document.getElementById(this.scrollBlock);
	  t = this;
      this.timer = setInterval((function () {t.moveBack();}), this.timeOut);			  

      this.itemValidate();
    }
    if (elementItem - this.visibleElement > 0)
	{
	  scrollValue = (elementItem - this.visibleElement) * this.scrollWidth;

	  this.hideItem();
      this.visibleElement = elementItem;
  	  this.showItem();
	  
      count = 0;   

      object = document.getElementById(this.scrollBlock);
	  t = this;
      this.timer = setInterval((function() {t.moveForvard();}), this.timeOut);			  

	  this.itemValidate();
    }
  } 
}
		

function Scroll_controlBackOver()
{
  if (this.visibleElement != 1)
  {
    var object;

    object = document.getElementById(this.controlBackName);
    object.style.display = 'none';
		    
    object = document.getElementById(this.controlBackName + '_hover');
    object.style.display = 'block';
  }
}


function Scroll_controlBackOut()
{
  if (this.visibleElement != 1)
  {
    var object;

    object = document.getElementById(this.controlBackName + '_hover');
    object.style.display = 'none';

    object = document.getElementById(this.controlBackName);
    object.style.display = 'block';		    
  }
}
		  
function Scroll_controlForvardOver()
{
  if (this.visibleElement != this.elementCount)
  {
    var object;
    object = document.getElementById(this.controlForvardName);
    object.style.display = 'none';
		    
    object = document.getElementById(this.controlForvardName + '_hover');
    object.style.display = 'block';
  }
}
		  
function Scroll_controlForvardOut()
{
  if (this.visibleElement != this.elementCount)
  {
    var object;
   
    object = document.getElementById(this.controlForvardName + '_hover');
    object.style.display = 'none';

    object = document.getElementById(this.controlForvardName);
    object.style.display = 'block';		    
  }
}		

function Scroll_hideItem()
{
  var object;
  object = document.getElementById(this.itemName + this.visibleElement);
  object.className = "item";
}

function Scroll_showItem()
{
  var object;
  object = document.getElementById(this.itemName + this.visibleElement);
  object.className = "selectitem";
}


function Scroll_itemValidate()
{
	var object;

	if (this.visibleElement == 1)
	{
	  object = document.getElementById(this.scrollBlock);
  	  object.style.left = '0px';			
		
	  object = document.getElementById(this.controlBackName);
	  object.style.display = 'none';
	  
   	  object = document.getElementById(this.controlBackName + '_hover');
	  object.style.display = 'none';
		    
	  object = document.getElementById(this.controlBackName + '_not_enable');
	  object.style.display = 'block';
	}
	else
	{
	  object = document.getElementById(this.controlBackName + '_not_enable');
	  object.style.display = 'none';
	  
  	  object = document.getElementById(this.controlBackName + '_hover');
	  object.style.display = 'none';

	  object = document.getElementById(this.controlBackName);
	  object.style.display = 'block';		    
	}
	
	if (this.visibleElement == this.elementCount)
	{
	  object = document.getElementById(this.controlForvardName);
      object.style.display = 'none';
	  
      object = document.getElementById(this.controlForvardName + '_hover');
      object.style.display = 'none';
		    
      object = document.getElementById(this.controlForvardName + '_not_enable');
      object.style.display = 'block';
	}
	else
	{
      object = document.getElementById(this.controlForvardName + '_not_enable');
      object.style.display = 'none';
	  
      object = document.getElementById(this.controlForvardName + '_hover');
      object.style.display = 'none';
	  
	  object = document.getElementById(this.controlForvardName);
      object.style.display = 'block';		
	}	
}

function Scroll_initSysMoveForvard()
{
	t = this;
	this.systimer = setInterval((function() {return t.initMoveForvard();}), 1000 * this.interval);
}

function Scroll_clearAutoScroll()
{
	clearInterval(this.systimer);
	this.systimer = 0;
}

var object;
var count = 0;
var scrollValue;

  
function Scroll(scrollBlock, elementCount, width, interval)
{  
  this.scrollBlock = scrollBlock;
  
  this.position = 0;
  this.scrollWidth = width;		  
  
  this.timer = 0;
	
  this.kStop = 2.5;
  this.timeOut = 50;
  
  this.controlBackName = '';
  this.controlForvardName = '';
  this.itemName = '';

  this.elementCount = elementCount;
  this.visibleElement = 1;
  
  this.interval = interval;
  
  
  this.moveBack = Scroll_moveBack;
  this.moveForvard = Scroll_moveForvard;
  this.initMoveBack = Scroll_initMoveBack;
  this.initMoveForvard = Scroll_initMoveForvard;
  this.initMoveTo = Scroll_initMoveTo;

  this.controlBackOver = Scroll_controlBackOver;
  this.controlBackOut = Scroll_controlBackOut;
  this.controlForvardOver = Scroll_controlForvardOver;
  this.controlForvardOut = Scroll_controlForvardOut;

  this.itemValidate = Scroll_itemValidate;
  this.initSysMoveForvard = Scroll_initSysMoveForvard;
  this.clearAutoScroll = Scroll_clearAutoScroll;

  this.hideItem = Scroll_hideItem;
  this.showItem = Scroll_showItem;
}

	

