var CSSmenu = {

/* Konfiguration */

imgTab 				: new Array(),
imgTab_hover 	: new Array(), 
pathToImages	:	"/images/",
disappeardelay		:	250, 																				// Zeit in ms zum Ausblenden des Menus bei Event : onmouseout
disablemenuclick	:	true,																				// Verhindern, dass Link bei Menu mit Unterobjekten ausgeführt wird
enableswipe		:	0,																					// Swipe Effekt aktivieren ? 1 = true | 0 = false
objSubmenu		:	null,
objLabelIMG		: 	null,
isIE			:	document.all,																// IE ?
isFirefox		:	document.getElementById && !document.all,
swipetimer		:	undefined,
bottomclip		:	0,

getElementOffset	:	function(obj, value) {
	var totaloffset		= (value == "left") ? obj.offsetLeft : obj.offsetTop;
	var parentElement 	= obj.offsetParent;
	while (parentElement != null){
		totaloffset 	= (value == "left") ? totaloffset + parentElement.offsetLeft : totaloffset + parentElement.offsetTop;
		parentElement	= parentElement.offsetParent;
	}
	return totaloffset;
},

swipeeffect		:	function(){
	if (this.bottomclip < parseInt(this.objSubmenu.offsetHeight)){
		this.bottomclip		 	+= 10 + (this.bottomclip / 10) 								//unclip drop down menu visibility gradually
		this.objSubmenu.style.clip	= "rect(0 auto " + this.bottomclip + "px 0)"
	}else{
		return
	}
	this.swipetimer				= setTimeout("CSSmenu.swipeeffect()", 10)
},

showhide		: function(objCSSStyle, event){

	if (this.isIE || this.isFirefox){
		this.objSubmenu.style.left	= this.objSubmenu.style.top = "-500px"
	}

	if (event.type == "click" && obj.visibility == "hidden" || event.type == "mouseover"){

		if (this.enableswipe == 1){

			if (typeof this.swipetimer != "undefined"){
				clearTimeout(this.swipetimer)
			}

			objCSSStyle.clip	= "rect(0 auto 0 0)" 													//hide menu via clipping
			this.bottomclip		= 0
			this.swipeeffect()
		}

		objCSSStyle.visibility		= "visible"

	}else if (event.type == "click"){

		objCSSStyle.visibility		= "hidden"

	}
},

RootNode		: function(){
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
},

clearbrowseredge	: function(obj, whichedge) {
	var edgeoffset	= 0
	if (whichedge == "rightedge"){
		var windowedge 			= this.isIE && !window.opera ? this.RootNode().scrollLeft + this.RootNode().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
		this.objSubmenu.contentmeasure = this.objSubmenu.offsetWidth
		if (windowedge - this.objSubmenu.x < this.objSubmenu.contentmeasure){  	//move menu to the left?
			edgeoffset		= this.objSubmenu.contentmeasure - obj.offsetWidth
		}
	}else{
		var topedge			= this.isIE && !window.opera ? this.RootNode().scrollTop : window.pageYOffset
		var windowedge			= this.isIE && !window.opera ? this.RootNode().scrollTop + this.RootNode().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
		this.objSubmenu.contentmeasure = this.objSubmenu.offsetHeight
		if (windowedge - this.objSubmenu.y < this.objSubmenu.contentmeasure){ 	//move up?
			edgeoffset		= this.objSubmenu.contentmeasure + obj.offsetHeight
			if ((this.objSubmenu.y - topedge) < this.objSubmenu.contentmeasure) { 	//up no good either?
				edgeoffset	= this.objSubmenu.y + obj.offsetHeight - topedge
			}
		}
	}
	return edgeoffset
},

showSubmenu			: function(objATag, event, dropmenuID, nameLabel){

	this.objLabelIMG			= document.getElementsByName(nameLabel)[0]

	if (this.objSubmenu != null){ 																							//hide previous menu
		this.objSubmenu.style.visibility = "hidden" 															//hide menu
		this.clearhidemenu()
	}
	if (this.isIE || this.isFirefox){
		objATag.onmouseout			= function() {
			CSSmenu.hideSubmenu()
			}
		objATag.onclick				= function() {
			return !CSSmenu.disablemenuclick
			}		 																																			//disable main menu item link onclick?
	this.objSubmenu			= document.getElementById(dropmenuID)
	this.objSubmenu.onmouseover		= function() {
		CSSmenu.clearhidemenu()
		}
	this.objSubmenu.onmouseout		= function() {
		CSSmenu.dynamichide(event)
		}
	this.objSubmenu.onclick		= function(){
		CSSmenu.hideSubmenu()
		}
	this.showhide(this.objSubmenu.style, event)
	this.objSubmenu.x			= this.getElementOffset(objATag, "left")
	this.objSubmenu.y			= this.getElementOffset(objATag, "top")
	this.objSubmenu.style.left		= this.objSubmenu.x - this.clearbrowseredge(objATag, "rightedge") + "px"
	this.objSubmenu.style.top		= this.objSubmenu.y - this.clearbrowseredge(objATag, "bottomedge") + objATag.offsetHeight + 1 + "px"
	}
},

contains_firefox	: function(a, b) {
	while (b.parentNode){
		if ((b = b.parentNode) == a){
			return true;
		}
	}
	return false;
},

dynamichide		: function(event){
/*	var evtobj 				= window.event ? window.event : event */

	var evtobj	= event || window.event

	if (this.isIE && !this.objSubmenu.contains(evtobj.toElement)){
		this.hideSubmenu()
	}else if (this.isFirefox && event.currentTarget != evtobj.relatedTarget && !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget)) {
		this.hideSubmenu()
	}
},

lostfocus				: function(){
	CSSmenu.objSubmenu.style.visibility = 'hidden'
},

hideSubmenu		: function(){
	labelIndex						= parseInt(this.objLabelIMG.name.substr(parseInt(this.objLabelIMG.name.length)-1,parseInt(this.objLabelIMG.name.length)))
	this.objLabelIMG.src	= CSSmenu.imgTab[labelIndex].src
	this.delayhide		= setTimeout("CSSmenu.lostfocus()" , this.disappeardelay)
},

clearhidemenu		: function(){
	if (this.delayhide != "undefined"){
		clearTimeout(this.delayhide)

	}
},

init			: function(){

/*	preload Label Images */
	var imgFileName					= new String()
	var imgFileNameHover		= new String()
	
for (var img=1; img < 7; img++){
	imgFileName							= CSSmenu.pathToImages+"cssnav_label"+img+".gif"
	imgFileNameHover				= CSSmenu.pathToImages+"cssnav_label"+img+"_hover.gif"
	CSSmenu.imgTab[img]						= new Image()
	CSSmenu.imgTab[img].src				= imgFileName
	CSSmenu.imgTab_hover[img]			= new Image()
	CSSmenu.imgTab_hover[img].src = imgFileNameHover
	}

	for (var ids=0; ids < arguments.length; ids++){
		var labelName			= new String()
		var menuitems			= document.getElementById(arguments[ids]).getElementsByTagName("a")
			for (var i=0; i < menuitems.length; i++){
				if (menuitems[i].getAttribute("rel")){
					menuitems[i].onmouseover = function(e){
						var event		= typeof e != "undefined" ? e : window.event
						labelIndex	= parseInt(this.firstChild.name.substr(parseInt(this.firstChild.name.length)-1,parseInt(this.firstChild.name.length)))
						this.firstChild.src = CSSmenu.imgTab_hover[labelIndex].src
						CSSmenu.showSubmenu(this, event, this.getAttribute("rel"),this.firstChild.name)
					}

				}
			}
		}
	}
}