var FrontpageSlider = new Class({
	Implements: [Options, Events],
	options: {
		actualItem: 0
	},
	
	initialize: function(options) {
	this.tips = new Tips('.slider-button', {
		'className': 'slideshow-tips',
		'text': 'rel',
		'fixed': true,
		'offset': {'x': -290, 'y': -2}
	});
	this.tips.addEvent('show', function(tip, el){
    	tip.fade(0.8);
	});
	this.tips.addEvent('hide', function(tip, el){
    	tip.fade(0);
	});
	$('slideshow-frontpage-images').fade('hide');
	$('slideshow-frontpage-toggler').fade('hide');
	this.setOptions(options);
	var me = this;
	this.picSlider = new Fx.Tween($('slideshow-frontpage-images'), {
		'transition': Fx.Transitions.Quad.easeInOut,
		'duration': 500
	});
	this.sliderImages = ['images/slideshow_frontpage_img1.jpg', 'images/slideshow_frontpage_img2.jpg', 'images/slideshow_frontpage_img3.jpg', 'images/slideshow_frontpage_img4.jpg'];
	this.imgElements = new Asset.images(this.sliderImages, {	
		onComplete: function(){
			$('slideshow-frontpage-toggler').fade('show');
			$('slideshow-frontpage-toggler').getElements('li').each(function(item, index){
				item.internalIndex = index;
				var darkener = new Element('span');
				item.darkener = darkener;
				if (me.options.actualItem == index) {
					darkener.setStyle('opacity', 0);
					item.morph('.li-button.active');
				} else {
					darkener.setStyle('opacity', 0.4);
				}
				
				darkener.inject(item.getElement('a'), 'bottom');
			});
	        me.imgElements.each(function(item){
	        	var li = new Element('li');
	        	item.inject(li);
	        	li.inject($('slideshow-frontpage-images'), 'bottom');
	        });
	        $('slideshow-frontpage-images').fade('hide');
	        $('slideshow-frontpage-images').fade('in');
	        
	        $('ziplines').addEvents({
	        	'click': 	function(ev) {
	        		if (me.options.actualItem != this.getParent().internalIndex) {
	        			me.slide(this.getParent().internalIndex);
	        		}
	        					
	        					ev.stop();
	        				},
	        	'mouseout':	function(ev) {
	        		
	        		if (this.getParent().internalIndex != me.options.actualItem) {
	        			this.getChildren('span').fade(0.4);
	        			this.getParent().morph('.li-button');
	        		}
	        		
	        		},
	        	'mouseover': function(ev) {
	        		this.getParent().morph('.li-button.active');
	        		this.getChildren('span').fade(0);
	        	}
	        });
	        $('screamer').addEvents({
	        	'click': 	function(ev) {
	        		if (me.options.actualItem != this.getParent().internalIndex) {
	        			me.slide(this.getParent().internalIndex);
	        		}
	        					ev.stop();
	        				},
	        	'mouseout':	function(ev) {
	        		
	        		if (this.getParent().internalIndex != me.options.actualItem) {
	        			this.getChildren('span').fade(0.4);
	        			this.getParent().morph('.li-button');
	        		}
	        		
	        		},
	        	'mouseover': function(ev) {
	        		this.getParent().morph('.li-button.active');
	        		this.getChildren('span').fade(0);
	        	}
	        });
	        $('paintsplat').addEvents({
	        	'click': 	function(ev) {
	        		if (me.options.actualItem != this.getParent().internalIndex) {
	        			me.slide(this.getParent().internalIndex);
	        		}
	        					ev.stop();
	        				},
	        	'mouseout':	function(ev) {
	        		
	        		if (this.getParent().internalIndex != me.options.actualItem) {
	        			this.getChildren('span').fade(0.4);
	        			this.getParent().morph('.li-button');
	        		}
	        		
	        		},
	        	'mouseover': function(ev) {
	        		this.getParent().morph('.li-button.active');
	        		this.getChildren('span').fade(0);
	        	}
	        });
	        $('atv').addEvents({
	        	'click': 	function(ev) {
	        		if (me.options.actualItem != this.getParent().internalIndex) {
	        			me.slide(this.getParent().internalIndex);
	        		}
	        					ev.stop();
	        				},
	        	'mouseout':	function(ev) {
	        		
	        		if (this.getParent().internalIndex != me.options.actualItem) {
	        			this.getChildren('span').fade(0.4);
	        			this.getParent().morph('.li-button');
	        		}
	        		
	        		},
	        	'mouseover': function(ev) {
	        		this.getParent().morph('.li-button.active');
	        		this.getChildren('span').fade(0);
	        	}
	        });
	    }
	});
	
	},
	
	slide: function(pos) {
	var me = this;
	$('slideshow-frontpage-toggler').getElements('li').each(function(item, index){
		if (item.internalIndex == me.options.actualItem) {
			item.darkener.fade(0.4);
			item.morph('.li-button');
		}
	});
	this.picSlider.cancel();
	this.picSlider.start('left', -(724 * pos) + 0 + 'px' );
	me.options.actualItem = pos;
	}

	
});



window.addEvent('domready', function() {
	var fps = new FrontpageSlider();
});