function translator(pattern) {
	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 over(sender,maxwid,minpad)//over-flow
{
	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";
	}
}

//Start Run
init();
function init()
{
	try{document.execCommand("BackgroundImageCache",false,true);}catch(e){}
	over("mainmenu",550,10);//overflow
	over("secondmenu",560,10);//overflow
/*
	var cur=Tag(Id("ctlist"),"h3");
	for(var i=0;i<cur.length;i++){
		if(cur[i].previousSibling){
			cur[i].previousSibling.innerHTML="<strong class='current'>"+cur[i].innerHTML+"</strong>";
			cur[i].parentNode.removeChild(cur[i]);
		}
		else{
			 var txt=cur[i].innerHTML;
			cur[i].parentNode.innerHTML="<strong class='current'>"+txt+"</strong>";
		}
	}
	var ctb=Tag(Id("ctlist"),"dt");
	for(var i=0;i<ctb.length;i++){
		var obj=ctb[i].firstChild;
		while(obj.offsetWidth>162){
			var size=Style(obj,"fontSize");
			size=parseInt(size);
			obj.style.fontSize=size-1+"px";
		}
	}
	var cts=Tag(Id("ctlist"),"dd");
	for(var i=0;i<cts.length;i++){
		var obj=cts[i].firstChild;
		while(obj.offsetWidth>154){
			var size=Style(obj,"fontSize");
			size=parseInt(size);
			obj.style.fontSize=size-1+"px";
		}
	}
*/
	var title1=Tag(Id("title1"),"a")[0];
	var title2=Tag(Id("title2"),"a")[0];
	while(title1.offsetWidth>170)
	{
		var size=Style(title1,"fontSize");
		size=parseInt(size);
		title1.style.fontSize=size-1+"px";
	}
	while(title2.offsetWidth>160)
	{
		var size=Style(title2,"fontSize");
		size=parseInt(size);
		title2.style.fontSize=size-1+"px";
	}

	var lang=Id("lang");
	var tran=Id("trans");
	lang.onmouseover=function(){this.style.cursor="pointer";tran.style.visibility="visible";}
	lang.onclick=stopBubble;
	document.onclick=function(){tran.style.visibility="hidden";}
	var trans=Tag(tran,"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();}
	searchbut.onclick=function()
	{
		var num=document.location.href.lastIndexOf('/');
		var base=document.location.href.substring(0,num);
		document.location.href=base+"/search.php?q="+q.value;
	}

	tables();
}


function $A(iterable) {
	var results = [];
	for (var i = 0; i < iterable.length; i++) results.push(iterable[i]);
	return results;
}

Function.prototype.bind = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	};
};

function flipMenu(flipObj){
	this.flipObj = flipObj;
	this.initialize();
}

flipMenu.prototype = {
	initialize: function(){
		this.getaim;
		this.timeout;
		this.aimPos = this.flipObj.aimTagPos;
		this.alpha = parseFloat(this.flipObj.opacity);
		this.freq = parseInt(this.flipObj.frequency);
		this.getflip = this.getNodeById(this.flipObj.flipMenuId);

		var getanchor = this.getNodeById(this.aimPos.idarr).getElementsByTagName(this.aimPos.tagarr);
		for(a = 0; a < getanchor.length; a++){
			if(eval("getanchor[a]." + this.aimPos.paraname + ".indexOf('" + this.aimPos.paravalue + "')") != -1){
				this.getaim = getanchor[a];
				break;
			}
		}

		if(!this.getaim) return;
		
		var obj = this;
		this.getaim.onmouseover = function(){
			clearTimeout(obj.timeout);
			var aimleft = obj.getaim.offsetLeft;
			var aimtop = obj.getaim.offsetTop;

			// As the layer's position is set absolute, the FF browser need to calculate all the layer's position
			//if(obj.checkNav("MSIE 6") || obj.checkNav("MSIE 7")){
				aimleft = obj.nodeRecursion(obj.getaim, "parentNode", "offsetLeft");
				aimtop = obj.nodeRecursion(obj.getaim, "parentNode", "offsetTop");
			//}

			obj.getflip.style.position = "absolute";
			obj.getflip.style.left = aimleft + parseInt(obj.flipObj.offset.x) + "px";
			obj.getflip.style.top = aimtop + parseInt(obj.flipObj.offset.y) + "px";

			obj.opacity(obj.getflip, obj.alpha);
			obj.getflip.style.display = "block";
		};

		this.getaim.onmouseout = function(){
			obj.changeOpacity(obj.getflip, obj.alpha, obj.freq);
		};

		this.getflip.onmouseover = function(){
			clearTimeout(obj.timeout);
			obj.opacity(this, obj.alpha);
			this.style.display = "block";
		};

		this.getflip.onmouseout = function(){
			obj.changeOpacity(obj.getflip, obj.alpha, obj.freq);
		};
	},

	opacity: function(flipObj, percent){
		if(document.all) flipObj.style.filter = "Alpha(opacity=" + percent * 10 + ")";
		else flipObj.style.opacity = percent / 10;
	},

	changeOpacity: function(flipObj, percent, freq){
		if(percent > 0){
			freq = freq / 2;
			this.opacity(flipObj, --percent);
			this.timeout = setTimeout(this.changeOpacity.bind(this, flipObj, percent, freq), freq);
		}
		else flipObj.style.display = "none";
	},

	checkNav: function(ver){
		var nav = navigator.userAgent.indexOf(ver);
		if(nav == -1) return false;
		else return true;
	},

	nodeRecursion: function(tobj, tarnodes, nodepro){
		var provalue;
		if(!provalue) provalue = 0;

		try {
			tobj = eval("tobj." + tarnodes);
			provalue = this.nodeRecursion(tobj, tarnodes, nodepro);
		}
		catch (e){}
		var temp = eval("tobj." + nodepro);
		temp = parseInt(temp);
		if(!isNaN(temp)){
			if(tobj.tagName && this.checkNav("MSIE 6")){
				var tname = tobj.tagName.toLowerCase();
				if((tname == "dt") || (tname == "li")){
					//provalue -= eval("tobj." + tarnodes + "." + nodepro);
				}
			}
			provalue += temp;
		}
		return provalue;
	},
	
	getNodeById: function(idname){
		var tags;
		var bodyhtml = document.body.innerHTML;
		var reg = new RegExp("<(\\w*)([^>]*) id=([\'\"]?)" + idname + "\\3(>| [^>]+>)", "i");
		bodyhtml.replace(reg, function(){ tags = arguments[1]; });

		var getags = document.getElementsByTagName(tags);
		for(i = 0; i < getags.length; i++){
			if(getags[i].id == idname){
				return getags[i];
			}
		}
	}
}

var flipObj = {
	aimTagPos: {idarr: "mainmenu", tagarr: "a", paraname: "href", paravalue: "products.html"},
	flipMenuId: "flipmenu",
	offset: {x: "0", y: "40"},
	opacity: "9.5",
	frequency: "200"
};

new flipMenu(flipObj);
