oldonload_home=window.onload;
window.onload=function()
{
	if(typeof oldonload_home == 'function')
		oldonload_home();
	
	tickertape=new ticker();
}
function ticker()
{
	var ul=document.getElementById('tickertape');
	this.pnode=ul.parentNode;
	var elements=ul.getElementsByTagName('a');
	this.els=[];
	for(var i=0;i<elements.length;i++)
	{
		var op=elements[i].cloneNode(true);
		this.els.push(op);
	}
	this.length=this.els.length;
	
	this.pnode.removeChild(ul);
	this.div=document.createElement('div');
	this.div.style.width=(this.width*2)+'px';
	this.div.style.overflow='hidden';
	if(typeof this.div.style.cssFloat != 'undefined')
		this.div.style.cssFloat='right';
	if(typeof this.div.style.styleFloat != 'undefined')
		this.div.style.styleFloat='right';
	this.div.style.marginTop='-23px';
	this.pnode.appendChild(this.div);
	
	this.init();
}
$pr=ticker.prototype;
$pr.an=null;
$pr.width=220;
$pr.pos=0;

$pr.init=function()
{
	var obj=this;
	var method=this.scrollleft;
	this.timer=setInterval(function(){method.apply(obj)},1600);
}
$pr.scrollleft=function()
{
	this.doscroll(1);
}
$pr.scrollright=function()
{
	this.doscroll(-1);
}
$pr.attachHL=function(div,op)
{
	op=op.cloneNode(true);
	op.style.display='block';
	if(typeof op.style.cssFloat != 'undefined')
		op.style.cssFloat='left';
	if(typeof op.style.styleFloat != 'undefined')
		op.style.styleFloat='left';
	op.style.paddingRight='40px';
//	op.style.width=this.width+'px';
	div.appendChild(op);
	return op;
}
$pr.doscroll=function(dir)
{
	clearInterval(this.timer);
	
	// running the positions
	var a=this.fix(this.pos+1);
	var b=this.fix(this.pos+2);
	var c=this.fix(this.pos+3);
	
	// adding the elements;
	this.div.innerHTML='';
	var indiv=document.createElement('div');
	indiv.style.width=(this.width*8)+'px';
	var first=this.attachHL(indiv,this.els[this.pos]);
	this.attachHL(indiv,this.els[a]);
	this.attachHL(indiv,this.els[b]);
	this.attachHL(indiv,this.els[c]);
	this.div.appendChild(indiv);
	this.div.scrollLeft=0;
	
	// running the positions
	this.pos=this.fix(this.pos+dir);
	
	// creating the animation
//	this.cancelan();
	var begin=this.div.scrollLeft;
	var change=first.offsetWidth*dir;
	var time=50;
	this.an=new phocus.Animator(null,null,begin,change,time,'inOutExpo');
	this.an.register(this,'scrollto');
	this.an.addListener(this,'init');
	this.an.round=true;
	this.an.run();
}
$pr.scrollto=function(y)
{
	this.div.scrollLeft=y;
}
$pr.fix=function(pos)
{
	if(pos>=this.length)
		pos=this.fix(pos%this.length);
	return pos;
//	return pos<=0 ? this.length : (pos>this.length ? 1 : pos)
}
$pr.cancelan=function()
{
	this.an.kill();
}
$pr.toString=function()
{
	return 'SCROLLER: '+this.length+"\r\n"+this.pos;
}
