
// Klasse fuer Slidebox (Portal)
var slideBox = Class.create();
slideBox.prototype = {

	initialize : function (element)
	{
		this.slidebox = element;
		this.top = this.slidebox.getElementsByClassName('top')[0];
		this.bottom = this.slidebox.getElementsByClassName('bottom')[0];
		
		this.statusOpen = true;
		
		this.top.observe('mouseover', this.slidedown);
		this.top.myClass = this;
		
		this.bottom.observe('mouseover', this.slideup);
		this.bottom.myClass = this;
		
	},
	
	setTop : function ()
	{
		this.top.observe('mouseover', this.slidedown);
	},
	
	setBottom : function ()
	{
		this.bottom.observe('mouseover', this.slideup);
	},
	
	
	slidedown : function ()
	{
		if(this.myClass.statusOpen == false)
		{
			
			this.myClass.top.stopObserving('mouseover', this.slidedown);
			this.myClass.bottom.stopObserving('mouseover', this.slideup);
			
			ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000, onComplete: this.myClass.setBottom.bind(this.myClass)});
			ex1.addSubject(new NumericalStyleSubject(this.myClass.top, 'height', 55, 140));
			ex1.play();
			this.myClass.statusOpen = true;
		}
		
	},
	
	slideup : function ()
	{
		if(this.myClass.statusOpen == true)
		{
			this.myClass.top.stopObserving('mouseover', this.slidedown);
			this.myClass.bottom.stopObserving('mouseover', this.slideup);
			
			ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000,onComplete: this.myClass.setTop.bind(this.myClass)});
			ex1.addSubject(new NumericalStyleSubject(this.myClass.top, 'height', 140, 55));
			ex1.play();
			this.myClass.statusOpen = false;
		}
	}
}




/* Klasse fuer Slidefunktion Sprachauswahl */

var langSelectInterval = null;
var langSelect = Class.create();
langSelect.prototype = {
	
	initialize : function (element)
	{
		$('langSelect').active = false;
		$('langSelect').myClass = this; 
		
		$('langSelect').onmouseover = function ()
		{
			document.getElementById('langSelect').className = "langSelectHover";
			clearInterval(langSelectInterval);
			 
			if(this.active == false)
			{
				ex = new Animator({transition: Animator.makeEaseOut(3),duration: 1000});
				ex.addSubject(new NumericalStyleSubject($('langChoose'), 'width', 0, 635));
				ex.play();
			}
			this.active = true;
		}
		
		$('langSelect').onmouseout = function ()
		{
			document.getElementById('langSelect').className = "";
			if(this.active == true)
			{
				langSelectInterval = window.setInterval("closeLangSelect()",1000);
			}
		}
		
		$('langChooseContainer').onmouseover = function ()
		{
			clearInterval(langSelectInterval);
		}
		
		$('langChooseContainer').onmouseout = function ()
		{
			langSelectInterval = window.setInterval("closeLangSelect()",1000);
		}
	}
}

function closeLangSelect ()
{
	$('langSelect').active = false;
	ex = new Animator({transition: Animator.makeEaseOut(3),duration: 1000});
	ex.addSubject(new NumericalStyleSubject($('langChoose'), 'width', 635, 0));
	ex.play();
	clearInterval(langSelectInterval);
}


// Klassen Switcher fuer Topnavigation
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('sfhover');
		clearInterval(this.hide);
	},
	
	out : function ()
	{
		this.hide = setInterval(this.myClass.removeClass.bind(this),50);
	},
	
	removeClass : function()
	{
		if(this.className.indexOf("sfhover") >= 0)
		{
			this.removeClassName("sfhover");
		}
	}
}


//Bildswitcher fuer Topnavigation (Hauptpunkte)
var classPicSwitcher = Class.create();
classPicSwitcher.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].observe('mouseover', this.rollover);
				this.options[i][k].observe('mouseout', this.rollout);
			}
		}
	},

	rollover : function ()
	{
		this.imgSrc = this.getElementsByTagName('img')[0].getAttribute('src');

		myregexp = new RegExp("http://" + window.location.hostname, "i");
		this.imgSrc = this.imgSrc.replace(myregexp, '');
		
		this.seperatedSrc = this.imgSrc.split('.');
		this.seperatedSrc[0] = this.seperatedSrc[0] + '_active';
		this.output = this.seperatedSrc[0] + '.' + this.seperatedSrc[1];
		this.getElementsByTagName('img')[0].src = this.output;
		
	
	},
	
	rollout : function ()
	{
		this.imgSrc = this.getElementsByTagName('img')[0].getAttribute('src');
		
		myregexp = new RegExp("http://" + window.location.hostname, "i");
		this.imgSrc = this.imgSrc.replace(myregexp, '');
		
		this.seperatedSrc = this.imgSrc.split('.');
		this.seperatedSrc[0] = this.seperatedSrc[0].replace(new RegExp("_active\\b"), "")
		this.output = this.seperatedSrc[0] + '.' + this.seperatedSrc[1]
		this.getElementsByTagName('img')[0].src = this.output;
	}
}




