var isIE = navigator.appName.indexOf("Microsoft") > -1;
if (isIE && document.execCommand)	document.execCommand('BackgroundImageCache', false, true);

function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
 	if (start<0) return '';
 	start += name.length+2;
 	var end=location.search.indexOf("&",start)-1;
 	if (end<0) end=location.search.length;
 	var result=location.search.substring(start,end);
 	var result='';
 	for(var i=start;i<=end;i++)
 	{
 		var c=location.search.charAt(i);
 		result=result+(c=='+'?' ':c);
 	}
 	//alert(unescape(result));
 	return unescape(result);
}

function checkURL(array)
{
	var url = window.top.location.href;
	var id;
	var va = [["/", "/"], ["=", ""]];

	for (var item=0; item<va.length; item++)
	{
		for (var i=0; i<array.length; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = array[i];
				break;
			}
		}
	}

	return id;
}

function changeLanguage(target)
{
	//var array = new Array("en", "tc", "sc");  // i don't konw why like this,
	var array = new Array("eng", "chi", "gb");
	var nowL = checkURL(array);
	var va = [["/", "/"], ["=", ""]];
	var url = window.top.location.href;
	for (var item=0; item<va.length; item++)
	{
		if (url.indexOf((va[item][0] + nowL + va[item][1])) >= 0)
		{
			url = url.replace((va[item][0] + nowL + va[item][1]), (va[item][0] + target + va[item][1]));
			break;
		}
	}
	if (url.substring((url.length-1), url.length) == '#')	url = url.substring(0, (url.length-1))
	window.top.location.href = url;
}

function NewWindow(mypage, myname, w, h, scroll,resizable) {
	if (isIE)
	{
		w = w - 4;
		h = h - 4;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+','
	win = window.open(mypage, myname, winprops)
	win.self.focus()
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isLiteVersion() {
	var vers = GetParam('v');
	if (vers != undefined && vers != '') {
		if (vers == 'lite') {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function genFlash(file, width, height, id, vars) {
	if (file.indexOf('flashnav.swf')!=-1)
		{
			// Funtion Hardcode by Fred 20081105
			// if calling home.swf thus the subpage main nav,
			// i need to append '?v=lite' at the back of any connecting URL link.
			// End of by Fred 20081105.
			var isLite = isLiteVersion();
			if (isLite) {
				vars += "&liteVersion=lite";
			}
		}
	if (file.indexOf('home.swf')!=-1)
		{
			// Funtion Hardcode by Fred 20081105
			// if calling home.swf thus the subpage main nav,
			// i need to append '?v=lite' at the back of any connecting URL link.
			// End of by Fred 20081105.
			var isLite = isLiteVersion();
			if (isLite) {
				vars += "&liteVersion=lite";
			}
		}
	var tempHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'">';
	tempHtml += '<param name="movie" value="'+file+'">';
	tempHtml += '<param name="quality" value="high">';
	tempHtml += '<param name="menu" value="false">';
	tempHtml += '<param name="wmode" value="transparent">';
	//tempHtml += '<param name="scale" value="noscale">';
	tempHtml += '<param name="salign" value="TL">';

	if (vars != null) {
		tempHtml += '<param name="flashVars" value="'+vars+'">';
		tempHtml += '<embed src="'+file+'" flashVars="'+vars+'" salign="TL" quality="high" wmode="transparent" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	} else {
		tempHtml += '<embed src="'+file+'" salign="TL" quality="high" wmode="transparent" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	}

	tempHtml += '</object>';

	document.write(tempHtml);
}

///////////////////////////////////////////////////////////////////////////////////////////////
// show / hide the content in order let the visitor to review the whole bg images.
// Function needed
///////////////////////////////////////////////////////////////////////////////////////////////
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
        oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

///////////////////////////////////////////////////////////////////////////////////////////////
// show / hide the content in order let the visitor to review the whole bg images.
///////////////////////////////////////////////////////////////////////////////////////////////
function goLong(elem, h, Fnc) {	
	document.getElementById("dummyPlane").style.display = "block";
	var a = new Object();
	a.onMotionFinished = function(){
		Fnc();
		document.getElementById("dummyPlane").style.display = "none";
	};
	var t1 = new Tween(elem.style,'height',Tween.regularEaseIn,1,h,0.3,'px');
	t1.addListener(a);
	t1.start();
}
function goShort(elem,h) {
	document.getElementById("dummyPlane").style.display = "block";
	var a = new Object();
	a.onMotionFinished = function(){
	   document.getElementById("dummyPlane").style.display = "none";
	};
	var t1 = new Tween(elem.style,'height',Tween.regularEaseIn,h,1,0.3,'px');
	t1.addListener(a);
	t1.start();
}
function doOpen() {	
	var e = document.getElementById("content");
	var e2 = getElementsByClassName(e, "div" ,"page");
	if (e2[0]) {
		e2[0].style.display = "block";
	}
	var e3 = getElementsByClassName(document, "div" , "footer_540");
	if (!e3[0]) {
		e3 = getElementsByClassName(document, "div" , "footer_750");
	}
	if (!e3[0]) {
		e3 = getElementsByClassName(document, "div" , "footer_900");
	}
	e3[0].style.display = "block";
}
function doClose() {
	var e = document.getElementById("content");
	var e2 = getElementsByClassName(e, "div" ,"page");
	if (e2[0]) {
		e2[0].style.display = "none";
	}
	var e3 = getElementsByClassName(document, "div" , "footer_540");
	if (!e3[0]) {
		e3 = getElementsByClassName(document, "div" , "footer_750");
	}
	if (!e3[0]) {
		e3 = getElementsByClassName(document, "div" , "footer_900");
	}
	e3[0].style.display = "none";
}
var dummyPlaneType = 540;

function toggleContent(f) {
	var h = 400;
	// make a dummy content
	var dummyPlane = document.getElementById("dummyPlane");
	if (!dummyPlane) {
		var dumElem = document.getElementById("container");
		var dummyPlane = document.createElement('div');
		dummyPlane.setAttribute('id','dummyPlane');
		var dummyPlaneStyleStr = "background:#E4E0DD;position:absolute;display:block;";
		dummyPlaneStyleStr += "top:436px;right:48px;height:600px;";		
		dummyPlaneStyleStr += "filter: alpha(opacity=50);opacity:0.5;-moz-opacity: 0.5; ";
		dummyPlaneType = 540;
		var e3 = getElementsByClassName(document, "div" , "footer_540");
		if (!e3[0]) {			
			e3 = getElementsByClassName(document, "div" , "footer_750");
			dummyPlaneType = 750;
		}
		if (!e3[0]) {
			e3 = getElementsByClassName(document, "div" , "footer_900");
			dummyPlaneType = 900;
		}		
		dummyPlaneStyleStr += "width:"+dummyPlaneType+"px;";
		dummyPlane.setAttribute('style', dummyPlaneStyleStr);
		dumElem.appendChild(dummyPlane);
	}
	if (isIE) {
		var dumPlane = document.getElementById("dummyPlane");
		dumPlane.style.backgroundColor = "#E4E0DD";
		dumPlane.style.width = dummyPlaneType + "px";
		dumPlane.style.height = "600px";
		dumPlane.style.position = "absolute";
		dumPlane.style.top = "436px";
		dumPlane.style.right = "48px";
		dumPlane.style.display = "block";
		dumPlane.style.filter = "alpha(opacity=50)";
	}
	if (f.toString() == 'true') {
		doClose();
		goShort(dummyPlane, 400);
	}else {
		goLong(dummyPlane, 400, doOpen);
	}

}