/*@ MyDropDownMenu : Class
*. ----------------------------------
*. Current project applied: |BestyleTokyo.com|
*. ----------------------------------
*. { MyDropDownMenu }
	Methods:
	- .linkSub ()
	- .hideSub ()
	- .showSub ()

*. ----------------------------------
*. description: 
	- This is a simple drop down menu modified from MySimpleDDMenu

*. ----------------------------------
*. First Created: 20070824
*. Last Modified : 20080310
*. ----------------------------------
*. Last Updated:
	- mouseout sub-menu, main menu should remain lit/on [fixed]:20080310

*. ----------------------------------
*. developed by oechai
*/


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]);
	var mainBtn = oTgt.getElementsByTagName('a')[0];
	
	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, mainBtn);
	oTgt.onmouseout = Delegate.create(this, this.hideSub, sTgt, mainBtn);
	/*
	mainBtn.onmouseover = function () { 
		this.style.backgroundPosition="0 -20px"; 
	}
	mainBtn.onmouseout = function () { 
		this.style.backgroundPosition="0 0px"; 
	}
	*/
}
MyDropDownMenu.prototype.hideSub = function (o, mainBtn) {
	//trace(o.id+", "+'to be none');
	if(mainBtn) { mainBtn.style.backgroundImage=""; }
	o.style.display = "none";
	if (this._selectedTarget!=null) {
		this._selectedTarget.style.display = "block"; 
		//alert(this._selectedTarget.id);
	}
}
MyDropDownMenu.prototype.showSub = function (o, mainBtn) {
	//trace(o.id+", "+'to be showed');
	if(mainBtn) { mainBtn.style.backgroundImage="url(img/hover_bg.gif)";}
	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];
			}
		}
	}
}
