var host = location.protocol + "//" + location.host;
function to(page){window.location.href=page;}
jQuery(document).ready(function($){
	
	var href = window.location.href;
	/**
	 * 分页下拉
	 * @memberOf {TypeName} 
	 */
	(function(){
		var s = $("#page #select > option");
		s.each(function(){
			var o = $(this);
			var v = o.attr("value");
			if(href.indexOf(v)>=0){
				document.getElementById("select").value=v;
			}
		});
	})();
	
	/**
	 * 搜索
	 */
	(function(){
		var s = $("#select_type > option");
		s.each(function(){
			var o = $(this);
			var v = o.attr("value");
			if(href.indexOf(v.substring(0, v.length-6))>=0){
				document.getElementById("select_type").value=v;
			}
		});
		$("#search").click(function(){
			var url = $("#select_type").val();
			if(url==null || url==""){
				if(href.indexOf("/en/")>=0){
					url="/en/product.html"
				}else{
					url="/zh/product.html"
				}
			}
			window.location.href=url+"?word="+encodeURIComponent($("#word").val());
		});
	})();
	
	/**
	 * 左菜单选中
	 */
	(function(){
		var boo = false;
		$("#left_list a").each(function(){
			var h = $(this).attr("href");
			if(href.indexOf(h.substring(0,h.length-6))>=0){
				boo=true;
				$(this).addClass("hover");
				$(this).parent().next(".childs").show();
				$(this).closest(".childs").show();
			}
		});
		if(boo==false){
			var o = $("#left_list a:first");
			o.addClass("hover");
			o.parent().next(".childs").show();
			o.closest(".childs").show();
		}
	})();
	
	/**
	 * 头部菜单
	 */
	$(".menu li").hover(function(){
		var w = $(this).parent().width();
		var p = $(this).position();
		var rwidth = w-p.left;//当前li右边剩余宽度
		
		var ch = $(this).children(".childs");
		if(ch.length){
			var li = ch.find("li");
			
			//显示
			ch.stop(true, true).slideDown(/*ch.find("li").length*100*/200, function(){
				$(this).show();
			});
			//li.width(ch.width()-(li.outerWidth()-li.width()));
			
			//宽度
			var w = 0;
			li.each(function(){
				w+=$(this).outerWidth();
			});
			ch.width(w);
			
			//左距离
			var chw = ch.width();
			if(chw>rwidth){
				ch.css("left", -(chw-rwidth));
			}
		}
	}, function(){
		var ch = $(this).children(".childs");
		if(ch.length){
			ch.stop(true, true).delay(200).slideUp(/*ch.find("li").length*100*/100, function(){
				$(this).hide();
			});
		}
	});
	
	/** 广告 **/
	/*var adver = new Advertising();
	adver.add({
		title : "广告", href : "#", imagepath : "/images/index_17.jpg", width : 100, height : 250, position : "right,out", top : 0
	}, "#container_advertising");
	adver.init();*/
	
	$("#container_advertising .advertising.adright").each(function(){
		$(this).css("right", -$(this).width()-20);
	});
	/*$("#container_advertising .advertising.adleft").each(function(){
		$(this).css("left", -$(this).width()-20);
	});*/
	/*var advertisingRight = function(){
		var ww = $(window).width();
		var dw = $(document).width();
			$("#container_advertising .advertising").each(function(){
				if(!$(this).data("ad_right")){
					$(this).data("ad_right", $(this).css("right"));
				}
				var w = $(this).width();
				var l = $(this).offset().left;
				if((l+w)>ww && dw>ww){
					var o = (l+w)-ww;
					var rs = $(this).css("right");
					var ri = Number(rs.substring(0, rs.indexOf("px")));
					$(this).css("right", ri+o);
				}else{
					$(this).css("right", $(this).data("ad_right"));
				}
			});
	}
	advertisingRight();
	$(window).resize(advertisingRight);*/
});

var browserName = navigator.userAgent.toLowerCase();
var isChrome = /chrome/i.test(browserName);
var isIE = /msie/i.test(browserName);
var isIE8 = /msie 8/i.test(browserName);


