document.write("<style type=\"text/css\">"); 
document.write("#sresult{filter:Alpha(Opacity=90);}");
document.write("</style>"); 

$(function(){
	$("#search").append("<span id=\"sresult\"><img src=\"images/lightbox-ico-loading.gif\" width=\"24\" height=\"24\" alt=\"正在传送数据...\" /></span>");
	$("#frmsearch").submit(function(){searchinput();return false;});
	$("searchGo").click(function(){searchinput();return false;});
	$("#searchArea").click(function(){
		if ($("input[name='keywords']").val() == "关键词"){
		$("input[name='keywords']").val("");
		}
	});

	$("#menu > ul > li >ol").css("opacity","0.9");
	$("#news h3").mouseover(function(){
		$(this).css({"background-color":"#006cde","color":"#fff"});
		$(this).siblings("h3").css({"background-color":"#add0f4","color":"#000"});
		$("#news div:visible").stop(true,true).slideUp("slow");
		$(this).next("div").stop(true,true).slideDown("slow");
    });

    var rootli = $("#menu > ul > li > ol > li > ol > li > ol > li > ol").children("li");
	rootli.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});

    var rootli = $("#menu > ul > li > ol > li > ol > li > ol").children("li");
	rootli.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});

    var rootli = $("#menu > ul > li > ol > li > ol").children("li");
	rootli.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});

	var rootli = $("#menu > ul > li > ol").children("li");
	rootli.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});
	rootli = $("#menu > ul").children("li");
	rootli.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});


	$("#menu ul li ul#menuThree li").eq(0).children("span").show();
	$("#menu > ul > li").hover(function(){
      	  $(this).children("ol").stop(true,true).slideDown();
		 },function(){
		  $(this).children("ol").stop(true,true).slideUp("fast");
	});
	$("#menu02").hover(function(){
      	  $(this).addClass("menu02Hover");
		 },function(){
		 $(this).removeClass("menu02Hover");
	});
	$("#menu03").hover(function(){
      	  $(this).addClass("menu03Hover");
		 },function(){
		 $(this).removeClass("menu03Hover");
	});
	$("#menu04").hover(function(){
      	  $(this).addClass("menu04Hover");
		 },function(){
		 $(this).removeClass("menu04Hover");
	});
	$("#menu05").hover(function(){
      	  $(this).addClass("menu05Hover");
		 },function(){
		 $(this).removeClass("menu05Hover");
	});
	$(".productList img").hover(function(){
      	  $(this).css({"width":"100px","height":"62px"});
		 },function(){
		  $(this).css({"width":"95px","height":"60px"});
	});
	$("#agency a").hover(function(){
      	  $(this).prev("img").css({"width":"40px","height":"42px"});
		 },function(){
		  $(this).prev("img").css({"width":"36px","height":"39px"});
	});
	$("#phone a").hover(function(){
      	  $(this).prev("img").css({"width":"25px","height":"27px"});
		 },function(){
		  $(this).prev("img").css({"width":"23px","height":"25px"});
	});
	$("#cooperation ul li a").hover(function(){
      	  $(this).next("span").stop(true,true).slideDown();
		 },function(){
		  $(this).next("span").stop(true,true).slideUp("fast");
	});
	$("#friendship a").mouseover(function(){
      	  $("#friend").fadeIn();
		  return false;
	});
	$("#friend").mouseleave(function(){
      	  $(this).fadeOut();
	});

	$("#close").click(function(){
      	  $(this).parents("#friend").fadeOut();
	});
	var len = $("#product > ul > li").length;
    var index = 0;
	var adTimer;
	$("#product ul li").mouseover(function(){
		index  =   $("#product ul li").index(this);
		showImg(index);
	 }).eq(0).mouseover();
	$("#product").hover(function(){
					clearInterval(adTimer);
			},function(){
				adTimer = setInterval(function(){
				  showImg(index)
				  index++;
				  if(index==len){index=0;}
				},4000);
			}).trigger("mouseleave");

     $("#pmenu ul li:has(ol)").hover(function(){$(this).children("ol").eq(0).stop(true,true).show();}		,function(){$(this).children("ol").eq(0).stop(true,true).hide();}
	 );

    rootli2 = $("#pmenu > div > ul").children("li");
	rootli2.each(function() {
		var childA = $(this).children("a");
		if(childA.attr("href").indexOf(":") > 0) {
			childA.attr("href", $("li:eq(0)>a", childA.next()).attr("href"));
		}
	});

    if($("body").attr("id") != "P00" && document.getElementById("flash") ) {document.getElementById("flash").innerHTML = fplay("images/flash.swf","975","109");}
	if ($("ul.list1").length > 0) {	$("ul.list1 li a.thumb").lightBox();	}
	if ($("ul.list2").length > 0) {	$("ul.list2 li a.thumb").lightBox();	}

  /* ---------------media--------------------- */
    if ($("#media").length > 0) {
        var ml = 0;                                             //当前 marginLeft 是 0；

        var win = $("#win");
        win.before("<img class='left' src='images/turn_left.gif' width='9' height='51'>");
        win.after("<img class='right' src='images/turn_right.gif' width='9' height='51'>");
		var winli = $("li", win);
        
/*0701*/if(winli.length > 4) {
            win.next().css("visibility", "visible");
        }

        var img_btn = $("#media").find(".slide_pl").find("img").not(".point").not(".min_scr");

        var rec = 1;
        img_btn.click(function() {
            var tar_ul = $(this).parent().children("#win").children("ul");
            if (this.className == "left") {
                if (rec > 1) {
                    ml = ml + 98;
                    tar_ul.animate({marginLeft: ml}, 800);

                    if (rec == 2) {
                        win.prev().css("visibility", "hidden");
                    }
                    win.next().css("visibility", "visible");    
                    rec--;
                }
            } else {
                if (rec <= tar_ul.children("li").length - 4) {
                    ml = ml - 98;
                    tar_ul.animate({marginLeft: ml}, 800);

                    win.prev().css("visibility", "visible");
                    if (rec == tar_ul.children("li").length - 4) {
                        win.next().css("visibility", "hidden");   
                    }
                    rec++;
                }
            }
        });

        var img_scr = $("#media").find(".min_scr");
        var img_pt = $("#media").find(".point");
        var title = $("#media > ul > .avi_txt > .title");
        var txt = title.next();

        title.text(img_scr.eq(0).next().next().text());
        txt.text(img_scr.eq(0).next().next().next().text());

        img_scr.click(function() {
            var cur = $(this);
//[0701]
            var rel = $("img", cur).attr("rel"); 
            var adr = "images/media.swf?media="+rel;
            cur.parent().append(img_pt);

            var cur_title = cur.nextAll(".title").text();
            var cur_txt = cur.nextAll(".txt").text();
            title.text(cur_title);
            txt.text(cur_txt);

            document.getElementById("flashcontent").innerHTML = fplay(adr,"480","360","full");
        });
        
        //初始化指向。
        winli.eq(0).append(img_pt);

        //页面加载自动播放。
        var adr_rel = $("img", winli.eq(0)).attr("rel");        //获取第一个视频的 rel。
        var adr = "images/media.swf?media="+adr_rel;
        document.getElementById("flashcontent").innerHTML = fplay(adr,"480","360","full");  //不需要判断了。
    }


})

