// JavaScript Document
document.write("<style type=\"text/css\">"); 
document.write("#sresult{filter:Alpha(Opacity=90);}");
document.write("</style>"); 

$(function(){
		  $("#logoBack").append("<span id=\"sresult\"><img src=\"../images/lightbox-ico-loading.gif\" width=\"24\" height=\"24\" alt=\"searching...\" /></span>");

		  $("#frmsearch").submit(function(){searchinput();return false;});
		  $("searchGo").click(function(){searchinput();return false;});

		$("#searchArea").click(function(){
			if ($("input[name='keywords']").val() == "keywords"){
			$("input[name='keywords']").val("");
			}
		});

		   $("#search").css("opacity","0.8");
		   $("#product ul li span").css("opacity","0.8");

		   $("#product ul li > img").hover(function(){
				$(this).next("span").css("background-color","#FF7200");
			   },function(){
				$(this).next("span").css("background-color","#4c4c4c");
		   });

		   $("#product ul li img").click(function(){
					$(this).parents("#product ul li").children("div").slideToggle(600);
			});
		   $("#product ul li div").mouseleave(function(){
					$(this).parents("#product ul li").children("div").slideToggle(400);
			}); 

	nav = $("#menu > ul");
    var rootli = nav.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"));
		}
	});

	$("#honor ul li a").hover(function(){
		$(this).parent().css("background-position","0 -54px");
		},function(){
		$(this).parent().css("background-position","0 8px");
	});
	$("#down ul li a").hover(function(){
		$(this).parent().css("background-position","0 -48px");
		},function(){
		$(this).parent().css("background-position","0 7px");
	});

	$("#menu ul li ul li:last-child a").addClass("last");
	$("#menu ul li:has(ul)").hover(function(){
      	  if($(this).children("ul").eq(0).children("li").length > 1){$(this).children("ul").stop(true,true).slideDown();}
		  $(this).children("a").eq(0).addClass("ac");
		    },function(){
		  if($(this).children("ul").eq(0).children("li").length > 1){$(this).children("ul").stop(true,true).slideUp("fast");}
		  $(this).children("a").eq(0).removeClass("ac");
	});

		 var len  = $("#flashNum > li").length;
		 var index = 0;
		 var adTimer;
		 $("#flashNum li").click(function(){
			index  =   $("#flashNum li").index(this);
			showImg(index);
		 }).eq(0).click();	
		 //滑入 停止动画，滑出开始动画.
		 $('#flashGif').hover(function(){
				 clearInterval(adTimer);
			 },function(){
				 adTimer = setInterval(function(){
					showImg(index)
					index++;
					if(index==len){index=0;}
				  } , 4000);
		 }).trigger("mouseleave");

        var $this = $("#activeContent");
		var scrollTimer;
		$this.hover(function(){
			  clearInterval(scrollTimer);
		 },function(){
		   scrollTimer = setInterval(function(){
						 scrollNews( $this );
					}, 5000 );
		}).trigger("mouseleave");

	//图集灯箱效果
	if ($("ul.list1").length > 0) {	$("ul.list1 li a.thumb").lightBox();}
	if ($("ul.list2").length > 0) {	$("ul.list2 li a.thumb").lightBox();}

});


function showImg(index){
		$("#flashSlider li").eq(index).stop(true,false).animate({opacity:"show"},1000)
		                      .siblings().hide();
         $("#flashNum li")
			.eq(index).animate({bottom:"10px",opacity:"1"},400).css("border","1px solid #fff")
			.siblings().animate({bottom:0,opacity:"0.4"},400).css("border","1px solid #000");
}

function scrollNews(obj){
   var $self = obj.find("ul:first"); 
   var lineHeight = $self.find("li:first").height(); //获取行高
         $self.animate({ "marginTop" : -lineHeight +"px" }, 600 , function(){
         $self.css({marginTop:0}).find("li:first").appendTo($self); //appendTo能直接移动元素
   })
}

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") == "keywords"){
		alert("PLZ input keywords");
		$("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=\"searching...\" />");
		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.');}
		}	
	}
}
