$(function(){
    //注册左边导航展开事件
	leftNavOpen();
	//注册改变字体事件
	changeFontSize("#divContent");
	//自动向上滚动
	autoScroll();
	//展区-鼠标移过事件
	exhi_area_hover();
	//banner事件
	//bannerHover("true",5);
	//首页搜索事件
	indexSearch();
	//首页->区域经济 切换事件
	economyHover("true",10);
	//进口展区->图片播放器 参数说明：id,图片宽度,是否自动播放,时间(单位为秒)
	ImgPlayer("imgPlayer",255,"true",6);
	//图片新闻->图片播放器
	ImgPlayer("imgPlayer1",155,"true",6);
	//现场图片->图片播放器
	ImgPlayer2();
	//导航
	navHover();
	//物流篇-鼠标移过弹出
 	hoverShow();
});

//1.加入收藏夹
function addFavorite(){
	var title=document.title
	var url=document.location.href
	if (window.sidebar) window.sidebar.addPanel(title, url,"");
	else if( window.opera  &&  window.print ){
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}
	else if( document.all ) window.external.AddFavorite( url, title);
}

//2.改变文章字体大小
function changeFontSize(content){
	$("#content_toolbar .contentFont>a").click(function(){
		var size = $(this).attr("size");
		$(content).css("font-size",size);
		return false;
	});
}

//3.左边导航展开事件
function leftNavOpen(){
	var lv1_a;
	var level2;
	var setTimeoutId;
	$("#menu .level1>li>.now").siblings(".level2").slideDown("fast");
	$("#menu .level1>li").hover(function(){
		lv1_a = $(this).children(".lv1_a");
		level2 = $(this).children(".level2");
		setTimeoutId=setTimeout(function(){
			if(!lv1_a.hasClass("now")){
				level2.slideDown("fast");
			}
		},200);

	},function(){
		clearTimeout(setTimeoutId);
		if(!lv1_a.hasClass("now")){
			level2.slideUp("fast");
		}
	});
}

//4.自动向上滚动
function autoScroll(){
	var _width = 146;
	var _height = 40;
	$("#telList>a:first").css("top",_height).css("left",0);
	$("body").everyTime("10s","autoscroll",function(){
		$("#telList>a:first").animate({
			top:0
		},1000);
		$("#telList>a:last").animate({
			top:"-"+_height
		},1000,"",function(){
			var lastObj = $("#telList>a:last").remove();
			lastObj.css("top",_height);
			$("#telList").prepend(lastObj);
		});
	});
}

//5.展区-鼠标移过事件
function exhi_area_hover(){
	var num = 1;
	var imgSrc = "";
	var setTimeoutId;
	$("#exhi_area .title>a:first").addClass("hover");
	$("#exhi_area .title a").hover(function(){
		var $this = $(this);
		num = $this.attr("num");
		imgSrc = "url(../images/exhibitor/zq_state"+num+".gif) no-repeat";
		if(!$this.hasClass("hover")){
			setTimeoutId = setTimeout(function(){
				$("#exhi_area .title>a.hover").removeClass("hover");
				$this.addClass("hover");
				$("#exhi_area .title").css("background",imgSrc);
				$("#exhi_area .cont").css("display","none");
				$("#exhi_area_"+num).css("display","block");	
			},100);
		}
	},function(){
		clearTimeout(setTimeoutId);
	});
}

function exhi_page_hover(id){
	var setTimeoutId;
	var $exhi_area = $("#"+id);
	$exhi_area.children("ul:first").css("display","block");
	$exhi_area.children(".page").children("a:first").addClass("now");
	$exhi_area.children(".page").children("a").hover(function(){
		var $this = $(this);
		if(!$this.hasClass("now")){
			 setTimeoutId = setTimeout(function(){
				 $exhi_area.children(".page").children(".now").removeClass("now");
				 $this.addClass("now");
				 $exhi_area.children("ul").css("display","none");
				 $exhi_area.children("ul").eq($this.index()).css("display","block");
			 },100);
		}
	},function(){
		clearTimeout(setTimeoutId);
	}).click(function(){ return false;});
}

//6.加载flash
function LoadSwf(id) {
	var swfBox = $("#"+id);
	try {
		var _swfUrl = swfBox.attr("swfUrl");
		var _swfW = isNaN(swfBox.attr("width"))?"100%":swfBox.attr("width");
		var _swfH = isNaN(swfBox.attr("height"))?"100%":swfBox.attr("height");
		var so = new SWFObject(_swfUrl, id, _swfW,_swfH, 8);
		so.addParam("menu", "false");
		so.addParam("wmode", "transparent");
		so.addParam("scale", "noBorder");
		//so.addParam("scale","noscale");
		//so.addParam("scale","showAll");
		//so.addParam("scale","exactFit");
		so.write(id);
	} catch (error) {}
}

