﻿// JavaScript Document

var strUrl=window.location.href;
var arrUrl=strUrl.split("/");
var pageName=arrUrl[arrUrl.length-1];

var siteroot = "/products/";

var temp = null;

$(document).ready(function(){

	// 首页Brandimage随机显示
	if($("#BrandImage").length > 0)
	{
		var start = 1;
		var end = 14;
		var rnd = Math.floor(Math.random() * end + start);
   
		$("#BrandImage").load("brandimage/list.html .Brandimage" + rnd);
	}
	
	// 修正当前路径栏
	if($("#TopicPath li").length > 1) {
		$("#TopicPath li:last").remove();
		$("#TopicPath li:last a").addClass("last");
	}
	
	
	// 判断是否为产品信息页面，如果是，则采用特别的样式
	var pdUrl = strUrl.split("/products/");
	if(pdUrl[1] == "index.html" || pdUrl[1] =="list_name.html" || pdUrl[1] == null)
	{
	}else{
		$('.PageTitleStyle2 h1').addClass("bg");
		
		// 初始化右侧菜单
		initMenu("/js/hcsh/navi.xml",pdUrl[1]);

	}
	
	// 判断是否为关于我们页面，如果是，则采用特别的样式
	if($("#GlobalNaviTop li.Current").text() == "关于我们" && $("#GlobalNaviTop li.Current").text() != $("h1").text())
	{
		$("h1").addClass("about");
	}
	
	// 判断是否是招聘首页，如果是，采用特别的背景样式
	if($("#recruitPageTop").length > 0) 
	{
		$(".GridSet").css("background", "#FFFFFF");	
	}
	

	// 产品右侧分类列表的状态判断
	if($("#VerticalLocalNavi").length > 0) {
		$.each($("#VerticalLocalNavi li a"), function(){
			if($(this).attr("href") == pageName) {
				$(this).parent().addClass("Current");	
				if($(this).parent().children("ul").length > 0) {
					$(this).parent().children("ul").slideDown("fast");
				}
			};
		});
		//alert($("#RightProductsNavi li").length);
	}
	
	if($("#ProductsDetail table").length > 0) {
		$("#ProductsDetail table").hover(
		  function () {
			$(this).addClass("float");
		  },
		  function () {
			$(this).removeClass("float");
		  }
		);
	}

	// 滑动返回页首
	$(function () {
		// scroll body to 0px on click
		$('.PageTop a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
	
	// China
	if($("ul.location").length > 0) {

		$("ul.location li").mouseover(function() {
			$(this).children("ul").show();
			$(this).css("z-index","999");
			$(this).children("span").addClass("hover");
		});
		$("ul.location li").mouseout(function() {
			$(this).children("ul").hide();
			$(this).css("z-index","1");
			$(this).children("span").removeClass("hover");
		}
		);
	}
	
	
	function initMenu(xmlpath,NavID){
		var temp_str = "";
			$.ajax({
			  type: "GET",
			  url: xmlpath ,
			  dataType: "xml" ,
			  success : function(data){


						if(NavID.length > 0) {
							var pgUrl = NavID.split("/");
							pgUrl.pop();
							//alert(pgUrl);
						}

						var htmlcode = ""
						$(data).find("navs > nav").each(function(){
							var navroot = siteroot + $(this).attr("id") + "/";

							var currentPage = (pgUrl.length == 1 && pgUrl[0] == $(this).attr("id")) ? " class=\"Current\"" : "";
							//alert(pgUrl.length);
							htmlcode += "<li"+currentPage+"><a href=\""+navroot+"index.html\">"+$(this).attr("title")+"</a>";
							
							if($(this).find("subnav").size()>0 && pgUrl[0] == $(this).attr("id")){
									htmlcode += "<ul>";
									$(this).find("subnav").each(function(){
										var subnavroot = navroot;

										if($(this).attr("id")!=null){
											var currentPage = (pgUrl.length == 2 && pgUrl[1] == $(this).attr("id")) ? " class=\"Current\"" : "";
											
											subnavroot += $(this).attr("id") + "/";
											htmlcode += "<li"+currentPage+"><a href=\""+subnavroot+"index.html\">"+$(this).attr("title")+"</a>";
										}else{
											htmlcode += "<li><span>"+$(this).attr("title")+"</span>";
										}
										if($(this).find("sub").size()>0){
											htmlcode += "<ul>";
											$(this).find("sub").each(function(){
												var currentPage = (pgUrl.length == 2 && pgUrl[1] == $(this).attr("id")) ? " class=\"Current\"" : "";

												var subsubnavroot = subnavroot + $(this).attr("id");
												htmlcode += "<li"+currentPage+"><a href=\""+subsubnavroot+"/index.html\">"+$(this).attr("title")+"</a></li>";
												
											});
											htmlcode += "</ul>";
										}
										htmlcode += "";
									});
									htmlcode += "</ul>";
							}
							htmlcode += "";
						});
	
						$("#search").after("<div id='VerticalLocalNavi'><ul>" + htmlcode + "</ul></div>");
			  },
			  error  : function(){
					$("#search").after("<div class='Section'><ul id='VerticalLocalNavi'><li>Load Menu Error</li></ul></div>");
			  }
		}); 
	}
});



