//Start Run
var wholebg;
init();
function translator(pattern) {//======translator
	var open_in_same_window = 0;
	var my_location = unescape(document.location.toString());
	var new_location ='';
	var new_pattern = '';
	var islocal = 1;
	if(my_location.indexOf('babelfish/translate_url_content?') != -1){
		var indexof_u = my_location.indexOf('&trurl=');
		if (indexof_u == -1) new_location = document.location;
		else {
			var subs = my_location.substring(indexof_u, my_location.length);
			var ss = subs.split('&');
			new_location = ss[1].substring(6, ss[1].length);
			islocal = 0;
		}
	} else {
		new_location = document.location;
		
	}

	indexof_p = pattern.indexOf('|');
	var isen = '';
	var lg = '';
	if (indexof_p == -1) {
		indexof_p1 = pattern.indexOf('><');
		if (indexof_p1 == -1) {
			new_pattern = pattern;
			if (pattern == 'en') isen = 1;
		}
		else {
			var psplit = pattern.split('><');
			new_pattern = psplit[0] + '_' + psplit[1];
			if (psplit[1] == 'en') isen = 1;
			else lg = psplit[1];
		}
	}
	else {
		var psplit = pattern.split('|');
		new_pattern = psplit[0]+'_'+psplit[1];
		if (psplit[1] == 'en') isen = 1;
		else lg = psplit[1];
	}

	var thisurl = '';
	if (isen == 1) thisurl = new_location;
	else {
		new_location = escape(new_location);
		if (islocal == 1) {
			thisurl = "language.php?to=" + lg + "&url=" + new_location;
		} else {
			open_in_same_window = 1;
			thisurl = "http://66.163.168.225/babelfish/translate_url_content?lp=" + new_pattern + "&trurl=" + new_location;
		}
	}

	if (open_in_same_window == 1) window.location.href = thisurl;
	else {
		msgWindow=window.open('' ,'subwindow','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes,left=0,top=0');
		msgWindow.focus();
		msgWindow.location.href = thisurl;
	}
}

//Zhe following is Writed By Jammy
function Id(key){return document.getElementById(key);}
function Tag(obj,key){if(key==null)return document.getElementsByTagName(obj);else return obj.getElementsByTagName(key);}
function Style(obj,key){return obj.currentStyle?obj.currentStyle[key]:document.defaultView.getComputedStyle(obj,null)[key];}
function stopBubble(){if(window.event)window.event.cancelBubble=true;else arguments[0].stopPropagation();}
function createXmlHttp(){var xmlHttp=null;if(window.ActiveXObject==null)xmlHttp=new XMLHttpRequest();if(window.ActiveXObject)xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");return xmlHttp;}
function over(sender,maxwid,minpad)
{
	var obj=Id(sender);
	var link=Tag(obj,"a");
	if(link.length==0)link=Tag(obj,"span");
	var wid=0;
	for(var i=0;i<link.length;i++)
	{
		link[i].style.paddingLeft=minpad+"px";
		link[i].style.paddingRight=minpad+"px";
		wid+=link[i].offsetWidth;
	}
	while(wid>maxwid){
		var size=Style(link[0],"fontSize");
		size=parseInt(size)-1;
		wid=0;
		for(var i=0;i<link.length;i++)
		{
			link[i].style.fontSize=size+"px";
			wid+=link[i].offsetWidth;
		}
	}
	var pad=(maxwid-wid+link.length*minpad*2)/(link.length*2);
	for(var i=0;i<link.length;i++)
	{
		link[i].style.paddingLeft=pad+"px";
		link[i].style.paddingRight=pad+"px";
	}
}
function tables()
{
	var tables=Tag("table");
	for(var i=0;i<tables.length;i++)
	{
		tables[i].border="0";
		tables[i].cellpadding="0";
		tables[i].cellspacing="0";
	}
}
function openf(file)
{
		var xmlHttp=createXmlHttp();
		xmlHttp.open("GET","html/"+file+".html",true);
		xmlHttp.setRequestHeader("Content-Type","text/html;charset=utf-8");
		xmlHttp.onreadystatechange=function(){callback(xmlHttp);}
		xmlHttp.send(null);
		return false;
}
function callback(xmlHttp)
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			Id("right").innerHTML=xmlHttp.responseText;
			wholebg.style.height=Id("whole").offsetHeight+"px";
			xmlHttp=null;
		}
	}
}
function init()
{
	try{document.execCommand("BackgroundImageCache",false,true);}catch(e){}
	
	var js_menu=document.createElement("dt");
	var js_link=document.createElement("a");
	js_link.innerHTML="Factory Tour";
	js_link.onmouseover=function(){this.style.cursor="pointer";}
	js_link.onclick=function(){openf("tour");}
	js_menu.appendChild(js_link);
	var mainmenu=Id("mainmenu");
	mainmenu.insertBefore(js_menu,Tag(mainmenu,"dt")[3]);
	
	over("mainmenu",877,10);//overflow
	over("secondmenu",877,10);//overflow
	
	var ctsorts=Tag(Id("ctlist"),"a");
	var t1=Tag(Id("title1"),"a")[0];
	var desp1=Tag("h2")[0]; // wjn
	//var desp1=Tag(Id("desp1"),"span")[0];
	//var key1=Id("key1");
	for(var i=1;i<ctsorts.length;i++)
	{
		while(ctsorts[i].offsetWidth>192)
		{
			var size=Style(ctsorts[i],"fontSize");
			size=parseInt(size)-1;
			ctsorts[i].style.fontSize=size+"px";
		}
	}
	while(t1.offsetWidth>188)
	{
		var size=Style(t1,"fontSize");
		size=parseInt(size)-1;
		t1.style.fontSize=size+"px";
	}
	while(desp1.offsetWidth>620)
	{
		var size=Style(desp1,"fontSize");
		size=parseInt(size)-1;
		desp1.style.fontSize=size+"px";
	}
	/*key1.innerHTML="<span>"+key1.innerHTML+"</span>";
	var span_key1=Tag(key1,"span")[0];
	while(span_key1.offsetWidth>430)
	{
	var size=Style(span_key1,"fontSize");
	size=parseInt(size)-1;
	span_key1.style.fontSize=size+"px";
	}*/

	Id("lang").onmouseover=function(){this.style.cursor="pointer";Id("trans").style.visibility="visible";}
	Id("lang").onclick=stopBubble;
	document.onclick=function(){Id("trans").style.visibility="hidden";}
	var trans=Tag(Id("trans"),"dd");

	
	for(var i=0;i<trans.length;i++)
	{
		trans[i].onmouseover=function(){this.style.cursor="pointer";}
		trans[i].onclick=function(){translator("en|"+this.id);};
	}

	var q=Id("q");
	var searchbut=Id("searchbut");
	q.onkeyup=function(e){var key=window.event?window.event.keyCode:e.which;if(key==13)searchbut.click();}
	if(q.value=="")q.value="search";
	q.onblur=function(){if(this.value=="")this.value="search";}
	q.onfocus=function(){if(this.value=="search")this.value="";}
	searchbut.onclick=function()
	{
		var num=document.location.href.lastIndexOf('/');
		var base=document.location.href.substring(0,num);
		document.location.href=base+"/search.php?q="+Id("q").value;
	}

	tables();

	if(Id("keywordlist"))Id("right").appendChild(Id("keywordlist"));

	wholebg=document.createElement("div");
	wholebg.id="wholebg";
	wholebg.style.height=Id("whole").offsetHeight+"px";
}
window.onload=function()
{
	Tag("body")[0].appendChild(wholebg);
}
