var classSwitcher = Class.create();
classSwitcher.prototype = {
	
	initialize : function (elems) {
		this.options = elems;
		this.writeEvents();
	},
	writeEvents : function () {
		for( i=0; i<this.options.length; i++ ) {
			for( k=0; k<this.options[i].length; k++ ) {
				this.options[i][k].myClass = this;
				this.options[i][k].observe('mouseover', this.over);				
				this.options[i][k].observe('mouseout', this.out);				
			}
		}
	},
	over : function () {
		this.addClassName('myover');
		clearInterval(this.hide);
	},
	out : function () {
		this.hide = setInterval(this.myClass.removeClass.bind(this),200);
	},	
	removeClass : function() {
		this.removeClassName("myover");	
	}
}

/* Europe List
------------------------------------------------------------------------------------------------ */

var linkClassSwitcher = Class.create();
linkClassSwitcher.prototype = {
	
	initialize : function (elems) {
		this.options = elems;
		this.active = 0;
		this.writeEvents();
	},
	writeEvents : function () {
		for( i=0; i<this.options.length; i++ ) {
			for( k=0; k<this.options[i].length; k++ ) {
				this.options[i][k].myClass = this;
				this.options[i][k].observe('mouseover', this.over.bind(this));				
				this.options[i][k].observe('mouseout', this.out.bind(this));				
			}
		}
		try {
			this.options[0][0].parentNode.observe('mouseover', this.overAll.bind(this));
			this.options[0][0].parentNode.observe('mouseout', this.removeAll.bind(this));
		}
		catch (e) {
		}
	},
	over : function (elem) {
		
		var myelement = elem.element();
		
		if (myelement.tagName == "LI") {
			var id = myelement.id.replace("linklist_","");
		}
		else if (myelement.tagName == "A") {
			var id = myelement.parentNode.id.replace("linklist_","");
		}
		else {
			var id = 0
		}
		
		this.active = id;
		this.setClasses();

		clearInterval(this.hide);
		clearInterval(this.hideall);
	},
	out : function (elem) {
			
		var myelement = elem.element();
		
		if (myelement.tagName == "LI") {
			var id = myelement.id.replace("linklist_","");
		}
		else if (myelement.tagName == "A") {
			var id = myelement.parentNode.id.replace("linklist_","");
		}
		else {
			var id = 1;
		}
		this.active = id - 1;
		this.hide = setInterval(this.setClasses.bind(this),200);
		
	},
	
	removeClass : function(id) {
		this.active(id - 1);
		
		
		clearInterval(this.hideall);
	},
	overAll : function () {
		try {
			clearInterval(this.hideall);
		}
		catch (e) { }
	},	
	removeAll : function () {
		this.active = 0;
		this.hideall = setInterval(this.setClasses.bind(this),400);
	},
	setClasses : function () {
		var active = this.active;
		var slide = true;
		if ((active > 0) && (active <= 3)) {
			active = 3;
		}
		else if (active > 3) {
			slide = false;
		}
		
		for( var i=0 ; i < this.options.length ; i++ ) {
			for( k=0; k<this.options[i].length; k++ ) {
				if (slide) {
					if (k < active) {
						this.options[i][k].addClassName('myover');
					}
					else {
						this.options[i][k].removeClassName("myover");	
					}
				}
				else {
					if ((k+1) == active) {
						this.options[i][k].addClassName('myover');
					}
					else {
						this.options[i][k].removeClassName("myover");	
					}
				}
			}
		}
	}
}

/* Standard List
------------------------------------------------------------------------------------------------ */
var listClassSwitcher = Class.create();
listClassSwitcher.prototype = {
	
	initialize : function (elems) {
		this.options = elems;
		this.writeEvents();
	},
	writeEvents : function () {
		for( i=0; i<this.options.length; i++ ) {
			for( k=0; k<this.options[i].length; k++ ) {
				this.options[i][k].myClass = this;
				this.options[i][k].observe('mouseover', this.over);				
				this.options[i][k].observe('mouseout', this.out);				
			}
		}
	},
	over : function () {
		this.addClassName('myover');
		clearInterval(this.hide);
	},
	out : function () {
		this.hide = setInterval(this.myClass.removeClass.bind(this),0);
	},	
	removeClass : function() {
		this.removeClassName("myover");	
	}
}

/**
 * Slider fuer Gallery
 */