//7.banner事件
//isAuto:是否自动播放 second:时间间隔（单位：s）
function bannerHover(isAuto,second){
	isAuto = false;
	var setTimeoutId;
	var isFinish =true;
	$("#banner .list li a").click(function(){ return false;});
	init();	
	$("#banner .list li").hover(function(){
		var li = $(this);		
		if(!li.hasClass("hover") && isFinish){
			setTimeoutId = setTimeout(function(){
				isFinish = false;
				$("#banner .list .hover").removeClass("hover");
				li.addClass("hover");
				$("#banner .imgBox a").attr("href",li.children("a").attr("href")).attr("title",li.children("a").attr("title"));
				$("#banner .imgBox a").children("img:first").attr("src",li.children("a").attr("src"));
				$("#banner .imgBox a").children("img:last").animate({
					opacity:0
				},500,"",function(){
					isFinish = true;
					var lastObj =$("#banner .imgBox a").children("img:last").remove();
					lastObj.css("opacity",1);
					$("#banner .imgBox a").prepend(lastObj);
				});			
			},200);
		}
	},function(){
		clearTimeout(setTimeoutId);
	});
	if(isAuto == "true"){
		if(typeof second != "number" || second<1) second = 5;
		$("#banner").everyTime(second+"s","bannerAuto",function(){
			var next_li = $("#banner .list .hover").next("li");
			if(isFinish){
				if(next_li.is("li")){
					next_li.trigger("mouseover");
				}else{
					$("#banner .list li:first").trigger("mouseover");
				};
			}
			
		});
	}
	$("#banner .imgBox").mouseover(function(){isFinish = false;}).mouseout(function(){isFinish = true;});
	
	function init(){
		$("#banner .list li:first").addClass("hover");
		var next_li = $("#banner .list .hover").next("li");
		var next_li_a = next_li.children("a");
		if($("#banner .imgBox a").children("img").length<=1 && next_li.is("li")){
			var newImg =$("<img />").attr("src",next_li_a.attr("src")).css("opacity",1);
			$("#banner .imgBox a").prepend(newImg);
		}
	}
}
//8.首页搜索事件
function indexSearch(){
	var setTimeoutId;
	$("#search>.list>a").hover(function(){
		var a = $(this);
		setTimeoutId = setTimeout(function(){
			$("#search>.list>a.hover").removeClass("hover");
			a.addClass("hover");
		},200);
		
	},function(){
		clearTimeout(setTimeoutId);
	});
	$("#search>.list>a").click(function(){ return false;});
}