// Slider fuer Hotelkategorien ECHT
var catSlider = Class.create();
catSlider.prototype = {

	initialize : function (elems)
	{
		this.container = elems;
		this.actualOpen = 0;
		this.writeEvents();

	},
	
	writeEvents : function ()
	{		
		for( i=0; i<this.container.length; i++ )
		{
			this.container[i].observe('click', this.press);
			this.container[i].myClass = this;
			this.container[i].myID = i;
		
			this.container[i].contentHeight = this.container[i].getHeight();
			this.container[i].icon = this.container[i].getElementsByClassName('status')[0];

			if(i != 0)
			{
				this.container[i].statusOpen = false;
				this.container[i].icon.className = 'status';
				this.container[i].setStyle({height: '52px'})
			}
			else
			{
				this.container[i].statusOpen = true;
				this.container[i].icon.className = 'status open';
			}
		}
	},
	

	press : function ()
	{
		if(this.myClass.container[this.myID].statusOpen == false)
		{
			this.myClass.slide(this.myID);
		}
	},
	
	
	slide : function (id)
	{		
		this.newID = id;		
		
		this.container[this.newID].icon.className = 'status open';
		this.container[this.actualOpen].icon.className = 'status';
		
	
		//Alten Container zusliden
		ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000});
		ex1.addSubject(new NumericalStyleSubject($(this.container[this.actualOpen]), 'height', this.container[this.actualOpen].contentHeight, 52));
		ex1.play();
		
		//Neuen Container aufsliden
		ex2 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000});
		ex2.addSubject(new NumericalStyleSubject($(this.container[this.newID]), 'height', 52, this.container[this.newID].contentHeight));
		ex2.play();
						
		this.container[this.actualOpen].statusOpen = false;
		this.container[this.newID].statusOpen = true;
		this.actualOpen = this.newID;
	}
	

}




// Slider fuer Angebote
var offerSlider = Class.create();
offerSlider.prototype = {
	initialize : function (elems) {
		
		this.container = elems;
		this.actualOpen = null;
		this.writeEvents();
	},
	writeEvents : function () {
		
		for( i=0; i<this.container.length; i++ )
		{
			this.container[i].head = this.container[i].getElementsByClassName('head')[0];
			this.container[i].head.observe('click', this.press);
			this.container[i].head.myClass = this;
			this.container[i].head.myID = i;
		
			this.container[i].contentHeight = this.container[i].getElementsByClassName('detail')[0].getHeight() + 33;
			this.container[i].statusOpen = false;
			this.container[i].setStyle({height: '33px'});
			
			if(this.container[i].getAttribute("lang") == "open") {
				window.setTimeout(this.press.bind(this.container[i].head),1);
			}
		}
	},
	press : function () {
		if(this.myClass.container[this.myID].statusOpen == false) {
			if(this.myClass.actualOpen == null) {
				this.myClass.openSingle(this.myID);
			}
			else {
				this.myClass.openCloseMulti(this.myID);	
			}
		}
		else {
			this.myClass.closeSingle(this.myID);
		}
		
	},
	openSingle : function (id)
	{
		ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000,onComplete: function() {
                                   
		}});
		ex1.addSubject(new NumericalStyleSubject($(this.container[id]), 'height', 33, this.container[id].contentHeight));
		ex1.play();
		this.container[id].statusOpen = true;
		this.container[id].head.className = 'head open';
		this.actualOpen = id;
	},
	closeSingle : function (id)
	{
	
		ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000,onComplete: function() {
                                   
		}});
		ex1.addSubject(new NumericalStyleSubject($(this.container[id]), 'height', this.container[id].contentHeight, 33));
		ex1.play();
		this.container[id].statusOpen = false;
		this.container[id].head.className = 'head';
		this.actualOpen = null;
	},
	openCloseMulti : function (id)
	{
		this.tmpID = id;
		ex1 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000,onComplete: this.openNew.bind(this)});
		ex1.addSubject(new NumericalStyleSubject($(this.container[this.actualOpen]), 'height', this.container[this.actualOpen].contentHeight, 33));
		ex1.play();
		this.container[this.actualOpen].statusOpen = false;
		this.container[this.actualOpen].head.className = 'head';
	},
	
	openNew : function ()
	{
		ex2 = new Animator({transition: Animator.makeEaseIn(2),duration: 1000,onComplete: function() {}});
		ex2.addSubject(new NumericalStyleSubject($(this.container[this.tmpID]), 'height', 33, this.container[this.tmpID].contentHeight ));
		ex2.play();
		this.container[this.tmpID].statusOpen = true;
		this.container[this.tmpID].head.className = 'head open';
		this.actualOpen = this.tmpID;
		
		this.tmpID = null;
	}
}



