var slider = new Class({
	Implements: Options
	,options: {
		images: false
		,img: false
		,current: false
		,interval: 5000
		,periodical: false
	}
	,initialize: function(options)
	{
		this.setOptions(options);
		
		// Attach click event
		options.images.addEvent('click', this.select.bind(this));
		
		// Automate the slider
		this.startAutomate.delay(this.options.interval, this);
	}
	,select: function(e)
	{
		// Stop the event
		var e = new Event(e);
		e.stop();
		
		// Stop interval
		$clear(this.options.periodical);
		this.options.periodical = this.startAutomate.delay(this.options.interval, this);
		
		// Change
		this.change(e.target);
	}
	,startAutomate: function()
	{
		this.options.periodical = this.automate.periodical(this.options.interval, this);
	}
	,automate: function()
	{
		var getNext = false;
		var nextEl = false;
		
		// Is last?
		if(this.options.current == this.options.images[this.options.images.length-1])
		{
			nextEl = this.options.images[0];
		}
		else
		{
			this.options.images.each(function(el) {
				if(getNext == true)
				{
					nextEl = el;
					getNext = false;
				}
				if(el.href == this.options.current.href)
				{
					getNext = true;
				}
			}.bind(this));
		}
		
		// Change
		if(nextEl != false) this.change(nextEl);
	}
	,change: function(el)
	{
		// Remove active class from current
		this.options.current.removeClass('active');
		
		// Create new element
		var newEl = new Element('img', {
			src: el.href
			,alt: ''
			,width: this.options.img.getWidth()
			,height: this.options.img.getHeight()
		});
		newEl.setStyles({
			'visibility': 'hidden'
			,'opactiy': 0
		});
		newEl.inject(this.options.img.getParent());
		
		// Fade in
		//new Fx.Tween(newEl,{duraction: 'long'}).start('visibility', 'hidden', 'visibile');
		new Fx.Tween(newEl,{duraction: 'long'}).start('opacity', 0, 1).addEvent('complete', function() {
			// Destroy current
			this.options.img.destroy();
			this.options.img = newEl;
		}.bind(this));
		
		// Get url of image
		
		
		// Set current active
		this.options.current = el;
		this.options.current.addClass('active');
	}
});
//
var a;
$(document).addEvent('domready', function() {
	a = new slider({
		images: $$('div.controls ul li a')
		,img: $$('div.image img')[0]
		,current: $$('div.controls ul li a.active')[0]
		,interval: 4000
	});
});