var HeaderSlider = new Class({
	initialize: function(el,options){
		this.speed = options.speed?options.speed: 1000;
		this.duration = options.duration?options.duration: 6000;
		
		//Get Elements
		this.el = el;
		this.items = this.el.getElements('img');
		this.cur = this.items.length -1;
		this.next = 0;
		
		for(i = 0;i < this.items.length-1;i++){
			this.items[i].setStyles({
				'display':'none',
				'opacity':0,
				'z-index':0
			});
		}
		
		if(this.items.length>1){
			this.intervalID = this.slide.periodical(this.duration,this);
		}
	},
	
	slide: function() {
		fxNext = new Fx.Morph(
			this.items[this.next], 
			{
				duration:this.speed,
				onStart:function(){
					this.items[this.next].setStyles({
						'display':'block',
						'z-index':10
					});
					this.items[this.cur].setStyles({
						'z-index':0
					});
				}.bind(this),
				onComplete:function() {
					this.items[this.cur].setStyles({
						'display':'none',
						'opacity':0
					});
					
					this.cur = (this.cur+1 < this.items.length)?this.cur+1:0;
					this.next = (this.next+1 < this.items.length)?this.next+1:0;
				}.bind(this)
			});
		
		fxNext.start({
			'opacity': 1
		});		
	}
		
});

window.addEvent('domready', function(){
	headerSlider = new HeaderSlider($('visual'),{speed:2000,duration: 6000});
});