function showImg(index){
		$("#product ol li").eq(index).stop(false,true).fadeIn(400).siblings().hide();
        $("#product ul li").eq(index).css("background","url(images/product_02.png) no-repeat").siblings().css("background","url(images/product_01.png) no-repeat");
}


function fplay(swf, swfwidth, swfheight,full) {
    if (navigator.userAgent.indexOf('Firefox') > - 1) {
		if (full == "full"){
	        return('<embed src="' + swf + '" width="' + swfwidth + '" height="' + swfheight + '" quality="high" wmode="Opaque" allowFullScreen="true" allowScriptAccess="always"></embed>');
		}else{
        return('<embed src="' + swf + '" width="' + swfwidth + '" height="' + swfheight + '" quality="high" wmode="transparent"></embed>');}
    } else {
		if (full == "full"){
			return('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + swfwidth + '" height="' + swfheight + '"><param name="movie" value="' + swf + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="Opaque" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>');
		}else{
        return('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + swfwidth + '" height="' + swfheight + '"><param name="movie" value="' + swf + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="transparent" /></object>');}
    }
}

function searchinput(){
	if ($("input[name='keywords']").attr("value") == "" || $("input[name='keywords']").attr("value") == "关键词"){
		alert("请输入关键词");
		$("input[name='keywords']").val("");
	    $("input[name='keywords']").focus();
		return false;
    }else{
		$("input[name='keywords']").attr("value",trim($("input[name='keywords']").attr("value")));
		$("#sresult").css("display","block");
		$("#sresult").html("<img src=\"images/lightbox-ico-loading.gif\" width=\"24\" height=\"24\" alt=\"正在传送数据...\" />");

		showrequest("search_ajax.asp?keywords=" + encodeURIComponent(escape($("input[name='keywords']").attr("value"))),"sresult",false);
		cls_button();
	}
}

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 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.');}
		}	
	}
}
