document.write("<style type=\"text/css\">"); 
document.write("#sresult{filter:Alpha(Opacity=90);display:none}");
document.write("</style>"); 
document.write("<span id=\"sresult\"><img src=\"../images/loadingsearch.gif\" width=\"16\" height=\"16\" alt=\"正在搜索...\" /></span>");

$(function() {

	if( !$("body").hasClass("p00") &&  !$("body").hasClass("p01") ) {
		document.getElementById("l_flash").innerHTML = fplay("../images/en" + $("body").attr("className").substring(1,3) + ".swf","783","114");
	}
    if($(".p01").length > 0 && document.getElementById("pd_flash")) {
		document.getElementById("pd_flash").innerHTML = fplay("../images/en01.swf","690","151");
   }
    if($(".p00").length > 0 && document.getElementById("flash")) {
		document.getElementById("flash").innerHTML = fplay("../images/enhome.swf","953","251");
   }

	if(!$("body").hasClass("p00")){$("#mid>ul.left").css("height",$("#mid")[0].offsetHeight-30);}     //高度对齐；
	//产品图集灯箱效果
	if ($("ul.list1").length > 0) {
		$("ul.list1 li a").lightBox();
	}

	$("#frmsearch").submit(function(){searchinput();return false;}); 

if($("body").hasClass("p00")) {
	var win = $(".slide");
	var tar_li = $(".slide > ul > li");
	var length = tar_li.length;
	
	var stepInter;
	stepInter = 39;
	var step = 0;

	var ul = win.children("ul");
	var new_li = tar_li.eq(0).clone();		
	ul.append(new_li);				//多一个；

	var timeCon = setInterval(timeRun = function() {
		if(step == 0) {
			ul.css("marginTop", "0");
		}
		step = step - stepInter;
		ul.animate({marginTop: step});
		if(step <= -stepInter * length) {				//移动四次就轮回了，然后迅速margin清零。视觉差。
			step = 0;
		}
	}, 3000);

	win.hover(function() {
		clearInterval(timeCon);
	}, function() {
		timeCon = setInterval(timeRun, 3000);
	});

/* ===================================== */
	$(".essay > li > ul > .first").before("<div class='tp'>");
	
	var essay_li = $(".essay > li");
	essay_li.find("div.tp").eq(1).css("backgroundColor", "#a6cc42");
	essay_li.find("div.tp").eq(2).css("backgroundColor", "#025a9a");
	if($.browser.mozilla) essay_li.find("div.tp").css("marginTop", 0);
	
	var time;
	essay_li.hover(function() {
		var this_li = $(this);
		time = setTimeout(function() {
			this_li.children("ul").animate({"marginTop": 0}, 300);
		}, 300);
	}, function() {
		clearTimeout(time);
		$(this).children("ul").animate({"marginTop": 105}, 300);
	});

/* ================= */
	var p_a = $(".product > li > a").not(".detail");
	var p_div;
	
	p_a.hover(function() {
		p_div = $(this).parent().children("div");
		if($(this).hasClass("i0")) {
			p_div.eq(0).css("zIndex", 2);
			p_div.eq(1).css("zIndex", 1);
		} else {
			p_div.eq(0).css("zIndex", 1);
			p_div.eq(1).css("zIndex", 2);
		}
		
		$(this).css("background", "url(../images/pd_tri.png) no-repeat top left");
		if($(this).nextAll().filter("a").not(".detail").hasClass("i1")) {
			var oth_a = $(this).nextAll().filter("a").not(".detail");	
		} else {
			oth_a = $(this).prevAll().filter("a");	
		}
		oth_a.css("background", "url(../images/blue_tri.gif) no-repeat top left");
	}, function() {
	});

}		/* p00 over */

/* ===============p03================ */
	if($("body").hasClass("p01")) {
		var record = -1;
		var aa_record = -1;
		
		var nav2_a = $("#mid > ul.left > li > a");
		
		nav2_a.click(function() {
			if(record == -1) {												//record为-1：无收缩，展开this，记录新record；
				$(this).next("ul").addClass("over");
				record = $.inArray(this, $.makeArray(nav2_a));
			} else {
				if($.inArray(this, $.makeArray(nav2_a)) != record) {		//record不相同：收缩record，展开this，记录新record；（record不为-1情况下）；
					nav2_a.eq(record).next("ul").removeClass("over");
					
					$(this).next("ul").addClass("over");
					record = $.inArray(this, $.makeArray(nav2_a));
				} else if($.inArray(this, $.makeArray(nav2_a)) == record) {	//record相同：收缩this，不展开，不记录（-1化）；（record不为-1情况下）；
					$(this).next("ul").removeClass("over");
					record = -1;
				}
			}			
		});
		
		var aa = nav2_a.next("ul").children("li").children("a");
		aa.click(function() {
			if(aa_record == -1) {												//record为-1：无收缩，展开this，记录新record；
				$(this).next("ul").addClass("over");
				aa_record = $.inArray(this, $.makeArray(aa));
			} else {
				if($.inArray(this, $.makeArray(aa)) != aa_record) {		//record不相同：收缩record，展开this，记录新record；（record不为-1情况下）；
					aa.eq(aa_record).next("ul").removeClass("over");
					
					$(this).next("ul").addClass("over");
					aa_record = $.inArray(this, $.makeArray(aa));
				} else if($.inArray(this, $.makeArray(aa)) == aa_record) {	//record相同：收缩this，不展开，不记录（-1化）；（record不为-1情况下）；
					$(this).next("ul").removeClass("over");
					aa_record = -1;
				}
			}			
		});

		var ac = $("#mid > ul.left > li > ul > li > a.ac");
		ac.parent("li").parent("ul").show();
	}
	
	
});