var pslider = Class.create();
pslider.prototype = {
	initialize : function (params) {
		this.options = params;
		
		this.options.posIndicator = $( this.options.posIndicator );
		this.options.posIndicator.items = this.options.posIndicator.getElementsByTagName('LI');
		this.options.sliderContainer = $( this.options.sliderContainer );
		//this.options.itemWidth = this.options.maxSliderWidth / this.options.posIndicator.items.length;
		this.options.maxSliderWidth = this.options.itemWidth * this.options.posIndicator.items.length;
		// Breite neu setzen
		$(this.options.sliderContainer).setStyle("width:" + this.options.maxSliderWidth + "px");
		this.options.triggerNext = $( this.options.triggerNext );
		this.options.triggerPrev = $( this.options.triggerPrev );
		this.options.tmpPos = 0;
		this.currentPos = 0;
		this.options.slideType = this.options.slideType == 'v' ? 'top' : 'left';
		this.writeEvents();
		
		try {
			if (params.start != undefined) {
				
				if (params.start > -1) {
					this.startDirekt();
				}
				
			}
		} catch (e) {}
		
	},
	writeEvents : function () {
		//Loop through indicators and set events
		for ( i=0; i<this.options.posIndicator.items.length; i++ ) {
			$(this.options.posIndicator.items[i]).observe( 'click', this.slideDirect );
			$(this.options.posIndicator.items[i]).myClass = this;
			$(this.options.posIndicator.items[i]).liID = i;
		}
		//Set the first indicator to active, after initialize
		$(this.options.posIndicator.items[0]).addClassName('active');
		
		//Set events for prev and next buttons
		this.options.triggerPrev.observe( 'click', this.slidePrev );
		this.options.triggerPrev.myClass = this;
		this.options.triggerNext.observe( 'click', this.slideNext );
		this.options.triggerNext.myClass = this;
	},
	startDirekt : function () {
		
		if (this.options.sliderContainer.getStyle( this.options.slideType ) == null) {
			this.currentPos = this.options.start;
		}
		else {
			this.currentPos = parseFloat( this.options.sliderContainer.getStyle( this.options.slideType ) );
		}
		this.options.tmpPos = this.options.start ;
		
		this.targetPos = ( this.options.itemWidth * ( this.options.tmpPos + 1 ) ) *-1;
		if( this.targetPos >= ( this.options.maxSliderWidth * -1 ) + this.options.itemWidth ) {
			
			//Set active indicator
			for( i=0; i<this.options.posIndicator.items.length; i++ ) {
				$( this.options.posIndicator.items[i].removeClassName('active') );
			}
			$( this.options.posIndicator.items[this.options.tmpPos+1].addClassName('active') );
			//Start sliding-animation
			if( this.currentPos != this.targetPos ) {
				
				ex0 = new Animator({ transition: Animator.easeInOut, interval: 20, duration: 400 });
				ex0.addSubject( new NumericalStyleSubject( this.options.sliderContainer, this.options.slideType, String( this.currentPos ) + 'px', String( this.targetPos ) + 'px' ) );
				ex0.play();
			}
		}
		
	},
	slideDirect : function () {
		//Make indicator highlighting
		for ( i=0; i<this.myClass.options.posIndicator.items.length; i++ ) {
			this.myClass.options.posIndicator.items[i].removeClassName('active');
		}
		this.addClassName('active'); 
		//Calculate start- and endpositions to slide to
		if (this.myClass.options.sliderContainer.getStyle( this.myClass.options.slideType ) == null) {
			this.currentPos = 0;
		}
		else {
			this.currentPos = parseFloat( this.myClass.options.sliderContainer.getStyle( this.myClass.options.slideType ) );
		}
		this.targetPos = ( this.myClass.options.itemWidth * this.liID ) *-1;
		this.myClass.options.tmpPos = this.liID;
		
		//Start sliding-animation
		if( this.currentPos != this.targetPos ) {
			ex0 = new Animator({ transition: Animator.easeInOut, interval: 20, duration: 400 });
			ex0.addSubject( new NumericalStyleSubject( this.myClass.options.sliderContainer, this.myClass.options.slideType, String( this.currentPos ) + 'px', String( this.targetPos ) + 'px' ) );
			ex0.play();
		}
	},
	slideNext : function () {
		//Calculate start- and endpositions to slide to
		if (this.myClass.options.sliderContainer.getStyle( this.myClass.options.slideType ) == null) {
			this.currentPos = 0;
		}
		else {
			this.currentPos = parseFloat( this.myClass.options.sliderContainer.getStyle( this.myClass.options.slideType ) );
		}
		this.targetPos = ( this.myClass.options.itemWidth * ( this.myClass.options.tmpPos + 1 ) ) *-1;
		if( this.targetPos >= ( this.myClass.options.maxSliderWidth * -1 ) + this.myClass.options.itemWidth ) {
			this.myClass.options.tmpPos += 1;
			
			//Set active indicator
			for( i=0; i<this.myClass.options.posIndicator.items.length; i++ ) {
				$( this.myClass.options.posIndicator.items[i].removeClassName('active') );
			}
			$( this.myClass.options.posIndicator.items[this.myClass.options.tmpPos].addClassName('active') );
			//Start sliding-animation
			if( this.currentPos != this.targetPos ) {
				ex0 = new Animator({ transition: Animator.easeInOut, interval: 20, duration: 400 });
				ex0.addSubject( new NumericalStyleSubject( this.myClass.options.sliderContainer, this.myClass.options.slideType, String( this.currentPos ) + 'px', String( this.targetPos ) + 'px' ) );
				ex0.play();
			}
		}
	},
	slidePrev : function () {
		//Calculate start- and endpositions to slide to
		this.currentPos = parseFloat( this.myClass.options.sliderContainer.getStyle( this.myClass.options.slideType ) );
		this.targetPos = ( this.currentPos + this.myClass.options.itemWidth );
		if( this.targetPos < this.myClass.options.itemWidth ) {
			this.myClass.options.tmpPos -= 1;
			//Set active indicator
			for( i=0; i<this.myClass.options.posIndicator.items.length; i++ ) {
				$( this.myClass.options.posIndicator.items[i].removeClassName('active') );
			}
			$( this.myClass.options.posIndicator.items[this.myClass.options.tmpPos].addClassName('active') );
			//Start sliding-animation
			if( this.currentPos != this.targetPos ) {
				ex0 = new Animator({ transition: Animator.easeInOut, interval: 20, duration: 400 });
				ex0.addSubject( new NumericalStyleSubject( this.myClass.options.sliderContainer, this.myClass.options.slideType, String( this.currentPos ) + 'px', String( this.targetPos ) + 'px' ) );
				ex0.play();
			}
		}
	}
}