/* ---------- DOM加载完毕 ---------- */
$(document).ready(function(){

/* ============================== 公共脚本 ============================== Begin */
	
	/* ---------- 去除虚线(部分元素) ---------- */
	$("#JS_thumbnailSlide li a").bind("focus",function(){
		if(this.blur){
			this.blur();
		};
	});
	$("#JS_promo a").addClass("bigimg");
			$("#JS_promo .bigimg img").banner_thaw({
				thumbObj:".promo .slide_triggers li",
				thumbNowClass:"hover",
				changeTime:3000
			});
	
	/* ---------- 输入框点击去除默认文字 ---------- */
	$("input.input_text").each(function(){
		var _this = $(this);
		if( _this.val() != ""){
			_this.prev("label.default_value").hide();  //输入框有值时，隐藏默认值
		};
		_this.focus(function(){
			_this.prev("label.default_value").hide();
		})
		.blur(function(){
			if(_this.val()==""){
				_this.prev("label.default_value").show();
			};
		});
	});
	
	$(".index_category_details ,.footer_nav").find("li:last").addClass("last");
	
	/* ---------- 主导航 nav ---------- */	
	$("#JS_nav > li:has(div) a").addClass("nav_dropdown");
	$("#JS_nav li.list_item").each(function(){
		var _this = $(this);
		$(this).hover(function(){
			_this.addClass("list_item_current");},function(){
			_this.removeClass("list_item_current");	
		});
		var _navSubItemL = _this.children("div").length;
		if(_navSubItemL > 0){
			_this.hover(function(){
				_this.find("div.nav_sublist_down").show();
			},function(){
				
				_this.find("div.nav_sublist_down").hide();
			});
		}
	});
	
	
	/* ---------- 边栏分类导航 sidenav ---------- */
	$(".sidenav_main").hover(function(){
		$(this).addClass("sidenav_hover").parent(".sidenav_item").siblings(".sidenav_item").removeClass("sidenav_hover");
	},function(){
		$(this).removeClass("sidenav_hover");
	})
	.click(function(){
		_this = $(this);
		if(_this.next(".sidenav_sublist").length > 0){		
			_this.toggleClass("sidenav_selected").next(".sidenav_sublist").slideToggle(100)
			.parent(".sidenav_item").siblings(".sidenav_item")
			.find(".sidenav_main").removeClass("sidenav_selected").end()
			.find(".sidenav_sublist").slideUp(100);
			return false;
		}else{};
	});
	

		
	

	
/* ============================== 首页 脚本 ============================== End */
	
	/*首页分类图轮转*/
/*		$(".homeCate_mod").carousel({		
			scrolls:1,
			auto: 3000,
			speed:500,		
			visible:4		
		});
		
*/	
	/* ---------- 首页滑过下拉 模块 slidedown ---------- */
	$("#JS_homeSlidedown").find("h3:first").addClass("home_slidedown_selected_title");
	$("#JS_homeSlidedown").find(".home_slidedown_info:first").show();
	$(".home_slidedown_title").click(function(){
		$(this).toggleClass("home_slidedown_selected_title");
		$(this).next(".home_slidedown_info").slideToggle(100).siblings(".home_slidedown_info").slideUp(100);				  		$(this).siblings(".home_slidedown_title").removeClass("home_slidedown_selected_title");
	});
	
	
	
/* ============================== 产品列表页 脚本 ============================== Begin */


	
	/* ---------- 产品列表过滤器 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();
	});
	
	$(".filter .select_list span").hover(function(){
		$(this).addClass("hover").siblings().removeClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
/* ============================== 产品列表页 脚本 ============================== End */
	/* ---------- 产品页图片展示 gallery ---------- */
	
	var productPic = $('#JS_productPic');   //使用全局变量存储DOM，性能会更好

	/* 大图展示 popover-1.0 */
	productPic.popover({
		imgWrap:				".picbox",						//存放大图路径且包裹小图的元素的类名或者ID
		thumbnail:				"#JS_thumbnail",				//缩略图区域的类名或者ID
		thumbnailWidth:			40,								//缩略图的宽度
		thumbWidth:				40,								//弹出框中缩略图的宽度
		thumbMargin:			20,								//弹出框中缩略图区域与大图展示区域之间的距离
		overlayBgColor: 		"#555555",						//背景遮罩层的颜色
		overlayOpacity:			0.4,							//背景遮罩层半透明值
		popoverTop:				30,								//窗口与浏览器顶部的距离，建议用默认值
		windowControl:			10,								//控制弹出窗口的宽度，数字越大，宽度越大。建议用默认值
		cursorZoomIn:			"/images/zoom_in.cur",			//放大镜指针路径(放大)，建议用默认图片(由于项目正式上线后路由会重写，文件夹路径会发生变化，要在"iamges"前加"/",以保证路径正确)
		cursorZoomOut:			"/images/zoom_out.cur"			//放大镜指针路径(缩小)，其余同ZoomIn
	});
	
	/* 图片展示提示信息变化 (当页面有大图浏览时用此脚本，否则不用) */
	productPic.hover(function(){
		$("span.gallery_tips_item").remove();
		$("div.gallery_tips").append('<span class="gallery_tips_item gallery_tips_enlarge">Click to open expanded view</span>');
	},function(){
		$("span.gallery_tips_item").remove();
		$("div.gallery_tips").append('<span class="gallery_tips_item gallery_tips_zoom">Roll over image to zoom in</span>');
	});
	
	/* 放大镜效果 zoom-1.2.3 */
	productPic.zoom({
		xzoom:300,
		yzoom:300,
		offset:-605,
		lens:1
	});
		$(".index_pro_list").carousel({
			btnNext:".rightBox",
			btnPrev:".leftBox",
			scrolls:1,
			circular: false,
			visible:5,
			vertical:false
		});
	
	
	/* 缩略图滚动 */
	if(("#JS_thumbnailSlide li").length > 0){
		$("#JS_thumbnailSlide").carousel({
			btnNext:"#JS_thumbnailNext",
			btnPrev:"#JS_thumbnailPrev",
			scrolls:1,
			circular: false,
			visible:5,
			vertical:true
		});
	}
	
	/* 缩略图切换 */
	var thumbItem = $("#JS_thumbnailSlide li");
	var small_img = 40;
	var mid_img = 300;
	thumbItem.first().addClass("selected");
	var thumbTimeHover,thumbTimeOut;
	thumbItem.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);
		_this.removeClass("hover");
		clearTimeout(thumbTimeHover);
		thumbTimeOut = setTimeout(function(){
			var _thumbSelectedImg = $("#JS_thumbnailSlide li.selected img");
			$("#picture").attr("src",_thumbSelectedImg.attr("src").replace(small_img + "x" + small_img,mid_img + "x" + mid_img));
			$(".bigimg").attr("src",_thumbSelectedImg.attr("src").replace("_" + small_img + "x" + small_img,""));
			$("#picture").parent("a").attr("href",$("#picture").attr("src").replace("_" + mid_img + "x" + mid_img,""));
		},100)
    })
	.click(function(){
		var _this=$(this);
		_this.addClass("selected").siblings().removeClass("selected");
		$("#picture").parent("a").attr("href",$("#picture").attr("src").replace("_" + mid_img + "x" + mid_img,""));
		return false;
	});
	
	
	/* ---------- 产品页 产品详细Tab切换 (details) ---------- */
	
	
	/*detail tab*/
	$("#JS_detailsTab li").each(function(index){
		$(this).click(function(){
			var _this=this;
			$(_this).addClass("current").siblings().removeClass("current");
			$(_this).parents("#JS_detailsTab").siblings("#JS_detailsPanels").find(".tabpanel").eq(index).show().siblings().hide();
		})
	});
	$("#JS_productShowTab li:first").click();
	
	
	/*send inquiry*/
	$("#JS_btnSend").click(function(){
		offsetTop=$("#details").offset().top;		
		$("html,body").animate({scrollTop:offsetTop},300);
		$("#JS_sendInquiryTab").click();
		return false;
	});
	
	$("#JS_btnAdd").click(function(){
		$(this).hide();
		$("#JS_btnEnter").css({"display":"block"});
	});
	
	/*tips_inquiry close*/
	$(".tips_inquiryadd .btn_close").click(function(){
		$(this).parent(".tips_inquiryadd").hide();
	});
	
	