//9.首页->区域经济 切换事件
function economyHover(isAuto,second){
	isAuto = isAuto || "true";
	var setTimeoutId;
	var isFinish = true;
	$("#economyMenu li").hover(function(){
		var li = $(this);
		var indexValue = li.index();
		if(!li.hasClass("hover")&&isFinish){
			isFinish = false;
			setTimeoutId = setTimeout(function(){
				if($("#economyItems>div").eq(indexValue).is("div")){
					$("#economyMenu .hover").removeClass("hover");
					li.addClass("hover");
					$("#economyItems>div").css("display","none");
					$("#economyItems>div").eq(indexValue).css("display","block");
				}
			},200);
		}
	},function(){
		isFinish = true;
		clearTimeout(setTimeoutId);
	});
	
	if(isAuto == "true"){
		if(typeof second != "number" || second<1) second = 5;
		$("#economy").everyTime(second+"s","economyAuto",function(){
			var next_li = $("#economyMenu .hover").next("li");
			if(next_li.is("li")){
				next_li.trigger("mouseover");
			}else{
				$("#economyMenu li:first").trigger("mouseover");
			};
			
		});
	}
	
	$("#economyItems").mouseover(function(){
		isFinish = false;
	}).mouseout(function(){
		isFinish = true;
	});
}
//10.图片播放器一
function ImgPlayer(imgPlayerId,moveWidth,isAuto,second){
	var $imgList = $("#"+imgPlayerId+" .imgList ul");
	var $prev = $("#"+imgPlayerId+" .prev");
	var $next = $("#"+imgPlayerId+" .next");
	var isFinish = true;
	isAuto = isAuto || "true";
	
	if(!$imgList.is("ul")) return;
	var length = $imgList.children("li").length;
	$("#imgPlayer .controls .all").text(length);
	$("#imgPlayer .controls .current").text(1);
	//计算出ul的宽度
	var _width = $imgList.children("li").length * moveWidth;
	$imgList.width(_width);
	$imgList.children("li:first").addClass("now");
		
	$prev.click(function(){
		if(isFinish){
			isFinish = false;
			var $now = $imgList.children(".now");
			var $prev_li = $now.prev("li");
			if($prev_li.is("li")){
				$now.removeClass("now");
				$prev_li.addClass("now");
				$("#imgPlayer .controls .current").text($prev_li.index() + 1);
				$imgList.animate({
					left:"+="+moveWidth
				},300,"",function(){isFinish = true;});
			}else{
				$imgList.children("li:last").addClass("now");
				$("#imgPlayer .controls .current").text(length);
				$imgList.animate({
					left:-(_width-moveWidth)
				},300,"",function(){isFinish = true;});
			}
		}
		return false;
	});
	$next.click(function(){
		if(isFinish){
			isFinish = false;
			var $now = $imgList.children(".now");
			var $next_li = $now.next("li");
			if($next_li.is("li")){
				$now.removeClass("now");
				$next_li.addClass("now");
				$("#imgPlayer .controls .current").text($next_li.index() + 1);
				$imgList.animate({
					left:"-="+moveWidth
				},300,"",function(){isFinish = true;});
			}else{
				$imgList.children("li:first").addClass("now");
				$("#imgPlayer .controls .current").text(1);
				$imgList.animate({
					left:0
				},300,"",function(){isFinish = true;});
			}		
		}
		return false;
	});
	
	if(isAuto == "true"){
		if(typeof second != "number" || second<1) second = 5;
		$("#"+imgPlayerId).everyTime(second+"s","ImgPlayerAuto",function(){
			if(isFinish){
				$next.trigger("click");
			}
		});
	}
	
	$("#imgPlayer .imgList").mouseover(function(){
		isFinish = false;
	}).mouseout(function(){
		isFinish = true;
	});
}

