

function menuDropOver(obj){
	obj.style.backgroundPosition	= 'right -81px';
	obj.style.color					= '#340';
}
function menuDropOut(obj){
	obj.style.backgroundPosition 	= 'right -54px';
	obj.style.color					= '#420';
}
function menuOver(obj){
	obj.style.backgroundPosition	= 'right -27px';
	obj.style.color					= '#340';
}
function menuOut(obj){
	obj.style.backgroundPosition 	= 'right 0';
	obj.style.color					= '#420';
}
function switchDropOver(obj){
	obj.style.backgroundPosition 	= 'right -63px';
}
function switchDropOut(obj){
	obj.style.backgroundPosition 	= 'right -42px';
}
function switchOver(obj){
	obj.style.backgroundPosition 	= 'right -21px';
}
function switchOut(obj){
	obj.style.backgroundPosition 	= 'right 0';
}
function ibtMeetingHostOver(obj){
	obj.style.backgroundPosition	= '0 -27px';
	obj.style.color					= '#340';
}
function ibtMeetingHostOut(obj){
	obj.style.backgroundPosition 	= '0 0';
	obj.style.color					= '#420';
}
function ibtMeetingJoinOver(obj){
	obj.style.backgroundPosition	= '0 -81px';
	obj.style.color					= '#340';
}
function ibtMeetingJoinOut(obj){
	obj.style.backgroundPosition 	= '0 -54px';
	obj.style.color					= '#420';
}
function ibtMeetingLoginOver(obj){
	obj.style.backgroundPosition	= '0 -135px';
	obj.style.color					= '#340';
}
function ibtMeetingLoginOut(obj){
	obj.style.backgroundPosition 	= '0 -108px';
	obj.style.color					= '#420';
}
var ibtTestDriveOver = function(){
	this.style.backgroundPosition 	= '-160px 0';
};
var ibtTestDriveOut = function(){
	this.style.backgroundPosition 	= '0 0';
};
var ibtFreeOver	= function(){
	this.style.backgroundPosition 	= '-160px -32px';
};
var ibtFreeOut = function(){
	this.style.backgroundPosition 	= '0 -32px';
};
var ibtBuyNowOver =	function(){
	this.style.backgroundPosition 	= '-160px -64px';
};
var ibtBuyNowOut = function(){
	this.style.backgroundPosition 	= '0 -64px';
};
var ibtLiveDemoOver	= function(){
	this.className					= 'ibtEyeCandy ibtEyeCandy_LiveDemoDown';
};
var ibtLiveDemoOut = function(){
	this.className					= 'ibtEyeCandy_LiveDemoUp';
};
var ibtFlashDemoOver = function(){
	this.style.backgroundPosition 	= '-160px -32px';
};
var ibtFlashDemoOut = function(){
	this.style.backgroundPosition 	= '0 -32px';
};
var ibtUsersGuideOver = function(){
	this.style.backgroundPosition = '-160px -64px';
};
var ibtUsersGuideOut = function(){
	this.style.backgroundPosition = '0 -64px';
};
var divOEMSwitchOver = function(){
	this.className = 'divOEMSwitchBtnOver';
};
var divOEMSwitchBtnOut = function(){
	this.className = 'divOEMSwitchBtnDown';
}

//top location swicth
function gotoURL(url){
	window.top.location.href = url;
}

//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 divObj = null;
	var setWidth = null;
	var liObj = obj.getElementsByTagName("li");
	if(isIE) {
		divObj = document.createElement('div');
		divObj.style.position = 'absolute';
		divObj.style.width = 'auto';
		divObj.style.visibility = 'hidden';
		document.body.appendChild(divObj);
	}
	
	setWidth = function(_obj) {
		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';
		}
	};
	
	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"), "");
				}
			}
		}
	}
}

//big eye candy slide
var HeaderSlideShow = 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( 'HeaderSlideShow.run()', this.persistTime );
				}else
					this.opacityLoop = setTimeout( 'HeaderSlideShow.run()', 1 );
			}
		}
	};
}();

