//menu events' define
function menuEvents(obj) {
	var ua = navigator.userAgent.toLowerCase();
	var isOpera = ua.indexOf("opera") > -1;
	var isIE = !isOpera && ua.indexOf("msie") > -1;
	var liObj = obj.getElementsByTagName("li");

	var setWidth = function(_obj) {
		var getWidth = function(_aObj) {
			if(_aObj) {				
				var divObj				= document.createElement('div');
				divObj.style.position	= 'absolute';
				divObj.style.width		= 'auto';
				divObj.style.visibility	= 'hidden';
				document.body.appendChild(divObj);
			
				var text			= _aObj.innerHTML;
				divObj.innerHTML	= text;
				var fontSize		= _aObj.currentStyle['fontSize'];
				var fontStyle		= _aObj.currentStyle['fontStyle'];
				var fontWeight		= _aObj.currentStyle['fontWeight'];
				var fontFamily		= _aObj.currentStyle['fontFamily'];
				var lineHeight		=_aObj.currentStyle['lineHeight'];
				
				divObj.style.fontSize	= fontSize;
				divObj.style.fontStyle	= fontStyle;
				divObj.style.fontWeight	= fontWeight;
				divObj.style.fontFamily = fontFamily;
				divObj.style.lineHeight = lineHeight;
				
				var width = divObj.offsetWidth;
				return width;
			}
			else {
				return -1;
			}
		};
		// add 40px to leave padding space
		if(_obj.firstChild.tagName.toLowerCase() == 'a') {
			_obj.style.width = getWidth(_obj.firstChild) + 40 + 'px';
		}
	};		//end of method getWidth
	
	for(var i=0; i<liObj.length; i++) {
		if(isIE) {
			setWidth(liObj[i]);
			if(liObj[i].className.length > 0) {
				liObj[i].onmouseover=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
					setWidth(this);
				};
				liObj[i].onMouseDown=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
					setWidth(this);
				};
				liObj[i].onMouseUp=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
					setWidth(this);
				};
				liObj[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp("( ?|^)lihover\\b"), "");
					setWidth(this);
				};
			}
		}
		else {
			if(liObj[i].className.length > 0) {
				liObj[i].onmouseover=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
				};
				liObj[i].onMouseDown=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
				};
				liObj[i].onMouseUp=function() {
					this.className+=(this.className.length>0? " ": "") + "lihover";
				};
				liObj[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp("( ?|^)lihover\\b"), "");
				};
			}
		}
	}
};

//Page Initializtion Ended
var initLaunch = function(_lc) {	
	menuEvents(document.getElementById("ulSwitch"));
	//mouse effect
	if(document.getElementById("btnLaunchChina") != null) {
		var btnLaunchChina = document.getElementById("btnLaunchChina");
		btnLaunchChina.onmouseover = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchChinaOver';
		};
		btnLaunchChina.onmouseout = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchChina';
		};
		btnLaunchChina.onmousedown = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchChina';
		};
	}
	if(document.getElementById("btnLaunchUSA") != null) {
		var btnLaunchUSA = document.getElementById("btnLaunchUSA");
		btnLaunchUSA.onmouseover = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchUSAOver';
		};
		btnLaunchUSA.onmouseout = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchUSA';
		};
		btnLaunchUSA.onmousedown = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchUSA';
		};
	}
	if(document.getElementById("btnLaunchJPN") != null) {
		var btnLaunchUSA = document.getElementById("btnLaunchJPN");
		btnLaunchUSA.onmouseover = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchJPNOver';
		};
		btnLaunchUSA.onmouseout = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchJPN';
		};
		btnLaunchUSA.onmousedown = function() {
			this.className = 'btnLaunch btnLaunchFont btnLaunchJPN';
		};
	}
	if(document.getElementById("divSwitchDropIcon") != null) {
		var divSwitchDropIcon = document.getElementById("divSwitchDropIcon");
		divSwitchDropIcon.onmouseover = function() {
			this.style.backgroundPosition = "right -21px";
		};
		divSwitchDropIcon.onmouseout = function() {
			this.style.backgroundPosition = "right 0";
		};
		divSwitchDropIcon.onmousedown = function() {
			this.style.backgroundPosition = "right -21px";
		};
	}
	if(document.getElementById("divLaunchLogo") != null) {
		var divLaunchLogo = document.getElementById("divLaunchLogo");
		if(_lc == "en") {
			divLaunchLogo.style.backgroundPosition = "0 0";
		}
		else if(_lc == "es") {
			divLaunchLogo.style.backgroundPosition = "0 -80px";
		}
		else if(_lc == "fr") {
			divLaunchLogo.style.backgroundPosition = "0 -160px";
		}
		else if(_lc == "ja") {
			divLaunchLogo.style.backgroundPosition = "0 -240px";
		}
		else if(_lc == "ko") {
			divLaunchLogo.style.backgroundPosition = "0 -320px";
		}
		else if(_lc == "cn") {
			divLaunchLogo.style.backgroundPosition = "0 -400px";
		}
		else if(_lc == "tw") {
			divLaunchLogo.style.backgroundPosition = "0 -480px";
		}
		else { //en
			divLaunchLogo.style.backgroundPosition = "0 0";
		}
	}
};

function launch(country) {
	document.getElementById('country').value = country;
	document.getElementById('launchForm').submit();
};

