﻿BlinderChild = function(el,parent,args){
    el.dom.self=this;
    this.parent=parent;
    this.el=el;
    el.dom.onmouseover=function(e){
        this.self.parent.dom.self.canhide=false;
    };
    el.dom.onmouseout=function(e){
        this.self.parent.dom.self.canhide=true;
        this.self.parent.dom.self._onmouseout();
    };
    /* we need to do this for the node placement */
    var p = Ext.get(Ext.DomQuery.selectNode('div#nav'));
    if(el.select('li').elements.length>5){
        el.setLeft(p.getX());
        el.setWidth(900);
    } else {
        el.setLeft(this.parent.getX()-20);
    }
    p.dom.appendChild(el.dom);
}

Blinder = function(el,args) {
    el.dom.self=this;
    el.dom.self.el=el;
    this.parent=null;
    this.canhide=true;
    this.child=new BlinderChild(Ext.Element.get(el.dom.parentNode.getElementsByTagName('ul')[0]),el,'');
    this._isVisible=false;
    this._show=function(){
		this.child.el.slideIn()
        this._isVisible = true;
    };
    this._hide=function(){
        if(this.canhide&&this._isVisible){
            this.child.el.hide();
            this._isVisible = false;
        }
    };
    this._onmouseover=function(){
        this.canhide=false;
        this._show();
    };
    this._onmouseout=function(){
        this.canhide=true;
        setTimeout("Ext.get('"+this.el.id+"').dom.self._hide()", 300);
    };
	el.dom.onmouseover=function(e){
        if (this.self.child!=null){
            this.self._onmouseover();
            return false;
        }
    };
    el.dom.onmouseout=function(e){
        this.self._onmouseout();
    }
}
Blinders = function() {
    this.children=Array();
    this.visible=null;
    this.add=function(obj) {
        obj.parent=this;
        this.children.push(obj);
    };
    this.onSelect=function(obj){
        if (this.visible!=null&&this.visible!=obj) {
            this.visible._hide();
			this.visible=null;
        }
        this.visible=obj;
    };

}

Ext.onReady(function(){
    var itm = Ext.DomQuery.select("a[class='menu']");
    var bs = new Blinders();
    for (var a=0;a<itm.length;a++) {
        var el = Ext.Element.get(itm[a]);
        var b = new Blinder(el);
        bs.add(b);
    }
    
})
