
var smtMenu=Class.create();
Object.extend(smtMenu.prototype,EventDispatcher.prototype);
Object.extend(smtMenu.prototype,{
    initialize:function(obj,state){
return;
        this.src=obj;
        this.items=[];
        $A(this.src.getElementsByTagName("li")).each(function(a){
            if(a.parentNode!=this.src) return;
            this.items.push(new smtMenu.Item(a));
        }.bind(this));
        this.items.each(function(a){a.addEventListener("onItemOpen",this);}.bind(this));
        var i=this.items.length-1;
        var j=0;
        if(state) return;
        var timer=setInterval(function(){
            this.items[j++].close();
            if(--i<0) clearInterval(timer);
        }.bind(this),200);
    },
    onItemOpen:function(obj){
        this.items.without(obj).each(function(a){a.close();});
    }
});

smtMenu.Item=Class.create();
Object.extend(smtMenu.Item.prototype,EventDispatcher.prototype);
Object.extend(smtMenu.Item.prototype,{
    initialize:function(obj){
        this.src=obj;
        new Insertion.Top(this.src,"<a class=\"trigger\">&nbsp;</a>");
        with(this.src.getElementsByTagName("a")){
            Object.extend(this,{"marker":item(0),"title":item(1)});
        }
        with(this.src.getElementsByTagName("ul")){
            if(length>0) this.body=item(0);
        }
        this.marker.onmouseover=this.open.bind(this);
    },
    open:function(){
        //if(!this.closed) return;
        this.marker.onmouseover=function(){};
        this.dispatchEvent({type:"onItemOpen"},this);
        new Effect.MoveBy(this.title,0,-this.title.offsetLeft,{
            duration:0.5,
            afterFinish:function(){
                this.closed=undefined;
                this.marker.onmouseover=this.open.bind(this);
                if(!this.body) return;
                Element.show(this.body);
                new Effect.Opacity(this.body,{duration:0.5,from:0,to:1});
            }.bind(this)
        });
    },
    close:function(){
        //if(this.closed) return;
        this.marker.onmouseover=this.title.onmouseover=function(){};
        new Effect.MoveBy(this.title,0,this.title.offsetLeft-this.title.offsetWidth,{
            duration:0.5,
            afterFinish:function(){
                this.closed=true;
                this.marker.onmouseover=this.open.bind(this);
            }.bind(this)
        });
        this.timer=setTimeout(function(){if(!this.closed)this.close();}.bind(this),5000);
        if(!this.body) return;
        new Effect.Opacity(this.body,{duration:0.5,from:1,to:0,afterFinish:function(){Element.hide(this.body);}.bind(this)});
    }
});