/* ============================== 产品页 脚本 ============================== Begin */
	
	
	/*============================fill in your inquiry询盘表单=======================*/
	
	/*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");
		}
		$(".forms .moreoptions").slideToggle(100);
		return false;
	});
	
	
	/*================================资质认证certification=================================*/
	
	/* 资质认证缩略图滚动 */
	$("#JS_hornor_slide").carousel({
		btnNext:"#JS_Next",
		btnPrev:"#JS_Prev",
		scrolls:1,
		mouseWheel: true,
		circular: false,
		visible:4,
		vertical: true
	});
	
	/*资质认证大图显示*/
    var i = 1;
    $("#JS_hornor_slide li").each(function(index){
            $(this).click(function(){
                $(this).addClass("selected").siblings().removeClass("selected");
                $("#JS_hornorPic").find("img").attr("src",$(this).find("img").attr("src").replace("_70x70","_360x360"));               
				$("#JS_hornorPic").find("a").attr("href",$(this).find("img").attr("src").replace("_70x70",""));              
                $("#big_name").find("p").each(function(index2){
                    if(index==index2){
                    $(this).addClass("show").siblings().removeClass("show");
                    }
                    });
                i = index +1
                });
            });
    function change_img(){       
        $("#big_name").find("p").each(function(index){
                if(i==index + 1){
                $(this).addClass("show").siblings().removeClass("show");
                }
                });
       
    };
	$("#JS_hornor_slide li:first").click();
	
	/*资质认证end*/
	
	
	
	
	/*=========================exhibition展会页面==========================*/
	
	/* 展会缩略图滚动 */
	$("#JS_exhi_slide").carousel({
		btnNext:"#JS_exhiNext",
		btnPrev:"#JS_exhiPrev",
		scrolls:1,
		mouseWheel: true,
		circular: false,
		visible:4,
		vertical: true
	});
	
	/*展会大图显示*/
    var i = 1;
    $("#JS_exhi_slide li").each(function(index){
            $(this).click(function(){
                $(this).addClass("selected").siblings().removeClass("selected");
                $("#JS_exhiPic").find("img").attr("src",$(this).find("img").attr("src").replace("_70x70","_360x360"));               
				$("#JS_exhiPic").find("a").attr("href",$(this).find("img").attr("src").replace("_70x70",""));              
                $("#exhi_name").find("p").each(function(index2){
                    if(index==index2){
                    $(this).addClass("show").siblings().removeClass("show");
                    }
                    });
                i = index +1
                });
            });
    function change_img(){       
        $("#exhi_name").find("p").each(function(index){
                if(i==index + 1){
                $(this).addClass("show").siblings().removeClass("show");
                }
                });
       
    };
	$("#JS_exhi_slide li:first").click();
	
	/*展会end*/
	
	
	
	
	

	 
	 /*==========================news======================*/	
	 $(".news_list li").hover(function(){
		 $(this).addClass("hover")
	 },function(){
		 $(this).removeClass("hover")
	 });
	 
	 
	 
	 /*================================faq===============================*/
	 	$("dl.faq_item").first().addClass("faq_item_selected");
		$("div.faq dt").first().addClass("selected");
		$("div.faq dd").first().show();
		$("div.faq dt").click(function(){
			_this = $(this);				
				$(this).toggleClass("selected").next(".faq_content").slideToggle(100)
				.parent(".faq_item").toggleClass("faq_item_selected").siblings(".faq_item").removeClass("faq_item_selected")
				.find("dt").removeClass("selected").end()
				.find("dd").slideUp(100)		
				return false;	
		});
		$("div.faq dt").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});	
		
		/*faq end*/
	
	
		 $('.lightbox').lightBox();
		 
		 
		 
		 /*表单验证*/
		 
	/*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();
		}
	});
		 
		 
		 
	/* 一般表单 */
	$("#form_validate").validate({
		
		rules: {
			subject: {    
				required: true,
				maxlength:150
			},
			message: {    
				required: true,
				maxlength:1000
			},
			company: {
				maxlength:100
			},
			email: {
				required: true,
				email: true
			},
			phone: {				
				maxlength:100
			},
			fax: {				
				maxlength:100
			},
			homepage: {				
				maxlength:100
			}
			
		},
		messages: {
			subject: {
				required: "Please be certain to enter the subject.",
				maxlength:"The subject exceeds maximum length of 150 characters."
			},
			message: {
				required:"Please be certain to enter your message.",			
				maxlength:"Please enter no more than 1000 characters."
			},
			email:{
				required:"Please provide an email.",
				email:"Please enter a valid email address."
			},
			
			phone:{
				maxlength:"The phone exceeds maximum length of 100 characters."
			},
			fax:{
				maxlength:"The phone exceeds maximum length of 100 characters."
			},
			homepage:{
				maxlength:"The phone exceeds maximum length of 100 characters."
			}
		}
	});
	
	
	
	
	
               
	
          
       
		
                
	
	
	
});

