/**
 * Slider
 * @author berge
 */

/**
 * Class Slider
 * @class Twitter
 */
NZO.Slider = Class.extend(
{
	/**
	 * Time between each slide
	 * @type int
	 */
	autoSlideTime : 5000,
	
	/**
	 * Current Slide
	 * @type int
	 */
	currentSlide : 0,
	
	/**
	 * AutoSlide running
	 * @type boolean
	 */
	autoSlideOn : true,
	
	/**
	 * Constructor
	 */
	init : function()
	{
		var indicators = $('#indicators');
		indicators.css("margin-left", (644 - indicators.find("li").length * indicators.find("li").outerWidth(true)) / 2 );
		
		for(var i=0,il=$('#indicators li a').length; i < il; i++)
		{
			$('#indicators li a').eq(i).bind("click", {id: i}, $.proxy(function(e){this.gotoSlide(e.data.id); return false;}, this));
		}
		
		setInterval($.proxy(this.autoSlideTick, this), this.autoSlideTime);
		$('#slider, #indicators').hover($.proxy(function(){this.autoSlideOn = false;}, this), $.proxy(function(){this.autoSlideOn = true;}, this));
		
		this.gotoSlide(0);
	},
	
	/**
	 * Go to a slide
	 * @param {int} slide Slide
	 */
	gotoSlide : function(slide)
	{
		this.currentSlide = slide;
		
		$('#indicators li a').removeClass("active");
		$('#indicators li a').eq(slide).addClass("active");
		
		$('#slider').animate({left: -slide * $('#slider li').outerWidth(true) }, 500);
	},
	
	/**
	 * Call with interval
	 */
	autoSlideTick : function()
	{
		if(this.autoSlideOn)
		{
			if($('#slider li').length > this.currentSlide + 1)
			{
				this.gotoSlide(this.currentSlide + 1);
			}
			else
			{
				this.gotoSlide(0);	
			}
		}
	}
});
