function correctIeOpacity(elem) {
	/*
	 * Copied from Prototype.js (http://www.prototypejs.org/) 
	 */
	function stripAlpha(filter) {
		return filter.replace(/alpha\([^\)]*\)/gi,'');
	}
 
	//remove filter if this is an IE-Browser and filter is empty anyway
	if (Browser.Engine.trident) {
		var filter = stripAlpha(elem.getStyle('filter'));
		if (!filter) elem.style.removeAttribute('filter', false);
	}
}

var ddSlider = new Class({
	
	initialize: function(sliderId) {

		
		this.slider = $(sliderId);
		this.sliderId = sliderId;
		this.slideActive = true;
		this.slideInProgress = false;

		/* fetch elements */
		this.elements = $$('#' + this.sliderId + ' div.sliderElement');
		this.links = $$('#' + this.sliderId + ' h2');
		/* first element is active element */
		this.activeElement = this.elements[0];
		this.activeIndex = 0;
		
		/* first hide all except first element */
		/*for (c=0; c<this.elements.length; c++) {
			if (c) {
				this.elements[c].fade('hide');
			}
		}*/
		/* first hide all except last element */
		var lastPos = this.elements.length-1;
		this.activeElement = this.elements[lastPos];
		this.activeIndex = lastPos;
		for (c=0; c<lastPos; c++) {
			this.elements[c].fade('hide');
		}
		
		/* click actions */
		for (c=0; c<this.links.length; c++) {
			this.links[c].addEvent('click', function() {
				this.slideActive = false;
				
				this.select(arguments[0]);
			}.bind(this, c));
		}
		if (this.elements.length>1) {
			this.slideInterval = this.slide.periodical(8000, this);
		}
		
		
	},
	
	select: function(index) {
		if (!this.slideInProgress && index != this.activeIndex) {
			this.slideInProgress = true;
			this.activeIndex = index;
			var fadeOut = new Fx.Tween(this.activeElement, 
				{
					duration: 500,
					property: 'opacity'
				}).start(0);
			fadeOut.addEvent('complete',  function() {
				this.slideInProgress = false;
			}.bind(this));	
						
			this.activeIndex = index;
			this.activeElement = this.elements[this.activeIndex];
			var fadeIn = new Fx.Tween(this.activeElement, 
				{
					duration: 500,
					property: 'opacity'
				}).start(1);
			fadeIn.addEvent('complete',  function() {
				this.slideInProgress = false;
			}.bind(this));							
		}
			
	},
	
	slide: function() {
		if (this.slideActive) {
			var fadeOut = new Fx.Tween(this.activeElement, 
				{
					duration: 1000,
					property: 'opacity'
				}).start(0);

			
			this.activeIndex = ((this.activeIndex+1)==this.elements.length)?0:(this.activeIndex+1);
			this.activeElement = this.elements[this.activeIndex];
			var fadeIn = new Fx.Tween(this.activeElement, 
				{
					duration: 2000,
					property: 'opacity'
				}).start(1);
		}	
	}
	
	
});

window.addEvent('domready', initSlider);
function initSlider() {
	homeSlider = new ddSlider('slider');
	
}

