JQ = $;  //rename $ function
//加载时初始化
JQ(function(){
	//script for search
	if(JQ("#s").val()==''){
		JQ("#s").val("Please provide keyword");
		//alert(JQ("#s").val());
		JQ("#s").bind("focus",function(){
			JQ("#s").val("");
			});
	};
	JQ(".hot-search a").bind("click",function(){
		JQ("#s").val(JQ.trim(JQ(this).text()));
		JQ("#searchform").submit();
	})

	//案列的特效
	JQ(".reveal-img li").hover(
			function(){
				JQ(".reveal-img li").removeClass("first-list");
				JQ(".re-main li").hide();
				JQ(".re-main span").hide();
				JQ(".re-right span").hide();
				JQ(this).addClass("first-list");
				JQ("#img_"+JQ(this).attr("name")).show();
				JQ("#text_"+JQ(this).attr("name")).show();
				JQ("#content_"+JQ(this).attr("name")).show();
				},
			function(){
				}
		);
	//detail
	JQ("#thumbnailList img").hover(
			function(){
				JQ("#productImg").attr("src",JQ(this).attr("src"));
				},
			function(){
				}
		);
	//左边菜单alert(JQ(".goods-categories .box-main ul > li:has(ul)").size())
	JQ(".goods-categories .box-main ul > li").toggle(
			function(){
				if (JQ(this).children(".children").size() > 0) {
					JQ(".goods-categories .box-main ul.children").hide(1000);
					if (JQ(this).children(".children").css('display') == 'block') {
						JQ(this).children(".children").hide(1000);
					}
					else {
						JQ(this).children(".children").show(1000);
					}
				}else{
					if(JQ(this).children("a").attr('href')!=''){
						window.location.href=JQ(this).children("a").attr('href');
					};
				}
			},
			function(){
				if (JQ(this).children(".children").size() > 0) {
					JQ(".goods-categories .box-main ul.children").hide(1000);
					if (JQ(this).children(".children").css('display') == 'block') {
						JQ(this).children(".children").hide(1000);
					}
					else {
						JQ(this).children(".children").show(1000);
					}
				}else{
					if(JQ(this).children("a").attr('href')!=''){
						window.location.href=JQ(this).children("a").attr('href');
					};
				}
               //JQ(".goods-categories li.current-cat,.goods-categories li.current-cat-parent").children(".children").show(1000);
			}
		);
	 JQ(".goods-categories li.current-cat,.goods-categories li.current-cat-parent").children(".children").show(1000);

	 //oem server
	JQ(".oem-service li").bind("click", function(){
		JQ(this).parent().children('li').removeClass('pitch');
		JQ(this).addClass('pitch');
		JQ("#oemcontent").html(JQ(this).children('div').html());
	});
	JQ("#oemcontent").html(JQ(".oem-service li.pitch>div").html());
	//JQ(".article p a").replaceAll((JQ(".article p a").children('img')));

	//产品详细页 缩略图

	var allEelemt=JQ("#thumbnailList").children('li').size();
	var showE=0;
	function fnPlayProAcsAction(action){
		if(action=='down'){
			if(showE==allEelemt-1){
				return;
			}
			if(showE>allEelemt-1){showE=0};
			showE++;
		}else if(action=='up'){
			if(showE==0){
				return;
			}
			if(showE>0){showE--;}
		}
		fnPlayProAcs(0,allEelemt,'none');
		if(showE<allEelemt){
			fnPlayProAcs(showE,allEelemt,'block');

		}else{
			JQ("#thumbnailList").children('li')[0].style.display="block";
		}

	}
	function fnPlayProAcs(start,end,playValue){
		var i= start!=''?start:0;
		var endE=end!=''?end:allEelemt;
		for(i;i<endE;i++){
			JQ("#thumbnailList").children('li')[i].style.display=playValue;
		}
 	}
	JQ("#thumb-left").click(function () {
		fnPlayProAcsAction('up');
	});
	JQ("#thumb-right").click(function () {
		fnPlayProAcsAction('down');
	});

	//头部导航弹出效果
	JQ("#navList li").hover(
			function(){
				//JQ(this).children(".children").show();
				//alert(JQ(this).attr("class"));
				//alert(JQ(this).children("a").html());
				var titleName=JQ(this).children("a").html();
				if(JQ(this).children("div.down-list").size()==0){
						//如果还没有创建一个div
						if(titleName.indexOf('Our Brands')!=-1){
							JQ(this).children("a").after("<div class=\"down-list \"></div>");
							JQ("#submenu-46").clone().prependTo(JQ(this).children("div.down-list"));
						}
						if(titleName.indexOf('Private Label')!=-1){
							JQ(this).children("a").after("<div class=\"down-list oem-down\"></div>");
							JQ("#submenu-63").clone().prependTo(JQ(this).children("div.down-list"));
						}
						if(titleName.indexOf('OEM Packaging')!=-1){
							JQ(this).children("a").after("<div class=\"down-list oem-down\"></div>");
							JQ("#submenu-64").clone().prependTo(JQ(this).children("div.down-list"));
						}
						if(titleName.indexOf('About Us')!=-1){
							JQ(this).children("a").after("<div class=\"down-list about-down\"></div>");
							JQ("#submenu-65").clone().show().prependTo(JQ(this).children("div.down-list"));
						}
						if(titleName.indexOf('Raw materials')!=-1){
						        JQ(this).children("a").after("<div class=\"down-list raw-down\"></div)");
						        JQ("#submenu-600").clone().prependTo(JQ(this).children("div.down-list"));
						}
					}else{
						JQ(this).children("div.down-list").show();
					}
				},
			function(){
				JQ(this).children("div.down-list").hide();
              // JQ(this).children(".children").hide();
              // JQ(".goods-categories li.current-cat,.goods-categories li.current-cat-parent").children(".children").show();

			}
	);

	//produts in sitemap
	JQ("#productCat li:first").addClass("major-select");
	JQ("#productCat-content ul:first").show();

	JQ("#productCat-img ul:first").show();
	JQ("#productCat li").hover(
			function(){
				JQ("#productCat li").removeClass("major-select");
				JQ(this).addClass("major-select");
				JQ("#productCat-content ul").hide();
				JQ("#productCat-img ul").hide();
				JQ("ul."+JQ(this).attr("name")+"content").show();
				},function(){
					}
			);
	JQ("#productCat-content li").hover(
			function(){
				JQ("#productCat-img li").hide();
				JQ("#productCat-img li."+JQ(this).attr("name")+"img").show();
				},function(){
					}
			);
});

Object.MAX_WIDTH = 600;