﻿function toggle(tabName, contentName, maxLength, currentIndex) {
	for (i = 1; i <= maxLength; i++) {
		$('#' + tabName + i)[0].className = '';
	}
	$('#' + tabName + currentIndex)[0].className = 'now';

	for (i = 1; i <= maxLength; i++) {
		$('#' + contentName + i)[0].style.display = 'none';
	}
	$('#' + contentName + currentIndex)[0].style.display = 'block';
}

function goTop(acceleration, time) {
	acceleration = acceleration || 0.1;
	time = time || 16;

	var dx = 0;
	var dy = 0;
	var bx = 0;
	var by = 0;
	var wx = 0;
	var wy = 0;

	if (document.documentElement) {
		dx = document.documentElement.scrollLeft || 0;
		dy = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		bx = document.body.scrollLeft || 0;
		by = document.body.scrollTop || 0;
	}
	var wx = window.scrollX || 0;
	var wy = window.scrollY || 0;

	var x = Math.max(wx, Math.max(bx, dx));
	var y = Math.max(wy, Math.max(by, dy));

	var speed = 1 + acceleration;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if (x > 0 || y > 0) {
		var invokeFunction = "MGJS.goTop(" + acceleration + ", " + time + ")"
		window.setTimeout(invokeFunction, time);
	}
}


window['MGJS'] = {};
//window['MGJS']['$'] = $;
window['MGJS']['goTop'] = goTop;

function bindClick() {	/*			
	$("#ulHead li a:eq(1)").bind("click",function(){
		var k = $("#q")[0].value;
		k = $.trim(k);
		if (k != "") {
			if ($.cookie("prodhistory") == null) {
				$.cookie("prodhistory", k + ",", { expires: 7, path: '/' });
			} else {
				var c = $.cookie("prodhistory").replace(k + ",", "") + k + ",";
				$.cookie("prodhistory", c, { expires: 7, path: '/' });
			}
			location.href = "http://www.xumuj.com/" + k + "/---------------------.htm";
		}else
		{
			location.href="http://www.xumuj.com/productshome.shtml";
		}
	});
	
	$("#ulHead li a:eq(2)").bind("click",function(){
		var k = $("#q")[0].value;
		k = $.trim(k);
		if (k != "") {
			if ($.cookie("comhistry") == null) {
				$.cookie("comhistry", k + ",", { expires: 7, path: '/' });
			} else {
			var c = $.cookie("comhistry").replace(k + ",", "") + k + ",";
				$.cookie("comhistry", c, { expires: 7, path: '/' });
			}
			location.href = "http://www.xumuj.com/CompanySearch/" + k + "--------------.htm";
		}
		else
		{
			location.href="http://www.xumuj.com/companyshome.shtml";		
		}
	});
	
	$("#ulHead li a:eq(3)").bind("click",function(){
		var k = $("#q")[0].value;
		k = $.trim(k);
		if (k != "") {
			if ($.cookie("offhistory") == null) {
				$.cookie("offhistory", k + ",", { expires: 7, path: '/' });
			} else {
				var c = $.cookie("offhistory").replace(k + ",", "") + k + ",";
				$.cookie("offhistory", c, { expires: 7, path: '/' });
			}
			location.href = "http://www.xumuj.com/BizInfo/" + k + "-----------------.htm";
		}else
		{			
			location.href="http://www.xumuj.com/offershome.shtml";
		}
	});
	
	$("#ulHead li a:eq(4)").bind("click",function(){
		var k = $("#q")[0].value;
		k = $.trim(k);
		if (k != "") {
			if ($.cookie("bizhistory") == null) {
				$.cookie("bizhistory", k + ",", { expires: 7, path: '/' });
			} else {
				var c = $.cookie("bizhistory").replace(k + ",", "") + k + ",";
				$.cookie("bizhistory", c, { expires: 7, path: '/' });
			}
			location.href = "http://www.xumuj.com/ProductAgent/" + k + "---------------------------.htm";
		}else
		{
			location.href="http://www.xumuj.com/bizinfoshome.shtml";			
		}				
	});*/
}

//设置下拉分类
function setDdlType(type, cate) {
	//显示隐藏的下拉列表
	document.getElementById("ddlType").style.display = "";
	if (type != "") {
		$("#ddlType option[value='" + type + "']").attr("selected", true);
		$("#subnavi ul li a[type='" + type + "']").addClass("now");
	}
	else {
		//选择所选择的分类
		$("#ddlType option[value='" + cate + "']").attr("selected", true);
		$("#subnavi ul li a[cate='" + cate + "']").addClass("now");

	}
}
