/**
* Horizontal News Ticker - August 2010
* Author: Adam Stephenson (adam@beetleblox.com)
* Dependancies: Mootools 1.2 library
*
* Introduction:
* This isn't a conventional scroller whereby the text scrolls in and out. The text will scroll in and stop
* at the beginning of the container. The text therefor must not be longer than the container width.
*
* How to use:
* Just include this script then call the following javascript function
* myHorizontalNewsTicker.start(@myContainerId,@myItems);
*
* @myContainerId => The id of the element that the scrolling content is going to scroll inside. If the container was "<DIV id='myScroller'></DIV>" then the id passed would be 'myScroller'
* @myItems => An array of items that will scroll in turn. eg Array("My scrolling text 1","My scrolling text 2");
**/
var myHorizontalNewsTicker = new function(){
	this.start = function(containerId,items,init){
		if(typeof(init) == "undefined"){
			var c = $(containerId);
			c.myHNTi 	= items;
			c.myHNTic	= 1;
			window.addEvent('domready', function(){
				myHorizontalNewsTicker.start(this.id,"",true);
			}.bind(c));
		} else {
			var c = $(containerId);
			c.setStyles({"overflow":"hidden"});
			if(typeof(c.myHNT) == "undefined"){
				c.myHNT = new Element("div",{"id":containerId+"_i","styles":{"position":"relative"}}).injectInside(c);
				this.next(c.id);
			}
		}
	}
	this.next = function(containerId){
		var c = $(containerId);
		var s = c.getSize();
		c.myHNT.setStyles({"width":s.x,"visibility":"hidden"});
		c.myHNT.set("html",c.myHNTi[(c.myHNTic-1)]);
		c.myHNTic ++;
		c.myHNTic 	= (c.myHNTic>c.myHNTi.length?1:c.myHNTic);
		c.myHNT.setStyles({"visibility":"visible","left":(s.x+10)});
		var f	= new Fx.Morph(c.myHNT, {
			duration	: 4000,
			transition	: Fx.Transitions.Quint.easeInOut,
			onComplete	: function(){
				myHorizontalNewsTicker.next.delay(5000,myHorizontalNewsTicker,this.id);
			}.bind(c)
		});
 		f.start({
			'left'		: [(s.x+10),0]
		});
	}
}
