// JavaScript Document
$(function(){
	
	/*------------------------index-------------------*/
	/*nav背景*/
	$(".nav li:first").css("background","none");
	
	/*idx_info背景*/
	$(".idx_info .mod:last").css("background","none");
	
	
	/* lightbox */
	$("a.lightbox").lightBox();
	
	/*search*/
	var SearchValue=$("#header .search .search_input").val();
	$("#header .search .search_input").focus(function(){
			if($(this).val()==SearchValue){$(this).val("")};
		})
	$("#header .search .search_input").blur(function(){
			if($(this).val()==""){$(this).val(SearchValue)};
		})
		
	/*newsletter—??search*/
	var NewsSearchValue=$(".newsletter .search .search_input").val();
	$(".newsletter .search .search_input").focus(function(){
			if($(this).val()==NewsSearchValue){$(this).val("")};
		})
	$(".newsletter .search .search_input").blur(function(){
			if($(this).val()==""){$(this).val(NewsSearchValue)};
		})
	
	
	$(".nav_item").hover(function(){
		$(this).addClass("hover").children(".nav_sublist").show(500);
		},function(){
		$(this).removeClass("hover").children(".nav_sublist").hide(100);
		});
	
		
	//idx_promo
	$("#JS_promo a").addClass("bigimg");
	$("#JS_promo .bigimg img").banner_thaw({
		thumbObj:".promo .num li",
		thumbNowClass:"current",
		changeTime:4500
	});
			
			
	/* ----------productƷ carousel ---------- */
	$("#JS_otherProducts").carousel({
		btnNext: "#JS_otherProNext",
		btnPrev: "#JS_otherProPrev",
		scrolls: 1,
		auto:false,
		speed:500,
		circular: false,
		visible: 4
 	});		
	
	/*JS_hover*/
	$("#JS_hover .name").hover(function(){
		$(this).siblings(".area_detail").show(0).parents(".list_item").siblings(".list_item").find(".area_detail").hide(0);
		},function(){
		$(this).siblings(".area_detail").hide(0);
	});
	
	/*---------------list----------------------*/
        $(".sidenav_item_main").hover(function(){
		$(this).addClass("hover").parent(".sidenav_item").siblings(".sidenav_item").find(".sidenav_item_main").removeClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	$(".sidenav_item_main").click(function(){
		_this = $(this);
		if(_this.next(".sidenav_list_sub").length > 0){		
			_this.toggleClass("normal_target_selected").next(".sidenav_list_sub").slideToggle(0)
			.parents(".sidenav_item").siblings(".sidenav_item")
			.find(".sidenav_list_sub").removeClass("normal_target_current normal_target_selected").end()
			.find(".sidenav_list_sub").slideUp(0);
			return false;
		}else{
			_this.toggleClass("normal_target_current")
			.parent(".sidenav_item").siblings(".sidenav_item")
			.find(".sidenav_item_main").removeClass("normal_target_current normal_target_selected").next(".sidenav_list_sub").slideUp(0);
			
		};
	});
	
	
	$(".sidenav_list_sub a").click(function(){
		$(this).addClass("current").parents(".sidenav_list_sub li").siblings(".sidenav_list_sub li").find(".current").removeClass("current");
	});
	
        
        
	/*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();
	});
	
	
	/*--------------------------inquiery_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");
		}
		$(".inquiry_fill .moreoptions").slideToggle(100);
		return false;
	});
	
		/*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();
		}
	});
	
	/*-----------------------product------------------------*/
	
	/*privacy 隐私条款*/	
	$(".privacy input").click(function(){$(this).addClass("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").removeClass("selected");
		return false;
		}
	else{
		$(this).parents("#form_validate").validate();}
	})

		/*tab切换*/
		$("#detail .tab_item").each(function(index){
			$(this).click(function(){
				$(this).addClass("current").siblings().removeClass("current");
			   $(this).parent(".tab_holder").siblings(".tab_content").find(".tab_panel").eq(index).show().siblings().hide();
				})
			});
		$("#detail .tab_item:first").click();
		
		/*点击关闭*/
		$(".tips_inquiryadd .btn_close").click(function(){
				$(this).parent(".tips_inquiryadd ").hide();
			})
		
		/*send inquiry*/
		$("#JS_btnSend").click(function(){
			offsetTop=$("#detail").offset().top;
			$("html,body").animate({scrollTop:offsetTop},300);
			$("#JS_sendInquiryTab").click();
			return false;
		});
		
		$("#JS_Send").click(function(){
			offsetTop=$("#detail").offset().top;
			})
		
		//zoom
	$("#JS_productPic").zoom({
		xzoom:340,
		yzoom:340,
		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,
			circular: false,
			vertical:true,
			visible:4
		});
	};
	
	//change picture
	var small_img = 70;
	var mid_img = 340;
	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(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,""));
			$(".picbox").attr("href",_this.find('img').attr("src").replace("_" + small_img + "x" + small_img,""));
		},150)
    },function(){
		var _this=$(this);
		clearTimeout(thumbTimeHover);
    })
	.click(function(){
		return false;
	});
	
	/*about_us_scroll*/
	var about_thumbItem = $("#JS_SCROLL li");
	if(about_thumbItem.length > 0){
		$("#JS_SCROLL").carousel({
			btnNext:".img_scroll .next",
			btnPrev:".img_scroll .prev",
			scrolls:1,
			circular: false,
			visible:5
		});
	};
	
	/*form表单验证*/
	$("#form_validate").validate();
	})
	
	/* ============================== certification ҳ ű ============================== */
	
		/**-----------------------------------------------------------*
* @name		:	Imgshow JS
* @type		:	
* @explain	:	
*/
	
	
	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:true,
			circular: false,
			visible:3
		});
	};
	
	
	/*change picture*/
	var _small_img = 100;
	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;
    });
	
	/*exhibition=================================================begin*/
	var picshowThumbItem = $("#JS_picshowThumbSlide .list_item");
	/*thumb slide*/
	picshowThumbItem.first().addClass("hover");
	if(picshowThumbItem.length > 0){
		$("#JS_picshowThumbSlide").carousel({
			btnNext:"#JS_imgshowThumbNext",
			btnPrev:"#JS_imgshowThumbPrev",
			scrolls:1,
			vertical:false,
			circular: false,
			visible:4
		});
	};
	
	
	/*change picture*/
	var _small_img = 100;
	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});
	picshowThumbItem.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;
    });
	/*exhibition===================================================end*/
