/* ---------- DOM加载完毕 ---------- */
$(document).ready(function(){
	

	
	/* ---------- 搜索框点击去除文字 ---------- */
	var searchInputObj = $(".search-input input");
	searchInputObj.focus(function(){
		$(this).prev("label").hide();
	})
	.blur(function(){
		var _this = $(this);
		if(_this.val()==""){
			_this.prev("label").show();
		}
	});
	
	
	/* ---------- 去除虚线(部分元素) clear outline ---------- */
	$("#JS_btnAddNew,#JS_btnMoreOption").bind("focus",function(){
		if(this.blur){
			this.blur();
		};
	});
	
	
	 /*---------- 关闭提示信息 product_btn_close ----------*/
	$(".btn_close").click(function(){
		$(this).parent().hide();							   
	})
		
   /*----------首页banner  index_promo----------*/
	$("#promo .bigimg img").banner_thaw({
		thumbObj:"#promo .triggers_num span",
		thumbNowClass:"hover",
		changeTime:4000
	});
	
	/*----------首页产品展示 index_carousel----------*/
	if($(".new_product .thumb_slide > ul > li").length > 0){
		$(".new_product .thumb_slide").carousel({
			btnNext: ".new_product .next",
			btnPrev: ".new_product .prev",
			scrolls:1,
			auto:false,
			circular: false,
			visible:3
		});
	};
	
		if($(".hot_product .thumb_slide > ul > li").length > 0){
		$(".hot_product .thumb_slide").carousel({
			btnNext: ".hot_product .next",
			btnPrev: ".hot_product .prev",
			scrolls:1,
			auto:false,
			circular: false,
			visible:3
		});
	};
	
	
	/*----------产品页大图展示----------*/

	/*放大镜效果 zoom*/
	$("#JS_zoom").zoom({
		xzoom:300,
		yzoom:300,
		offset:10,
		position:"right",
		lens:1
	});
	
	
	/*缩略图滚动 thumbnail slide*/
	  var thumbItem = $("#JS_thumbnailSlide .list_item");
	  if(thumbItem.length > 0){
		$("#JS_thumbnailSlide").carousel({
		  btnNext:"#JS_thumbnailNext",
		  btnPrev:"#JS_thumbnailPrev",
		  scrolls:1,
		  mouseWheel: true,
		  circular: false,
		  visible:4
		}).mousewheel(function(){
		  return false;
		});
	  };
	  
	 
	  
	 /*缩略图切换 change picture*/
	var product_small_img = 40;
	var product_mid_img = 300;
	thumbItem.first().addClass("hover");
	var thumbTimeHover;
	thumbItem.hover(function(){
		var _this=$(this);
		thumbTimeHover = setTimeout(function(){
			_this.addClass("hover").siblings().removeClass("hover");
			$("#picture").attr("src",_this.find('img').attr("src").replace(product_small_img + "x" + product_small_img,product_mid_img + "x" +product_mid_img));
			$("#picture").parent("a").attr("href",_this.find('img').attr("src").replace("_" + product_small_img + "x" + product_small_img,""));
		},150)
    },function(){
		var _this=$(this);
		clearTimeout(thumbTimeHover);
    })
	.click(function(){
		return false;
	});
	
	  
	  
	/* ---------- 产品页 产品详细Tab切换 (details) ---------- */
	$("#detail .tab_holder > li").each(function(index){
		$(this).click(function(){
			var _this=this;
			$(_this).addClass("current").siblings().removeClass("current");
			$(_this).parent(".tab_holder").siblings(".tab_content").find(".tab_panel").eq(index).show().siblings().hide();
		})
	});
	$("#detail .tab_holder > li:first").click();
	
	/*表单*/
	$(".parameter tr:even").addClass("even"); 
		/*btn*/
		$("#JS_inquiryInfoTitle").click(function(){
		$(this).toggleClass("inquiry_info_hide");
		$(this).parent(".hd").siblings(".bd").slideToggle(100);
		return false;
	});
		$(".btn_moreoption").click(function(){
		$(this).toggleClass("btn_moreoption_hide");
		if($(this).text()=="More options"){
			$(this).text("Hide options");
		}else{
			$(this).text("More options");
		}
		$(".moreoptions").slideToggle(100);
		return false;
	})
		/*form*/
	$("#form_validate").validate({errorClass:"error"});
		/*message length*/
	var MessageObj = $(".message_length");
	MessageObj.keyup(function(){
		var _len=$(this).val().length;
		if(_len > -1){
			var _remain=parseInt(1000-_len)>'0'?parseInt(1000-_len):'0';
			var _str = '<div class="message_length_tips"><em>' + _remain + '</em> characters left.</div>'
			$(".message_tips_wrap").html(_str);
		}else{
		}
	});
	MessageObj.keyup(function(){
		var _len=$(this).val().length;
		if(_len==0){
			$(".message_length_tips").remove();
		}
	});
	
	/* ---------- 产品页 点击切换进入购物车按钮 ---------- */
	$("#JS_btnSend").click(function(){
		offsetTop=$("#detail").offset().top;
		$("html,body").animate({scrollTop:offsetTop},300);
		$("#JS_sendInquiryTab").click();
		return false;
	})	
	$("#JS_btnEnter").hide();
	$("#JS_btnAdd").click(function(){
		$(this).hide();
		$("#JS_btnEnter").css({"display":"block"});
	});
	
	/* ---------- 产品列表过滤器 filter ---------- */	
	  var timeFilterHover;
	  $(".filter-select").hover(function(){
		_this = $(this);
		timeFilterHover = setTimeout(function(){
		  _this.find(".select-list").show().parents(".filter-item").siblings().find(".select-list").hide()
		},100);
	  },function(){
		_this = $(this);
		clearTimeout(timeFilterHover);
	
		_this.find(".select-list").hide();
	  });
	  
	  $(".select-item span").hover(function(){
		$(this).parent(".select-item").addClass("select-item-hover").siblings(".select-item").removeClass("select-item-hover");
	  },function(){
		$(this).parent(".select-item").removeClass("select-item-hover");
	  });	
		
   /* ---------- 资质认证页图片展示 certification ---------- */	
   /*缩略图轮转*/
	  if($(".plant_slide > ul > li").length > 0){
		$(".plant_slide").carousel({
			btnNext: ".next",
			btnPrev: ".prev",
			scrolls:1,
			auto:false,
			mouseWheel: true,
            circular: false,
            btnGo: [".0", ".1", ".2"],
			vertical:true,
			visible:5
		}).mousewheel(function(){
		    return false;
		});
    }
	/*缩略图切换*/
			var plant_small_img = 50;
			var plant_mid_img = 300;
			$(".plant_nail ul li:first").addClass("selected");
			var thumbTimeHover,thumbTimeOut;
			$(".plant_nail ul li").hover(function(){
				var _this=$(this);
				clearTimeout(thumbTimeOut);
				thumbTimeHover = setTimeout(function(){
					_this.addClass("hover").siblings().removeClass("hover");
					$("#picture").attr("src",_this.find('img').attr("src").replace(plant_small_img + "x" + plant_small_img,plant_mid_img + "x" + plant_mid_img));
					$("#picture").attr("big",_this.find('img').attr("src").replace("_" + plant_small_img + "x" + plant_small_img,""));
				},150)
			},function(){
				var _this=$(this);
				_this.removeClass("hover");
				clearTimeout(thumbTimeHover);
				thumbTimeOut = setTimeout(function(){
					$("#picture").attr("src",$(".plant_nail .selected").find('img').attr("src").replace(small_img + "x" + small_img,mid_img + "x" + mid_img));
					$(".bigimg").attr("src",$(".plant_nail .selected").find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
					$("#picture").attr("big",$("#picture").attr("src").replace("_" + mid_img + "x" + mid_img,""));
				},10)
			});
			$(".plant_nail ul li").click(function(){
				$(this).addClass("selected").siblings().removeClass("selected");
				$("#picture").attr("big",$(this).find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
				return false;
			})



     /* ---------- 展会信息页页图片展示 Exhibition Informations ---------- */
     /*缩略图轮转*/
	
			  if($(".exhibition_slide > ul > li").length > 0){
				$(".exhibition_slide").carousel({
					btnNext: ".next",
					btnPrev: ".prev",
					scrolls:1,
					auto:false,
					mouseWheel: true,
					circular: false,
					btnGo: [".0", ".1", ".2"],
					vertical:true,
					visible:5
				}).mousewheel(function(){
					return false;
				});
			}
	
	 /*缩略图切换*/
			var small_img = 50;
			var mid_img = 300;
			$(".exhibition_nail ul li:first").addClass("selected");
			var thumbTimeHover,thumbTimeOut;
			$(".exhibition_nail ul li").hover(function(){
				var _this=$(this);
				clearTimeout(thumbTimeOut);
				thumbTimeHover = setTimeout(function(){
					_this.addClass("hover").siblings().removeClass("hover");
					$("#picture").attr("src",_this.find('img').attr("src").replace(small_img + "x" + small_img,mid_img + "x" + mid_img));
					$("#picture").attr("big",_this.find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
				},150)
			},function(){
				var _this=$(this);
				_this.removeClass("hover");
				clearTimeout(thumbTimeHover);
				thumbTimeOut = setTimeout(function(){
					$("#picture").attr("src",$(".exhibition_nail .selected").find('img').attr("src").replace(small_img + "x" + small_img,mid_img + "x" + mid_img));
					$(".bigimg").attr("src",$(".exhibition_nail .selected").find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
					$("#picture").attr("big",$("#picture").attr("src").replace("_" + mid_img + "x" + mid_img,""));
				},10)
			});
			$(".exhibition_nail ul li").click(function(){
				$(this).addClass("selected").siblings().removeClass("selected");
				$("#picture").attr("big",$(this).find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
				return false;
			})

    /* ---------- FAQ页 内容显示与隐藏 ---------- */
	$(".faq-name").click(function(){
		$(this).addClass("faq-name-selected");
		$(this).next(".faq-item-content").slideToggle(100).parent().siblings().find(".faq-item-content").slideUp(100);
		$(this).parent().siblings().find(".faq-name").removeClass("faq-name-selected");
	});
	
	


    /* ---------- 点击弹出大图 lightbox ---------- */
    $('.lightbox').lightBox();
  
  
	//top menu down
	$(".head_right .language").each(function(){
		$(this).hover(function(){
			$(this).addClass("position_r").find('ul:first').css({display: "block"});	
		},function(){
			$(this).removeClass("position_r").find('ul:first').css({display: "none"});
		})						 
	});

});


