
var Dropdown = Class.create();

Dropdown.prototype = {
	
	
	myMenus: [],
	initialize: function() { 
			this.updateLinkList();
	},
	
	updateLinkList: function() {   
        this.updateImageList = Prototype.emptyFunction;

        document.observe('mouseover', (function(event){
            var target = event.findElement('a[rel^=dropdown]');
            if (target) {
                event.stop();
				this.hideAll();
                this.show(target);
            } else {
				var element = Event.element(event);

	
				if (element.tagName == "BODY" || element.tagName == "HTML"){
					this.hideAll();
					return;
				}
				if (element.id != "gelberBalkenContent" && 
					element.id != "gelberBalken" &&
					(!element.hasClassName('subItem') &&
					!element.hasClassName('dropMenu') &&
					!element.up().hasClassName('subItem'))
					){
				//alert(element.inspect())
						this.hideAll();
				}
				
			}
        }).bind(this));
		
		/*
		document.observe('mouseout', (function(event){
            var target = event.findElement('a[rel^=dropdown]');
            if (target) {
                event.stop();
                this.hide(target);
            }
        }).bind(this));
		*/
		// alle menus finden
		//alert($$('DIV.dropMenu'));
		this.myMenus = $$('DIV.dropMenu');
		this.myMenus.each(function(s) {
			nr = s.id.toString().substring(3,s.id.toString().length);
			position = $('link'+nr).up().positionedOffset();
			s.removeClassName('hidden');
			s.setStyle({
			  top: (position.top+28)+'px',
			  left: (position.left-3)+'px'
			});

			s.hide();
		});

    },
	
	show: function(dropLink) { 
		number = dropLink.toString();
		number = number.substring(number.lastIndexOf('/')+1,number.length-5);
		$('sub'+number).show();
		//alert($('sub127'));
	},
	
	hide: function(dropLink) { 
		number = dropLink.toString();
		number = number.substring(number.lastIndexOf('/')+1,number.length-5);
		$('sub'+number).hide();
		//alert($('sub127'));
	},
	
	hideAll: function() { 
		this.myMenus.each(function(s) {
			s.hide();
		});
	}
	
}



document.observe('dom:loaded', function () { new Dropdown(); });