var dropDown = Class.create();
dropDown.prototype = {

	initialize : function (elem)
	{
		this.dropdown = elem;
		
		this.button = this.dropdown.getElementsByClassName('selectbutton')[0];
		this.optionBox = this.dropdown.getElementsByClassName('options')[0];
		
		this.myInterval = null;
		this.writeEvents();
	},
	
	writeEvents : function ()
	{

		this.button.observe('click', this.openOptions.bind(this));
	},
	
	openOptions : function ()
	{
		this.optionBox.style.display = 'block';
		this.optionBox.onmouseover = this.setMouse.bind(this);
	},
	
	setMouse : function ()
	{
		this.optionBox.onmouseout = this.intervalClose.bind(this);
		if(this.myInterval != null)
		{
			this.clearInterval(); 
		}
		
	},
	
	intervalClose : function ()
	{
		this.myInterval = window.setInterval(this.closeOptions.bind(this), 1000);
	},
	
	closeOptions : function ()
	{
		this.optionBox.style.display = 'none';
		this.clearInterval(); 
	},
	
	clearInterval : function ()
	{
		clearInterval(this.myInterval);
		this.myInterval = null;
	}

}

// Klasse fuer Slider Angebots detailseite
var packageBoxSlide = Class.create();
packageBoxSlide.prototype = {

	initialize : function (element)
	{
		this.slider = element;
		this.slideLeft = this.slider.getElementsByClassName('pd_slide_left')[0];
		this.slideRight = this.slider.getElementsByClassName('pd_slide_right')[0];
		
		if(this.slideLeft && this.slideRight)
		{		
			this.slideLeft.observe('click', this.left);	
			this.slideLeft.observe('mouseover', this.mouseover);
			this.slideLeft.observe('mouseout', this.mouseout);	

			this.slideRight.observe('click', this.right);
			this.slideRight.observe('mouseover', this.mouseover);
			this.slideRight.observe('mouseout', this.mouseout);	
			
			this.slideLeft.myClass = this;	
			this.slideRight.myClass = this;
			
			//this.itemWidth = this.slider.getElementsByClassName('webcam_thumb')[0].getWidth();
			this.itemWidth = 233;
			this.actualPos = 0;
	
			this.sliderContainer = this.slider.getElementsByClassName('pd_slider')[0];
			
			this.entries = this.slider.getElementsByClassName('pds_entry');
		}
		
	},
	
	mouseover : function ()
	{
		//this.addClassName('hoverButton');
	},
	
	mouseout : function ()
	{
		/*if(this.className.indexOf("hoverButton") >= 0)
		{
			this.removeClassName("hoverButton");
		}*/
	},
	

	left : function ()
	{
		if(this.myClass.actualPos > 0)
		{
			
			this.myClass.slide(this.myClass.actualPos-1);
		}
	},
	
	right : function ()
	{
		if(this.myClass.actualPos < this.myClass.entries.length - 2)
		{
			
			this.myClass.slide(this.myClass.actualPos+1);
		}
	},
	
	slide : function (targetPos)
	{
		
		var currentPos = this.actualPos * (this.itemWidth * -1);
		var newSliderPos = targetPos * (this.itemWidth * -1);
		
		ex0 = new Animator({ transition: Animator.makeEaseOut(4),duration: 500});
		ex0.addSubject(new NumericalStyleSubject(this.sliderContainer,'left', String( currentPos ) + 'px', String( newSliderPos ) + 'px' ) );
		ex0.play();
		
		this.actualPos = targetPos;
	}
}


