var __ActiveItem = null;     // - это MenuItem

function HideAll(oMenu) {	if(oMenu != null) {		if(oMenu.isRoot == false)			if(__ActiveItem == null ||				(__ActiveItem != null && __ActiveItem.pOwner != oMenu))	    		oMenu.Show(false);	    for(var i = 0; i < oMenu.Items.length; i++) {	    	oMenu.Items[i].navObj.className = (oMenu.isRoot) ? 'root' : 'sub';	    	HideAll(oMenu.Items[i].SubMenu);	  	}    }}
function DrawMenu(oMenu) {	HideAll(oMenu);	if(__ActiveItem != null) {		var aActItems = Array();		var oSub = __ActiveItem;		while(oSub != null) {			aActItems[aActItems.length] = oSub;			oSub = oSub.pOwner.pParent;		}		for(var i = aActItems.length-1; i >= 0; i--) {			aActItems[i].navObj.className = (aActItems[i].pOwner.isRoot) ? 'aroot' : 'asub';   			var mMenu = aActItems[i].SubMenu;			if(mMenu != null) {				var stPos = getElementPosition(aActItems[i].navObj);
                mMenu.Show(true);
                var thPos = getElementPosition(mMenu.navObj);                if(aActItems[i].pOwner.isRoot) {                	mMenu.Move(stPos.left+stPos.width/2-thPos.width/2, stPos.top + stPos.height);                } else                	mMenu.Move(stPos.left + stPos.width-4, stPos.top+4);    		}		}	}}
function Menu(p, r) {
	this.pParent = p;
	this.isRoot = r;

    this.Items = new Array();
	this.navObj = null;

	// методы
	this.Create = function(id) {
 		var doc = window.document;
	}

    this.Over = function(e) { if(__ActiveItem == null) { __ActiveItem = this.pParent; } }
    this.Out = function(e) { __ActiveItem = null; }
    this.Click = function(e) {  }

    this.Attach = function(id) {
    	var doc = window.document;
        var o = he(id);
        o.o = this;

		o.onmouseover = function(e) {  this.o.Over(e); }
		o.onmouseout = function(e) { this.o.Out(e); }
        o.onclick = function(e) { this.o.Click(e); }

        this.navObj = o;

		var micnt = 0;
        while(true) {
            micnt++;
            var sid = id + 'i' + micnt;
            var s = he(sid);

            if(typeof(s) != 'undefined' && s != null) {
            	this.Add(micnt);
            	this.Items[this.Items.length-1].Attach(sid);
            }
            else { break; }
        }
    }
	this.Add = function(index, label, link) {
        var label = label ? label : '';
        var link = link ? link : '';
		var mi = new MenuItem(this, index, label, link);
       	this.Items[this.Items.length] = mi;

       	return mi;
	}
	this.Remove = function(nNumber) {
 		if(nNumber < this.Items.length)
   			this.Items.splice(nNumber, 1);
	}
	this.Show = function(visible) {		this.navObj.style.display = visible ? 'block' : 'none';	}
	this.Move = function(x, y) {
		this.navObj.style.left = x + 'px';    	this.navObj.style.top = y + 'px';	}
}

function MenuItem(owner, index, label, link) {
	this.pOwner = owner;
	this.nIndex = index;
	this.Label = label ? label : '';
	this.Href = link ? link : '';

    this.SubMenu = null;

	this.navObj = null;

    this.Over = function(e) {
    	__ActiveItem = this;
    	var so1 = new SWFObject("/templates/flash/sound_click.swf?_click=1&r=" + (new Date()).getTime(),"bn","1","1", "7");
		so1.addParam('wmode','transparent');
		so1.write("fl_c");
    }
    this.Out = function(e) { __ActiveItem = null; }
    this.Click = function(e) {  }

    this.Attach = function(id) {
    	var doc = window.document;
        var o = he(id);
        o.o = this;

		o.onmouseover = function(e) {  this.o.Over(e); }
		o.onmouseout = function(e) { this.o.Out(e); }
        o.onclick = function(e) { this.o.Click(e); }

        this.navObj = o;

		var pdis = this.pOwner.navObj.id + '_' + this.nIndex;

		var sm = he(pdis);

		if(typeof(sm) != 'undefined' && sm != null) {
        	this.SubMenu = new Menu(this, false);
            this.SubMenu.Attach(pdis);
        }
    }
}