if (typeof Effect == 'undefined')
  throw("You must have the script.aculo.us library to use this accordion");

if (typeof DROW == 'undefined') var DROW = {};

DROW.overlayMenu = Class.create({
	
    initialize: function(id, options) {
        if(!$(id)) throw("Attempted to initalize accordion with id: "+ id + " which was not found.");
        
        this.isIE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
        this.menuEl = $(id);
        
        this.options = {
        	labelSelector: 'a.menu-label',
        	contentSelector: 'ul.menu-content',
            labelCls: "menu-label",
            contentCls: "menu-content",
            activeSuffixCls: "-active",
            backgroundCls: "menu-background"
        }
        Object.extend(this.options, options || {});
        
        this.aItems = new Array();
        
    	var menuItems = this.menuEl.childElements();

    	this.aItems = new Array();
    	for (var i=0;i<menuItems.length;i++) {

    		this.aItems[i] = {};
    		this.aItems[i].label = menuItems[i].select('a')[0];
    		//this.aItems[i].label.addClassName(this.options.labelCls);
    		
    		this.aItems[i].content = menuItems[i].select(this.options.contentSelector)[0];
    		if (this.isIE6) {
    			//this.aItems[i].content.style.left = '-'+this.menuEl.getWidth()+'px';
    		}
    		
    		menuItems[i].observe('mouseover', this.onMouseOver.bindAsEventListener(this, this.aItems[i]));
    		menuItems[i].observe('mouseout', this.onMouseOut.bindAsEventListener(this, this.aItems[i]));
    	}
    	
    	this.background = new Element('div', {
    		className: this.options.backgroundCls
    	});
    	this.background.hide();
    	if (this.isIE6) {
			//this.background.style.left = '-'+this.menuEl.getWidth()+'px';
		}
    	$(document.body).appendChild(this.background);
    }

	,onMouseOver: function (e, item) {
		if(item.content == undefined) return;
		this.background.style.height = item.content.getHeight()+'px';
		
		this.background.show();
		
		var o = this.options;
		item.label.addClassName(o.labelCls+o.activeSuffixCls);
		item.content.addClassName(o.contentCls+o.activeSuffixCls);
	}
	
	,onMouseOut: function (e, item) {
		if(item.content == undefined) return;
		this.background.hide();
		
		var o = this.options;
		item.label.removeClassName(o.labelCls+o.activeSuffixCls);
		item.content.removeClassName(o.contentCls+o.activeSuffixCls);
	}
});
