var IE6 = false; // via conditional comment auf true
var Guichinger = new Class({
	initialize: function(debug) {
		this.debug 		  = debug;
		this.menuSelector = 'ul.rex-navi1';
		this.addMenuEvents();
	},
	addMenuEvents: function() {
		var thisObj = this;
		this.elNavi = $('navigation');
		if (!this.elNavi) return;
		this.elMenu = this.elNavi.getElement('ul');
		if (this.debug) console.log('menu found: ul.' + this.elMenu.className);
		this.selectedSubMenu = null;
		this.subMenus     	 = this.elMenu.getElements('UL');
		if (this.debug) console.log('submenus found: ' + this.subMenus.length);
		this.menuElements 	 = this.elMenu.getElements('LI');
		this.menuElements.each(function(item,index) {
			var subMenu = item.getElement('UL');
			if (!subMenu) {
				item.getElement('A').addEvents({
					'click': function() {
						//alert('clicked');
					}
				});
			} else {
				if (item.hasClass('rex-active') || item.hasClass('rex-current')) {
					thisObj.selectedSubMenu = subMenu;
				}
				item.getElement('A').addEvents({
					'mouseover': function() {
						thisObj.openSubNav(subMenu);
					}  
				});	
			}
		});
		this.elNavi.addEvents({
			'mouseleave': function() {
				if (thisObj.debug) console.log('leaving menu' + thisObj.selectedSubMenu);
				thisObj.openSubNav();
			}				  
		});
	},
	openSubNav: function(el) {
		this.subMenus.setStyle('display','none');
		var submenu = (el) ? el : this.selectedSubMenu;
		if (submenu != null) submenu.setStyle('display','block');
	}
});

window.addEvent('domready',function(){
	//var debug = (!document.all);
	var debug = false;
	var thisSite = new Guichinger(debug);
	
	if (IE6) {
		DD_belatedPNG.fix('#container'); // argument is a CSS selector
		DD_belatedPNG.fix('.image'); // argument is a CSS selector
	}
	
});