//11.图片播放器二
function ImgPlayer2(){
    try {
		var $imgBox = $("#imgPlayer2 .imgBox");
        var $topBtn = $("#imgPlayer2 .controls .prev");
        var $bottomBtn = $("#imgPlayer2 .controls .next");
        var $imgList = $("#imgPlayer2 .controls .imgList ul");
		var $eachImg = $imgList.children("li");
		
		var moveSpeed = 300;//缩略图移动速度
		var moveHeight = 66;//每个缩略图的高度
		var showAreaHeight = moveHeight * 5;//展示区域的高度
		var isAllowClick = true;
		//计算出ul的高度
   	    var _height = 0;
		$imgList.children("li").each(function(){
            _height +=$(this).outerHeight();
        });
        $imgList.height(_height);
		
		//向上点击事件
		$topBtn.click(function(){
			if(isAllowClick){
				var $now = $imgList.children(".now");
				if(!$now.is("li")){
					$imgList.children("li").eq(4).addClass("now");
					//更换图片
					playerShowImg($imgBox,$imgList.children(".now"));
				}else if($now.prev("li").is("li")){
					$now.removeClass("now");
					$now.prev("li").addClass("now");
					//更换图片
					playerShowImg($imgBox,$imgList.children(".now"));
					//判断是否需要移动
					var n =$imgList.children("li:last").index()- $now.index();
					if (n > 1) {
						var top = parseInt($imgList.css("top"));
						if (top < 0) {
							$imgList.animate({
								top: '+=' + moveHeight
							}, moveSpeed,"",function(){
							});
						}
					}
				}
			}
            return false;
		});
		
		//向下点击事件
		$bottomBtn.click(function(){
			if(isAllowClick){
				var $now = $imgList.children(".now");
				if(!$now.is("li")){
					$imgList.children("li").eq(0).addClass("now");
					//更换图片
					playerShowImg($imgBox,$imgList.children(".now"));
				}else if($now.next("li").is("li")){
					$now.removeClass("now");
					$now.next("li").addClass("now");
					//更换图片
					playerShowImg($imgBox,$imgList.children(".now"));
					//判断是否需要移动
					var n = $now.index() - $imgList.children("li:first").index();
					if (n > 1) {
						var top = parseInt($imgList.css("top"));
						if ((_height + top) > showAreaHeight) {
							$imgList.animate({
								top:"-="+moveHeight
							}, moveSpeed,"",function(){
							});
						}
					}
				}
			}
			return false;
		});
		
		//每个图片的点击事件
		$eachImg.click(function(){
			if(!isAllowClick) return false;
			var $now = $imgList.children(".now");
            var index = $now.index();
			var fristIndex = $imgList.children("li:first").index();
            var lastIndex = $imgList.children("li:last").index();
            if (index == $(this).index()) return false;
			if (index == -1) index = 0;
			
			$now.removeClass("now");
            $(this).addClass("now");
			//更换图片
			playerShowImg($imgBox,$imgList.children(".now"));
			
            if (index == 0) {
                index = 2;
            } else if (index == lastIndex) {
				index = lastIndex-2;
            }
			
            var clickMoveHieght = ($(this).index() - index) * moveHeight;  //点击的缩略图相对当前状态的缩略图所需移动的高度
			
            var subtract;
			var top = -parseInt($imgList.css("top"));
            if (clickMoveHieght > 0) {
				subtract = $(this).index() - fristIndex;
				if(subtract>=-2 && subtract<=2) return false;
                //向下滚动
                if ((_height - (showAreaHeight + top)) < clickMoveHieght)
                    clickMoveHieght = _height - (showAreaHeight + top);
                $imgList.animate({
                    top: '-=' + clickMoveHieght
                }, moveSpeed);
            } else {
                //向上滚动
				subtract = $(this).index() - lastIndex;
				if(subtract>=-2 && subtract<=2) return false;
                var temp = -clickMoveHieght;
                if (top < temp) temp = top;
                $imgList.animate({
                    top: '+=' + temp
                }, moveSpeed);
            }
            return false;
		});
	}catch(err){
       var txt = '本页中存在错误.\n\n';
	   txt+='错误描述:'+err.description+'\n\n';
	   txt+= '点击"确定"继续.\n\n';
	}
	
	function playerShowImg(imgBoxObj,eachImgObj) {
		isAllowClick = false;
		imgBoxObj.find("img").animate({
			opacity:0
		},300,"",function(){
			$(this).attr("src",eachImgObj.children("a").attr("src"));
			$("#imgTitle").text(eachImgObj.children("a").attr("title"));
			$(this).animate({
				opacity:1
			},300,"",function(){
				isAllowClick = true;
			});
		});
	}
}
//12.导航条事件
function navHover(){
	var setTimeoutId;
	$("#nav>li").hover(function(){
		var $li = $(this);
		var $lv_1 = $(this).children(".lv_1");
		setTimeoutId = setTimeout(function(){
			if(!$lv_1.hasClass("hover")){
				$lv_1.addClass("hover");
				$li.children(".nav_sub1").css("display","block");
				//$li.children(".nav_sub1").fadeIn(300);
			}
		},200);
		
	},function(){
		clearTimeout(setTimeoutId);
		var $li = $(this);
		var $lv_1 = $(this).children(".lv_1");
		$lv_1.removeClass("hover");
		$li.children(".nav_sub1").css("display","none");
		//$li.children(".nav_sub1").fadeOut(100);
	});
}
//13.下拉框选择跳转
function selectGoto(selectId){
	$("#"+selectId).change(function(){
		if($(this).val() !="" && $(this).val()!="#"){
			window.location.href = $(this).val();
		} 
	});
}

//14.物流篇-鼠标移过弹出
function hoverShow(){
	$("#freightage .list li").hover(function(e){
		//e.pageX-$(this).offset().left -- 鼠标相对当前对象的X轴
		$(this).addClass("hover");
		$(this).children(".box").css({"top":$(this).children(".name").height(),"display":"block"});
	},function(){
		$(this).removeClass("hover");
		$(this).children(".box").css("display","none");	
	});
}

//高亮关键字
function highlight(str)
{
 if(str=="")
    return;
  if(document.createRange){ 
  var range = document.createRange(); 
  }else 
  var range = document.body.createTextRange(); 
  if(range.findText){ 
      while(range.findText(str)){ 
        range.pasteHTML(range.text.fontcolor("#ff0000")); 
        range.collapse(true); 
      } 
  }else{ 
  var s,n; 
  s = window.getSelection(); 
      while(window.find(str)){ 
        
        var n = document.createElement("SPAN"); 
        n.style.color="#ff0000" 
        s.getRangeAt(0).surroundContents(n); 
      } 
  } 
}

//函数名称：Check_Email(strEmail)
//作用：检查邮件地址有效性，如果正确，返回true，否则返回false
//作者：lison
//日期：2006-06-20
//参数：strEmail，输入的email
function Check_Email(strEmail)
{
  //正则表达式，检测email格式
	var Reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if(strEmail==""){
    	return false; 
    } 
    if(Reg.test(strEmail)){
    	return true;
    }
    else
	{
	    return false;
	}
}
