IOM.HWS.Header	= {};

IOM.HWS.Header.gotoURL = function(_url){
	window.top.location.href = _url;
};

IOM.HWS.Header.menuEvents = function(obj){
	var ua			= navigator.userAgent.toLowerCase();
	var isOpera		= ua.indexOf("opera") > -1;
	var isIE		= !isOpera && ua.indexOf("msie") > -1;
	var ieVersion	= 0;
	if(isIE) {
		var info	= ua.match(/msie ([\d.]+)/);
		ieVersion	= info[1].split(".")[0] * 1;
	}

	var divObj		= null;
	if(isIE && ieVersion < 8) {
		divObj					= document.createElement('div');
		divObj.style.position	= 'absolute';
		divObj.style.width		= 'auto';
		divObj.style.visibility	= 'hidden';
		document.body.appendChild(divObj);
	}
	
	var setWidth = function(_obj) {
		if(isIE && ieVersion < 8) {
			var getWidth = function(_aObj) {
				if(_aObj) {
					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';
			}
		}
	};
	
	var objLis = obj.getElementsByTagName("li");
	for (var i=0; i<objLis.length; i++){
		setWidth(objLis[i]);
		if (objLis[i].className.length > 0){
			objLis[i].onmouseover = function(){
				this.className += (this.className.length>0? " ": "") + "lihover";
				setWidth(this);
			};
			objLis[i].onMouseDown = function(){
				this.className += (this.className.length>0? " ": "") + "lihover";
				setWidth(this);
			};
			objLis[i].onMouseUp = function(){
				this.className += (this.className.length>0? " ": "") + "lihover";
				setWidth(this);
			};
			objLis[i].onmouseout = function(){
				this.className = this.className.replace(new RegExp("( ?|^)lihover\\b"), "");
				setWidth(this);
			};
		}
	}
};

//big eye candy slide
IOM.HWS.Header.slideShow = function(){
	return {		
		clarityDegree	: 0,
		opacityDegree	: 100,
		images			: null,
		startIndex		: 0,
		endIndex		: 0,
		persistTime		: 0,
		countLoop		: null,
		opacityLoop		: null,
		run : function( containerID, persistTime ){
			//get images
			if( containerID ){
				this.images = document.getElementById( containerID ).getElementsByTagName('IMG');
				this.endIndex = this.images.length - 1;
			}
			//0 pic, 1 pic, n pics
			if( this.images.length == 0 ){
				document.getElementById( containerID ).innerHTML = "Can't find any images!";
			}
			else if( this.images.length == 1 ){
				this.images[0].style.filter	= 'alpha(opacity=100)';
				this.images[0].style.opacity = 1;
			}
			else if( this.images.length > 1 ){
				//fade in next image
				this.images[this.startIndex].style.filter = 'alpha(opacity=' + this.clarityDegree + ')';
				this.images[this.startIndex].style.opacity = this.clarityDegree/100;
				//fade out pre image
				var tempIndex = this.startIndex==0 ? this.images.length-1 : this.startIndex-1;
				this.images[tempIndex].style.filter = 'alpha(opacity=' + this.opacityDegree + ')';
				this.images[tempIndex].style.opacity = this.opacityDegree / 100;
				//persist time
				if( persistTime ) this.persistTime = persistTime;
				//loop var, IE's speed is different than other browsers
				this.clarityDegree += document.all? 20 : 4;
				this.opacityDegree -= document.all? 20 : 4;
				//loop run
				if( this.clarityDegree > 100 ){
					this.clarityDegree = 0;
					this.opacityDegree = 100;
					this.startIndex == this.endIndex ? this.startIndex=0 : this.startIndex += 1;							
					this.countLoop = setTimeout( 'IOM.HWS.Header.slideShow.run()', this.persistTime );
				}
				else{
					this.opacityLoop = setTimeout( 'IOM.HWS.Header.slideShow.run()', 1 );
				}
			}
		}
	};
}();

IOM.HWS.Header.freshSlideShow = function() {
	//show big eyecandy pictures
	if(document.getElementById( 'slideIndex' ) != null) {
		var svn			= 439;
		var slideIndex	= parseInt( document.getElementById( 'slideIndex' ).value );
		var isCHN		= document.getElementById( 'isCHN' ).value == 'true' ? true : false;
		var divImgWhole	= document.createElement( 'DIV' );
		
		var addImg = function( strSite, imgArray ){
			var divTemp	= document.createElement( 'DIV' );
			var imgPath	= '../resource/image/Header/' + document.getElementById('pageLanguage').value + '/';
			var imgName	= 'img_';
			divTemp.className = 'divImgWhole';
			for( i = 0; i < imgArray.length; i++ ){
				imgObj = imgName + i;
				var imgObj = document.createElement( 'IMG' );
				imgObj.id  = 'eyeCandy_' + i;
				imgObj.src = imgPath + 'imgEyeCandy' + strSite + '_' + imgArray[i] + '_' + svn + '.jpg';
				divTemp.appendChild( imgObj );
			}
			return divTemp;
		};
		
		switch ( slideIndex ) {
			case 1:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['01'] );	
				else 		divImgWhole = addImg( 'USA', ['01'] );
				break;
			case 2:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['02'] );	
				else		divImgWhole = addImg( 'USA', ['02'] );
				break;
			case 3:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['03'] );	
				else		divImgWhole = addImg( 'USA', ['03'] );
				break;
			case 4:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['04'] );	
				else		divImgWhole = addImg( 'USA', ['04'] );
				break;
			case 5:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['05'] );	
				else		divImgWhole = addImg( 'CHN', ['05'] );
				break;
			case 6:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['06'] );	
				else		divImgWhole = addImg( 'USA', ['06'] );
				break;
			case 7:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['07'] );	
				else		divImgWhole = addImg( 'USA', ['07'] );
				break;
			default:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['01'] );	
				else		divImgWhole = addImg( 'USA', ['01'] );
		}
		document.getElementById( 'divEyeCandyLeft' ).appendChild( divImgWhole );
		IOM.HWS.Header.slideShow.run( 'divEyeCandyLeft', 5000 );
	}
};
IOM.HWS.Header.mouseEffect = function() {
	if (document.getElementById('divOEMSwitchBtn')){
		var divOEMSwitchBtn = document.getElementById('divOEMSwitchBtn');
		divOEMSwitchBtn.onmouseover	= function(){
			this.className = 'divOEMSwitchBtnOver';
		};
		divOEMSwitchBtn.onmouseout = function(){
			this.className = 'divOEMSwitchBtnOut';
		};
	}
	
	if(document.getElementById("ibtTestDrive")) {
		var ibtTestDrive = document.getElementById("ibtTestDrive");
		ibtTestDrive.onmouseover = function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_TestDriveUp';
		};
		ibtTestDrive.onmouseout = function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_TestDriveOut';
		};
	}
	
	if(document.getElementById("ibtFree")) {
		var ibtFree = document.getElementById("ibtFree");
		ibtFree.onmouseover	= function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_FreeUp';
		};
		ibtFree.onmouseout = function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_FreeOut';
		};
	}
	
	if(document.getElementById("ibtLiveDemo")) {
		var ibtLiveDemo = document.getElementById("ibtLiveDemo");
		ibtLiveDemo.onmouseover = function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_LiveDemoDown';
		};
		ibtLiveDemo.onmouseout = function(){
			this.className = 'ibtEyeCandy_LiveDemoUp';
		};
	}
	
	if(document.getElementById("ibtDemo")) {
		var ibtDemo = document.getElementById("ibtDemo");
		ibtDemo.onmouseover	= function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_DemoUp';
		};
		ibtDemo.onmouseout = function(){
			this.className = 'ibtEyeCandy ibtEyeCandy_DemoOut';
		};
	}
	
	if(document.getElementById('tdLoginSeat')) {
		var tdLoginSeat = document.getElementById('tdLoginSeat');
		tdLoginSeat.onmouseover = function() {
			this.className = 'tdLogin tdLoginSeatOver';
		};
		tdLoginSeat.onmouseout = function() {
			this.className = 'tdLogin tdLoginSeatOut';
		};
	}
	
	if(document.getElementById('tdLoginAdmin')) {
		var tdLoginAdmin = document.getElementById('tdLoginAdmin');
		tdLoginAdmin.onmouseover = function() {
			this.className = 'tdLogin tdLoginAdminOver';
		};
		tdLoginAdmin.onmouseout = function() {
			this.className = 'tdLogin tdLoginAdminOut';
		};
	}
	
	if(document.getElementById('tdLoginAgent')) {
		var tdLoginAgent = document.getElementById('tdLoginAgent');
		tdLoginAgent.onmouseover = function() {
			this.className = 'tdLogin tdLoginAgentOver';
		};
		tdLoginAgent.onmouseout = function() {
			this.className = 'tdLogin tdLoginAgentOut';
		};
	}
	
	if(document.getElementById('divSwitchLanguageDrop')) {
		var divSwitchLanguageDrop = document.getElementById('divSwitchLanguageDrop');
		divSwitchLanguageDrop.onmouseover = function() {
			this.className = 'divSwitchDropIcon divSwitchDropIconOver';
		};
		divSwitchLanguageDrop.onmouseout = function() {
			this.className = 'divSwitchDropIcon divSwitchDropIconOut';
		};
	}
	
	if(document.getElementById('divSwitchSiteDrop')) {
		var divSwitchSiteDrop = document.getElementById('divSwitchSiteDrop');
		divSwitchSiteDrop.onmouseover = function() {
			this.className = 'divSwitchDropIcon divSwitchDropIconOver';
		};
		divSwitchSiteDrop.onmouseout = function() {
			this.className = 'divSwitchDropIcon divSwitchDropIconOut';
		};
	}
	
	if(document.getElementById('divMenuProduct')) {
		var divMenuProduct = document.getElementById('divMenuProduct');
		divMenuProduct.onmouseover = function() {
			this.className = 'divMenuDropIcon divMenuDropIconOver';
		};
		divMenuProduct.onmouseout = function() {
			this.className = 'divMenuDropIcon divMenuDropIconOut';
		};
	}
	
	if(document.getElementById('divMenuAboutUs')) {
		var divMenuAboutUs = document.getElementById('divMenuAboutUs');
		divMenuAboutUs.onmouseover = function() {
			this.className = 'divMenuDropIcon divMenuDropIconOver';
		};
		divMenuAboutUs.onmouseout = function() {
			this.className = 'divMenuDropIcon divMenuDropIconOut';
		};
	}
	
	if(document.getElementById('divMenuHome')) {
		var divMenuHome = document.getElementById('divMenuHome');
		divMenuHome.onmouseover = function() {
			this.className = 'divMenu divMenuOver';
		};
		divMenuHome.onmouseout = function() {
			this.className = 'divMenu divMenuOut';
		};
	}
	
	if(document.getElementById('divMenuDownload')) {
		var divMenuDownload = document.getElementById('divMenuDownload');
		divMenuDownload.onmouseover = function() {
			this.className = 'divMenu divMenuOver';
		};
		divMenuDownload.onmouseout = function() {
			this.className = 'divMenu divMenuOut';
		};
	}
};

//enter expirence group begin
IOM.HWS.Header.init = function() {
	window.document.title = document.getElementById("idPageTitle").value;
	IOM.HWS.Header.menuEvents(document.getElementById("ulSwitch"));
	IOM.HWS.Header.menuEvents(document.getElementById("ulMenu")); 
	IOM.HWS.Header.freshSlideShow();
	IOM.HWS.Header.mouseEffect();
};

if(document.all) {
	window.attachEvent('onload', IOM.HWS.Header.init);
}
else {
	window.addEventListener('load', IOM.HWS.Header.init, false);
}
