var pause=10;
var step = 5;
var mx=200;
var my=80;

function localMenu( index, id, parent ) {

        this.index = index;
        this.status = false;

        this.id = id;
        this.obj = document.getElementById( id );

        this.parent = document.getElementById( parent );
        this.className = this.parent.className;

        this.show = function() {

                if ( !this.obj ) {
                        scanMenu();
                        return;
                }

                this.obj.style.display = "";
                this.obj.style.display = "block";
                this.visible = true;


                if ( typeof this.height == "undefined" ) {
                        // determine absolute coord of top/left corner
                        this.left=0
                        this.top=0;
                        el = this.obj;
                        while ( true ) {
                                try {
                                        this.left += el.offsetLeft;
                                        this.top += el.offsetTop;
                                        el = el.offsetParent;

                                } catch(e) { break; }
                        }

                        this.height=this.obj.offsetHeight;
                        this.width=this.obj.offsetWidth;
                        this.obj.style.top=this.obj.style.top-this.height+22+"px";

                        this.y = parseInt(this.obj.style.top);
                        this.old_y = this.y;
                }

                // change bg of tab
                var color = this.parent.className.slice( 8, 14 );
                switch ( color ) {
                        case "C7C575":
                        case "4C87C7":
                        case "C75746":
                        case "A67999":
                        case "6BA5A5":
                        case "6BA5A5": this.parent.className="menu-tab-hover"+color;
                }

                this.status = "down";
                scanMenu();
        }

        this.hide = function() {
                if ( this.status != "opened" ) return;
                this.status = "up";
        }

        this.invisible = function () {
                y = this.old_y;
                this.status = false;
                this.parent.className=this.className;
                this.obj.style.display="none";

                clearTimeout( this.timeOutClose );
                this.timeOutClose = false;
        }

        this.move = function( y ) {
                if ( y>=0 ) { y = 0; this.status = "opened"; }
                else if ( y<=this.old_y ) this.invisible();

                this.y = y;
                this.obj.style.top = this.y+"px";
        }

        this.next = function() {

                switch (this.status) {

                        case "opened":
                                if (!this.timeOutClose && (mx<this.left || mx>this.left+this.width || my>this.top+this.height || my<this.top-35)) {
                                        this.timeOutClose = setTimeout('m['+this.index+'].status="up"', 800);
                                }
                                break;

                        case "up":
                                this.move( this.y - step )
                                break;

                        case "down":

                                this.move( this.y + step );
                                break;
                }
        }
}



/**
 * scan menus and move them
 */
function scanMenu() {
        var stop = true;
        for ( var z=0; z<m.length; z++ ) {
                if (m[z].status!=false) {
                        m[z].next();
                        stop=false;
                }                
        }
        if (stop) clearTimeout(movetimer); else movetimer=setTimeout("scanMenu()",pause);
}