function fplay(swf,swfwidth,swfheight)
{
	if(navigator.userAgent.indexOf('Firefox')>-1)
	{return('<embed src="'+swf+'" width="'+ swfwidth +'" height="'+ swfheight + '" quality="high" wmode="window" menu="false"></embed>')}
	else
	{
		return('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+ swfwidth +'px" height="'+ swfheight + 'px"><param name="movie" value="'+swf+'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="window" /></object>')
	}
}

function trim(a_strVarContent) {
var pos1, pos2, newstring;pos1 = 0;pos2 = 0;newstring = "";
	if ( a_strVarContent.length > 0 ) {
		for( i=0; i<=a_strVarContent.length; i++) { 
			if ( a_strVarContent.charAt(i) == " " ) pos1 = pos1 + 1;
			else break;
		} 
		for( i=a_strVarContent.length; i>=0 ; i--) {
			if ( a_strVarContent.charAt(i) == " " ) pos2 = pos2 + 1;
			else break;
		}
		newstring = a_strVarContent.substring(pos1, a_strVarContent.length-pos2) 
	} 
	return newstring; 
} 

function searchinput(){
	if ($("input[name='keywords']").attr("value") == ""){
		alert("Please input keywords...");
	    $("input[name='keywords']").focus();
    }else{
		$("input[name='keywords']").attr("value",trim($("input[name='keywords']").attr("value")));
		$("#sresult").css("display","block");
		$("#sresult").html("<img src=\"../images/loadingsearch.gif\" width=\"16\" height=\"16\" alt=\"searching...\" />");
		showrequest("search_ajax.asp?keywords=" + escape($("input[name='keywords']").attr("value")),"sresult",false);
		cls_button();
	}
}

function searchp(keywords,r,p,ttype){
	showrequest("search_ajax.asp?keywords=" + keywords + "&r=" + r + "&p=" + p + "&type=" + ttype,"sresult",false);cls_button();
	return false;
}

function cls_button(){
	nCol = $("#sresult > A");
	for (i=0;i<nCol.length;i++){
		if (nCol[i].className == "cls"){
			nCol[i].onclick = function(){
				this.parentNode.style.display = "none";
			}
		}
	}
}

var http_request = false;
function showrequest(url,element,asyn) {
	var isFFCLS = true;
	http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {alert('Giving up :( Cannot create an XMLHTTP instance');return false;}
    http_request.onreadystatechange = sub_showrequest;
    http_request.open('GET', url, asyn);
    http_request.send(null);
	if ((!asyn) && (isFFCLS)) sub_showrequest();
	function sub_showrequest(){
	    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			isFFCLS = false;
			document.getElementById(element).innerHTML = http_request.responseText;
        } else {alert('There was a problem with the request.');}
		}	
	}
}
