//Klasse um Menupunkte zu hovern
var classSwitcher = Class.create();
classSwitcher.prototype = {

	initialize : function (elems)
	{
		
		this.naventries = elems;
		
		for( i=0; i<this.naventries.length; i++ )
		{
			for( k=0; k<this.naventries[i].length; k++ )
			{
				this.naventries[i][k].myClass = this;
				this.naventries[i][k].observe('mouseover', this.over);				
				this.naventries[i][k].observe('mouseout', this.out);				
			}
		}
	},

	over : function ()
	{
		this.addClassName('hover');
		clearInterval(this.hide);
	},
	
	out : function ()
	{
		this.hide = setInterval(this.myClass.removeClass.bind(this),20);
	},
	
	removeClass : function()
	{
		if(this.className.indexOf("hover") >= 0)
		{
			this.removeClassName("hover");
		}
	}
}

//Klasse um Portaldropdown
var portalSelection = Class.create();
portalSelection.prototype = {

	initialize : function (selectbox,config)
	{
		this.config = {};
		if(typeof config == "object") {
			this.config = config;
		}
		
		this.selectbox = selectbox;
		
		this.button = this.selectbox.getElementsByClassName('tag_select')[0];
		this.optionBox = this.selectbox.getElementsByClassName('tag_options')[0];

		this.myInterval = null;
		
		this.button.observe('click', this.openOptions.bind(this));
	},

	openOptions : function ()
	{
	
		this.optionBox.style.display = 'block';
		this.optionBox.onmouseover = this.setMouse.bind(this);
		
		if(typeof this.config.onClick == "function") {
			this.config.onClick();
		}
	},
	
	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 um Produkte bei Uebersicht zu switchen
var productSwitch = Class.create();
productSwitch.prototype = {

	initialize : function (element)
	{
		
		this.actualTab = 0;
		this.box = element;
		
		this.butterflyBig = $('butterfly_big');
		this.butterflySmall = $('butterfly_small');
		
		this.tabnavi = this.box.getElementsByClassName('product_select')[0];
		if(!this.tabnavi) {
			return false;
		}
		//this.tabs = this.tabnavi.getElementsByTagName('li');
		this.tabs = this.tabnavi.getElementsByTagName('div');
		
		this.productContents = this.box.getElementsByClassName('product_text_content');
		
		// Alle Tabs auf deaktiviert setzen bis auf den Ersten
		for (var i=0; i<this.tabs.length; i++ )
		{
			$(this.tabs[i]).observe('click', this.press);
			$(this.tabs[i]).myClass = this;
			$(this.tabs[i]).myID = i;
			$(this.tabs[i]).observe('mouseover', this.mouseover);				
			$(this.tabs[i]).observe('mouseout', this.mouseout);	
			
		}
		//ersten Tab ausblenden
		this.tabs[0].style.display = 'none';
		
		
		for (var j=0; j<this.productContents.length; j++ )
		{
			$(this.productContents[j]).myClass = this;
			$(this.productContents[j]).myID = i;
			$(this.productContents[j]).style.display = 'none';
		}
		this.productContents[0].style.display = 'block';
	
	},
	
	press : function ()
	{
		if(this.myID != this.myClass.actualTab)
		{
			this.myClass.activate(this.myID);
		}
		this.myClass.butterflyBig.style.display = 'none';
		this.myClass.butterflySmall.style.display = 'block';
		
	},
	
	activate : function (newTabPos)
	{
		
		for (var i=0; i<this.tabs.length; i++ )
		{
			$(this.tabs[i]).removeClassName("active");
			
			if(i != newTabPos)
			{
				$(this.tabs[i]).addClassName('');
			}
			else
			{
				$(this.tabs[i]).addClassName('active');

			}
		}
		
		for (var j=0; j<this.productContents.length; j++ )
		{
			
			if(j != newTabPos)
			{
				$(this.productContents[j]).style.display = 'none';
			}
			else
			{
				$(this.productContents[j]).style.display = 'block';
			}
		}
		
		this.actualTab = newTabPos;
	},
	
	mouseover : function ()
	{
		this.addClassName('mouseover');
	},
	
	mouseout : function ()
	{
		if(this.className.indexOf("mouseover") >= 0)
		{
			this.removeClassName("mouseover");
		}
	}


}


//Klasse um Portaldropdown
var toggler = Class.create();
toggler.prototype = {

	initialize : function (container)
	{
		
		this.immutable = container;

		this.textboxes = this.immutable.getElementsByClassName('textbox');
		
		// Alle Tabs auf deaktiviert setzen bis auf den Ersten
		for (var i=0; i<this.textboxes.length; i++ )
		{
			$(this.textboxes[i]).observe('click', this.toggleDetail);
			$(this.textboxes[i]).myClass = this;
			$(this.textboxes[i]).myID = i;
			$(this.textboxes[i]).actualOpen = false;
			$(this.textboxes[i]).details = $(this.textboxes[i]).getElementsByClassName('detailtext')[0];
		}
	},
	
	toggleDetail : function ()
	{
		if(this.actualOpen == false)
		{
			this.details.style.display = 'block';
			this.actualOpen = true;
		}
		else
		{
			this.details.style.display = 'none';
			this.actualOpen = false;
		}
	
	}

}











