
function SideBar(cf)
{
	
	this.Interal = cf.interal;
	this.autoplay = false;
	this.container =$(cf.id);

	this.height = cf.height;
	this._list = [];
	this._get_list_element(this.container);
	this.currentIndex = 0;
	this.dir = 1;	 // 0 ΟΒ 1 ΙΟ
	this.timeID = 0;
	this.subtimeID = 0;
}

SideBar.prototype._get_list_element = function (obj)
{	
	var list = obj.getElementsByTagName("li");
	for(var i = 0;i<list.length;i++)
	{
	    this._list.push({index:i,ele:list[i]});
	}

}
SideBar.prototype._next_index= function ()
{	
	if(this.currentIndex==this._list.length-1)
	{	
		this.currentIndex = this.currentIndex-1;
		this.dir = 1;
	}
	else if(this.currentIndex==0)
	{
		this.currentIndex = this.currentIndex+1;
		this.dir = 0;
	}
	else
	{
		if(this.dir==0)
		    this.currentIndex++;
		else
		    this.currentIndex--;
	}
}

SideBar.prototype.Scroll = function ()
{
	this._start_margin();
	this.Start();
}

SideBar.prototype.ScrollTo = function (page)
{
	window.clearTimeout(this.timeID);
	if(page == this.currentIndex) return ;

	if(page > this.currentIndex)
	{
		this.dir = 0;
		this.currentIndex = page-1;
	}
	else
	{
		this.dir = 1;
		this.currentIndex = page;
	}
	var temp = this;	
	temp._next_index();
	this._start_margin();
	this.timeID = setTimeout(function (){temp.Start();})
	
}

SideBar.prototype._get_margin = function ()
{
	var temp = -(this.currentIndex * this.height);
	return temp;
}


SideBar.prototype._start_margin = function ()
{
	if(this.dir == 0&&this._get_margin() >= parseInt(this._list[0].ele.style.marginTop))
	{
		window.clearTimeout(this.subtimeID);
		return;
	}
	else if(this.dir == 1&&this._get_margin() <= parseInt(this._list[0].ele.style.marginTop))
	{

		window.clearTimeout(this.subtimeID);
		return;
	}
	if(this.dir==0)
	{	
		
		this._list[0].ele.style.marginTop = (parseInt(this._list[0].ele.style.marginTop) - 10)+"px";
	}
	else
	{
		this._list[0].ele.style.marginTop = (parseInt(this._list[0].ele.style.marginTop) + 10 )+"px";
	}
	var temp2 = this;
	this.subtimeID = setTimeout(function (){temp2._start_margin();},100);
}


SideBar.prototype.Start = function ()
{
	var temp = this;
	if(this.timeID!=-100)
	{
		this.timeID = setTimeout(function (){
		temp._next_index();
		temp.Scroll();
			},this.Interal);
	}
}

SideBar.prototype.Stop = function ()
{
	window.clearTimeout(this.timeID);
	this.timeID = -100;
}
function $(name)
{
	return document.getElementById(name);
}