var headerMouseEffect = function() {
	//mouse effect
	if (document.getElementById('divOEMSwitchBtn') != null){
		var divOEMSwitchBtn = document.getElementById('divOEMSwitchBtn');
		divOEMSwitchBtn.onmouseover	=	divOEMSwitchOver;
		divOEMSwitchBtn.onmouseout	=	divOEMSwitchBtnOut;
		divOEMSwitchBtn.onmousedown	=	divOEMSwitchOver;
	}
	if(document.getElementById("ibtTestDrive") != null) {
		var ibtTestDrive = document.getElementById("ibtTestDrive");
		ibtTestDrive.onmouseover	=	ibtTestDriveOver;
		ibtTestDrive.onmouseout		=	ibtTestDriveOut;
		ibtTestDrive.onmousedown	=	ibtTestDriveOver;
	}
	if(document.getElementById("ibtFree") != null) {
		var ibtFree = document.getElementById("ibtFree");
		ibtFree.onmouseover	=	ibtFreeOver;
		ibtFree.onmouseout	=	ibtFreeOut;
		ibtFree.onmousedown	=	ibtFreeOver;
	}
	if(document.getElementById("ibtBuyNow") != null) {
		var ibtBuyNow = document.getElementById("ibtBuyNow");
		ibtBuyNow.onmouseover		=	ibtBuyNowOver;
		ibtBuyNow.onmouseout		=	ibtBuyNowOut;
		ibtBuyNow.onmousedown		=	ibtBuyNowOver;
	}
	if(document.getElementById("ibtLiveDemo") != null) {
		var ibtLiveDemo = document.getElementById("ibtLiveDemo");
		ibtLiveDemo.onmouseover		=	ibtLiveDemoOver;
		ibtLiveDemo.onmouseout		=	ibtLiveDemoOut;
		ibtLiveDemo.onmousedown		=	ibtLiveDemoOver;
	}
	if(document.getElementById("ibtFlashDemo") != null) {
		var ibtFlashDemo = document.getElementById("ibtFlashDemo");
		ibtFlashDemo.onmouseover	=	ibtFlashDemoOver;
		ibtFlashDemo.onmouseout		=	ibtFlashDemoOut;
		ibtFlashDemo.onmousedown	=	ibtFlashDemoOver;
	}
	if(document.getElementById("ibtUsersGuide") != null) {
		var ibtUsersGuide = document.getElementById("ibtUsersGuide");
		ibtUsersGuide.onmouseover	=	ibtUsersGuideOver;
		ibtUsersGuide.onmouseout	=	ibtUsersGuideOut;
		ibtUsersGuide.onmousedown	=	ibtUsersGuideOver;
	}
};

//enter expirence group begin
var initHeaderPage = function() {
	menuEvents(document.getElementById("ulSwitch"));
	menuEvents(document.getElementById("ulMenu")); 
	
	window.document.title = document.getElementById("idPageTitle").value;
	
	//show big eyecandy pictures
	if(document.getElementById( 'slideIndex' ) != null) {
		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] + '.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', ['10'] );	
				else		divImgWhole = addImg( 'USA', ['10'] );
				break;
			case 4:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['09'] );	
				else		divImgWhole = addImg( 'USA', ['09'] );
				break;
			case 5:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['11'] );	
				else		divImgWhole = addImg( 'CHN', ['11'] );
				break;
			case 6:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['08'] );	
				else		divImgWhole = addImg( 'USA', ['08'] );
				break;
			case 7:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['05'] );	
				else		divImgWhole = addImg( 'USA', ['05'] );
				break;
			case 8:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['03'] );	
				else		divImgWhole = addImg( 'USA', ['03'] );
				break;
			case 9:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['04'] );	
				else		divImgWhole = addImg( 'USA', ['04'] );
				break;
			case 10:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['07'] );	
				else		divImgWhole = addImg( 'USA', ['07'] );
				break;
			case 11:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['06'] );	
				else		divImgWhole = addImg( 'USA', ['06'] );
				break;
			default:
				if( isCHN )	divImgWhole = addImg( 'CHN', ['01'] );	
				else		divImgWhole = addImg( 'USA', ['01'] );
		}
		document.getElementById( 'divEyeCandyLeft' ).appendChild( divImgWhole );
		HeaderSlideShow.run( 'divEyeCandyLeft', 5000 );
	}
	
	headerMouseEffect();
};

if(document.all) {
	window.attachEvent('onload', initHeaderPage);
}
else {
	window.addEventListener('load', initHeaderPage, false);
}