
/*@ MyDropDownMenu Class
*. ----------------------------------
*. Last Modified : 24 August 2007
*. ----------------------------------
*. MyDropDownMenu
	- linkSub ()
	- hideSub ()
	- showSub ()
*. ----------------------------------
*. This is a simple drop down menu modified from MySimpleDDMenu
*. 
*. 
*/

MyDropDownMenu = function () {
	this._submenu = new Array();
	this._selectedTarget = null;
}
MyDropDownMenu.prototype.linkSub = function () {
	var oTgt = document.getElementById(arguments[0]);
	var sTgt = document.getElementById(arguments[1]);

	this._submenu.push(sTgt);

	var selectedAttr = this.getAttr(oTgt, "selected");
	
	//default
	if(selectedAttr!=undefined) { 
		this.showSub(sTgt);
		//alert(oTgt.attributes.selected.value+", "+typeof oTgt.attributes.selected.value)
		if (selectedAttr.value=="true") {
			this._selectedTarget = sTgt;
		}
	} else { this.hideSub(sTgt);
		//alert("@linkSub: "+oTgt.id+", "+oTgt.attributes["selected"]+", "+oTgt.attributes.length);
	}
	
	oTgt.onmouseover = Delegate.create(this, this.showSub, sTgt);
	oTgt.onmouseout = Delegate.create(this, this.hideSub, sTgt);
}
MyDropDownMenu.prototype.hideSub = function (o) {
	//trace(o.id+", "+'to be none');
	o.style.display = "none";
	if (this._selectedTarget!=null) {
		this._selectedTarget.style.display = "block"; 
		//alert(this._selectedTarget.id);
	}
}
MyDropDownMenu.prototype.showSub = function (o) {
	//trace(o.id+", "+'to be showed');
	var m = this._submenu;
	var l = m.length;

	for (i=0; i<l; i++) {
		if (m[i].style.display=="block") m[i].style.display = "none";
	}
	o.style.display = "block";
}
MyDropDownMenu.prototype.getAttr = function (target, nodeName) {
	var attr = target.attributes;
	if (attr) {
		var len = attr.length;
		if (attr[nodeName]) {
			return attr[nodeName];
		}else {
			for (i=0; i<len; i++) {
				//if (attr[i].nodeName == "selected") alert(target.id +" got selected & it value is " + attr[i].value +", "+typeof attr[i].value);
				if (attr[i].nodeName == nodeName) return attr[i];
			}
		}
	}
}

