var Carousel = Class.create();
Carousel.prototype = {
	initialize : function( container, options ) {
		this.options = Object.extend({
			delay: 0.01,
			offSetX: 1
        },options || {});
		
		this.moving = true;
		this.mousein = false;
		this.container = $(container);
		this.posCount = 0;
		this.cList = $(container).down('ul');
		this.cList.style.left = '0pt';
		
		$(container).observe('mouseover', this.mouseon.bindAsEventListener(this), false );
		$(container).observe('mouseout', this.mouseoff.bindAsEventListener(this), false );
		
		this.current = 0;
//		Event.observe(window, 'load', function() {
			this.timeout = new PeriodicalExecuter( this.circulate.bind(this), this.options.delay );
//		}, false);	
	},
	mouseon : function()
	{
		this.mousein = true;
	},
	mouseoff : function()
	{
		this.mousein = false;
	},
	circulate : function( pe )
	{		
		if(!this.moving || this.mousein) {return;}
		
		var l = parseInt( this.cList.style.left.replace('px', '') ) * -1;
		// console.log(l);
		if(l >= this.cList.firstDescendant().getWidth())
		{
			var li = this.cList.firstDescendant();
			li.remove();
			this.cList.insert(li);
			this.options.offSetX = 1;
			this.cList.style.left = '0pt';
		}
		else
		{
			this.options.offSetX += 1;
			this.cList.style.left = -this.options.offSetX + "px";
		}
	},
	stop : function()
	{
		this.moving = false;
	},
	start : function()
	{
		this.moving = true;
	}
}
