/* DOM 加载完毕 */

$(document).ready(function(){
	
	/*nav 的 click 效果*/
	$(".nav_item").click(function(){
		$(this).addClass("nav_item_current").siblings(".nav_item").removeClass("nav_item_current");
	});
	
	/*cate_item的click 效果*/
	$(".cate_item").click(function(){
		$(this).addClass("cate_item_current").siblings(".cate_item").removeClass("cate_item_current");
		});
	
	/* ===========================product 页面===================================*/
	//gallery
	$("#JS_zoom").zoom({
		xzoom: 300,
		yzoom: 300,
		offsetTop: 0,
		offset: 0,
		lens:1
	});
	
	$("#JS_thumbnailSlide").carousel({
			btnNext:"#JS_thumbnailNext",
			btnPrev:"#JS_thumbnailPrev",
			scrolls:1,
			vertical:false,
			circular: false,
			visible:4
	});
		
		
	var small_img = 50;
	var mid_img = 300;
	$(".thumbnail ul li:first").addClass("hover");
	var thumbTimeHover,thumbTimeOut;
	$(".thumbnail 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").parent("a").attr("href",_this.find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
		},150);
    },function(){
		var _this=$(this);
		clearTimeout(thumbTimeHover);
    });
	$(".thumbnail ul li").click(function(){
		return false;
	});
	
	
	//send inquiry
	$("#JS_btnSend").click(function(){
		offsetTop=$("#detail").offset().top;
		$("html,body").animate({scrollTop:offsetTop},300);
		$("#JS_sendInquiryTab").click();
		return false;
	})
	
	
	//tips_inquiry close
	$(".tips_inquiryadd .btn_close").click(function(){
		$(this).parent(".tips_inquiryadd").hide();
	});
	
	$("#JS_btnAdd").click(function(){
		$(this).hide();
		$("#JS_btnEnter").css({"display":"block"});
	});
	
	//detail tab
	$(".JS_tabHolder > li").each(function(index){
		$(".JS_tabHolder > li:first").addClass("tab_item_current");
		$(".JS_tabContent .JS_tabPanel:first").show();
		$(this).click(function(){
			var _this=this;
			$(_this).addClass("tab_item_current").siblings().removeClass("tab_item_current");
			$(_this).parents(".tab_holder").siblings(".JS_tabContent").find(".JS_tabPanel").eq(index).show().siblings().hide();
		})
	});

	
	/*=========================inquiry_basket=================================*/

	$(".inquiry_data_table tr").hover(function(){
		$(this).addClass("hover");
		 },function(){$(this).removeClass("hover")
	});
	
	
	
	//inquiry_fill
	$("#JS_inquiryInfoTitle").click(function(){
		$(this).toggleClass("inquiry_info_hide");
		$(this).parent(".hd").siblings(".bd").slideToggle(100);
		return false;
	});
	$("#JS_btnMoreOption").click(function(){
		$(this).toggleClass("btn_moreoption_hide");
		if($(this).text()=="More options"){
			$(this).text("Hide options");
		}else{
			$(this).text("More options");
		}
		//$("#JS_moreoptions").slideToggle("100");
		$("#JS_moreoptions").toggleClass("moreoptions");
		return false;
	});
	
	
	
	/*textarea 多行文本输入框字数控制*/
	var MessageObj = $(".message_length");
	MessageObj.keyup(function(){
		var _len=$(this).val().length;
		if(_len > -1 && _len<=1000){
			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{
			$(this).val($(this).val().substr(0,1000));  
			$(".message_tips_wrap").html("<div class='message_length_tips'>0 characters left</div>");
		}
	});
	
	
	/* ==============================plan & equipment 页面脚本 =============================== */

	
	var imgshowThumbItem = $("#JS_imgshowThumbSlide .list_item");
	 
	/*thumb slide*/
	imgshowThumbItem.first().addClass("hover");
	if(imgshowThumbItem.length > 0){
		$("#JS_imgshowThumbSlide").carousel({
			btnNext:"#JS_imgshowThumbNext",
			btnPrev:"#JS_imgshowThumbPrev",
			scrolls:1,
			vertical:false,
			circular: false,
			visible:4
		});
	};
	
	
	
	
	/*change picture*/
	var _small_img = 50;
	var imgshowPic = $("#JS_imgshowPic");
	var imgshowPicBox = $("#JS_imgshowPicBox");
	var imgshowPicId = "JS_imgshowPic";
	var imgshowPicBoxId = "JS_imgshowPicBox";
	imgshowPic.loadthumb({"src":imgshowPicBox.find("img").attr("src"),"imgId":imgshowPicId,"parentId":imgshowPicBoxId});
	imgshowThumbItem.click(function(){
		var _this=$(this);
		_this.addClass("hover").siblings().removeClass("hover");
		imgshowPic.attr("src",_this.find('img').attr("src").replace("_" + _small_img + "x" + _small_img,""));
		imgshowPicBox.find("a").attr("href",_this.find('img').attr("src").replace("_" + _small_img + "x" + _small_img,""));
		imgshowPic.loadthumb({"src":imgshowPicBox.find("img").attr("src"),"imgId":imgshowPicId,"parentId":imgshowPicBoxId});
		return false;
    });
		
		/*certification 页面的切换*/
	$(".imgshow_thumb .cert_tips").hide();
	$(".imgshow_thumb .cert_tips:first").show();
	$("#JS_imgshowThumbSlide li").each(function(index){		
		$(this).click(function(){
			$(this).addClass("hover").siblings().removeClass("hover");
			$(this).parents(".imgshow_thumb").find(".cert_tips").eq(index).show().siblings().hide();
			});
	});
	
	/* ==============================category 页面脚本 =============================== */

	
	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();
	});
	
	$(".pagination a").click(function(){
		$(this).addClass("current").siblings("a").removeClass("current");
	});
	
	/* 头部搜索  搜索框点击去除文字 */
	var searchInputObj = $(".search_input input");
	searchInputObj.focus(function(){
		$(this).prev("label").hide();
	})
	.blur(function(){
		var _this = $(this);
		if(_this.val()==""){
			_this.prev("label").show();
		}
	});
	
	/* 搜索框内容为空时 提示无法搜索 */
	
	
	/*lightbox*/
	$("a.lightbox,.imgshow_pic a").lightBox();
	

	/*nav 的 click 效果*/
	$(".nav_item .nav_target").click(function(){
		$(this).addClass("nav_target_current").parents(".nav_item").siblings(".nav_item").find(".nav_target_current").removeClass("nav_target_current");
	});
	
	
	
	
	/*privacy 隐私条款*/	
	$(".privacy input").click(function(){$(this).toggleClass("selected");});
	$(".btn_submit").click(function(){
		if(!$(".privacy input").hasClass("selected")){
		/*alert("please click the privacy policy!!");*/
		$(this).parents("#form_validate").next(".privacy_tips").show();
		/*$(".privacy input").html("checked","unchecked");*/
		return false;
		}
	else{
		$(this).parents("#form_validate").validate();}
	})
	
	
	
	
/* ============================== 公共脚本 ============================== End */
	
	
	$(".aside_category .cate_item").click(function(){
		_this=$(this);
		_this.addClass("cate_item_selected").siblings(".cate_item").removeClass("cate_item_selected").end();
		
		})
	
/* ============================== 首页 脚本 ============================== */

	
	
	//banner
	$("#promo a").addClass("bigimg");
	$("#promo .bigimg img").banner_thaw({
		thumbObj:"#promo .slide_triggers li",
		thumbNowClass:"hover",
		changeTime:5000
	});

})
