		var origin;
		var activeNav;
		var activeNavWidth;
		var startPos;
		var lock = new Boolean();
		var footBoxOpen = new Boolean();
		var counter;
		var contentLength;
		var sub;
		var curr;
		var lowerc = "";
		var lowerc2 = "";
		var key = "";
		var subkey = "";
		var defaultHash = "home-2"; 
		var manArray = new Array();

	
		var Browser = {
		  Version: function() {
		    var version = 999; // we assume a sane browser
		    if (navigator.appVersion.indexOf("MSIE") != -1)
		      // bah, IE again, lets downgrade version number
		      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		    return version;
		  }
		}
		
		if (Browser.Version() < 7) {
			contentLength = 912;
		} else {
			contentLength = 910;
		}
		
		
		function init() {
			
			setLanSwitch();
			var hash = window.location.hash.substr(1); 
			if (hash == "") hash = defaultHash;
			hash = hash.split("/");
			
			//$("#test").text(xx.left);
			
		
			if (hash[0] == "footer") {
				
				$(".rightFooter ul li").each(function(index) {
					key = $(this).attr("id");
					if (key == hash[1]) {
						
						$("#footArrow").css({"display":"block"});
						$("#footBox").css({"display":"block"});
						openFooter(index);
					}
				});
				
				hash[0] = defaultHash;
			}
			$(".menu li").each(function(index) {
				
				key = $(this).attr("id");
				key = key.replace("1", "");
				if (key == hash[0]) {
					sub = key.substr(0,3);
					$(this).addClass("current");
					if (hash[1] != "") {
						$("." + sub +" li").each(function(index2) {
							index2++;
							subkey = $(this).attr("id");

							if (subkey == hash[1]) {										
								$("."+sub+" li.current").removeClass("current");
								$("#"+sub+" .subpage-first").css({"display": "none"});
								$(this).addClass("current");
								$("#"+sub+" .page" + index2).css({"display": "block"});
							}
						});
					}
				}
			});
			
			var n = $(".menu li.current").prevAll().length;
			var contentPos = n * contentLength;
			$("#scrollContent").css({ "left": -contentPos});
			origin = $(".menu").position();
			activeNav = $(".menu li.current").position();
			activeNavWidth = $(".menu li.current").width();
			startPos = (origin.left + 25) + activeNav.left + activeNavWidth/2;
			$(".menu-arrow").css({ "left": startPos });
			lock = false;	
			footBoxOpen = false;			
			xx = $(".menu-arrow").position();
			if (Browser.Version() == 7) {$("."+sub).css("left", xx.left-32);} else {$("."+sub).css("left", xx.left-10);}
			$("."+sub).css({"display":"block"});			
	
		}
		
		function openFooter(n) {
			var pos = new Array();
			$("#footBox").css({ "width": 366, "right": 80 });
			$(".footBoxContent").css({ "width": 322 });

			var w = $("#footBox").width();
			$("#ieShadow").width(w);
			if (Browser.Version() == 8) {
				$("#ieShadow").css({"right": 82});
			} else if (Browser.Version() < 8) {
				$("#ieShadow").css({"right": 76});
			}
			if ( screen.width < 1025 ) {
				if ( lan != "zh/" ) pos[0] = 230; else pos[0] = 180;
				if ( lan != "zh/" ) pos[1] = 188; else pos[1] = 140;
				if ( lan != "zh/" ) pos[2] = 100; else pos[2] = 80;
				if ( lan != "zh/" ) pos[3] = 15; else pos[3] = 15;
			} else {
				if ( lan != "zh/" ) pos[0] = 290; else pos[0] = 225;
				if ( lan != "zh/" ) pos[1] = 248; else pos[1] = 188;
				if ( lan != "zh/" ) pos[2] = 160; else pos[2] = 120;
				if ( lan != "zh/" ) pos[3] = 70; else pos[3] = 70;
			}
						
				switch (n) {
					case 0:
						if (lan != "zh/") {
								$(".footLeft").html("LATEST NEWS");
						} else {
							$(".footLeft").html("最新动态");
						}
						$("#footArrow").css({ "right": pos[n] });
	
						loadAjax("news");		
						break;
						
					case 1:
						if (lan != "zh/") {
							$(".footLeft").html("A PATH TO SUCCESS");
						} else {
							$(".footLeft").html("成功之路");
						}
						$("#footArrow").css({ "right": pos[n] });
						loadAjax("careers");		
						break;
						
					case 2:
						if (lan != "zh/") {
							$(".footLeft").html("PRIVACY POLICY AND TERMS");
						} else {
							$(".footLeft").html("政策及条款");
						}
						$("#footArrow").css({ "right": pos[n] });
	
						loadAjax("privacy");		
						break;

					case 3:
						$("#footArrow").css({ "right": pos[n] });
						$("#footBox").css({ "width": 200, "right": pos[n] });
						$(".footBoxContent").css({ "width": 150 });
						w = $("#footBox").width();
						$("#ieShadow").width(w);
						$("#ieShadow").css({"right": pos[n]});

						if (lan != "zh/") $(".footLeft").html("SITEMAP");
						else $(".footLeft").html("网站地图");						
						loadAjax("site-map");		
						break;
					
					case 4:
						
						$("#footArrow").css({ "right": pos[0] });
						if (lan != "zh/") $(".footLeft").html("LATEST NEWS");
						else $(".footLeft").html("最新动态");
						break;
							
					
				}
				if (!footBoxOpen) {
					footBoxOpen = true;
		   			$("#footBox").fadeIn("fast");
		   			$("#footArrow").fadeIn("fast");
			   		if (Browser.Version() < 9) {
		   				$("#ieShadow").css({"display": "block" });
		   			}
	   			} 	

	

		}

		function loadAjax(type) {
	   			
	   			var url = "";
	   			if (type == "news") loadContent = "http://www.chapmancraig.com/" + lan + "footer/news/";
	   			if (type == "careers") loadContent = "http://www.chapmancraig.com/" + lan + "footer/careers/";
	   			if (type == "privacy") loadContent = "http://www.chapmancraig.com/" + lan + "footer/privacy-policy-and-terms/";
	   			if (type == "site-map") loadContent = "http://www.chapmancraig.com/" + lan + "footer/sitemap/";
	   			
		   		$(".footBoxContent").css({"display":"none"});

	   			$(".footBoxContent").load(loadContent, null, function() {
	   				$("#test").text($(".footBoxContent").height());
	   				
  					if (lan == "zh/") {$(".footRight").html("<a class='close'>关闭</a>");} else {$(".footRight").html("<a class='close'>CLOSE</a>");}
		   			$(".footBoxContent").css({"display":"block"});
		   			if (Browser.Version() < 9) {var h = $(".footBoxContent").height()+60;$("#ieShadow").height(h);}

		   			$(".close").click(function() {closeFooter();});
		   			if (type == "site-map") {
			   			$("#sitemap a").click(function() {

		   					window.location.href = $(this).attr("href");
				   			window.location.reload(true);
		   				});
					} else {	   				
						$(".footBoxContent a").click(function(event) {
							
							$(".footBoxContent").css({"display":"none"});
	   						event.preventDefault();   
	   						url = $(this).attr("href");		
	   						$(".footBoxContent").load(url, null, function() {
	   							if (Browser.Version() < 9) {var h = $(".footBoxContent").height()+60;$("#ieShadow").height(h);}
		   						$(".footBoxContent").css({"display":"block"});
		   						if (lan == "zh/") {
	   							$(".footRight").html("<a class='back'>返回</a>&nbsp;&nbsp; <a class='print'>列印</a>&nbsp;&nbsp; <a class='close'>关闭</a>");						
	   							} else {
	   							$(".footRight").html("<a class='back'>BACK</a>&nbsp;&nbsp; <a class='print'>PRINT</a>&nbsp;&nbsp; <a class='close'>CLOSE</a>");						
	   							
	   							}
	   							$("a.back").click(function() {$(".footBoxContent").css({"display":"none"});loadAjax(type);});	 
	   							$("a.close").click(function() {closeFooter();});
	   							if (lan == "zh/") {$("a.print").click(function() {openPrint(url + "?x=x");});}
	 							else {$("a.print").click(function() {openPrint(url + "?x=x");});}
	 							

	   						});
						});
					}
				});				
		
	   		}
	   		function closeFooter() {
	   			if (Browser.Version() < 9) {
	   				$("#ieShadow").css({"display": "none" });
	   			}

   				footBoxOpen = false;
   				$("#footBox").fadeOut("fast");
	   			$("#footArrow").fadeOut("fast");
	   		}
	   		
		function fromFlash(str) {  
			
			$(".people").css({"display":"block"});
			$(".people").load(manArray[str], null, function() {
				$(".people").css({"background":"none"});
			});
		}

	   		function openPrint(url) {
	   			window.open(url,'mywindow','width=600,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	   		
	   		}
		function resetSubpage(e) {
			if (e == 1) {
				$("."+sub).fadeOut("fast");
				$("#"+sub+" .subpage-first").delay(500).show("fast");	
				$("#"+sub+" .subpage").hide("fast");	
				$("."+sub+" li.current").removeClass("current");
				$("."+sub+" li:first-child").addClass("current");	
			} else if (e == 2) {
				if (Browser.Version() < 8) {
					$("#"+sub+" .subpage-first").css({"display": "none"});
					$("#"+sub+" .subpage").css({"display": "none"});
				} else {
					$("#"+sub+" .subpage-first").hide("fast");	
					$("#"+sub+" .subpage").hide("fast");	
				}
			}
		}
		
		function setSub(curr) {
			curr = curr.replace(/ /g, "-");
			curr = curr.toLowerCase();			
			//window.location.hash = curr;			
			curr2 = curr.substr(0,3);
			sub = curr2;
		}
		function setLanSwitch() {
		
			var lanUrl = window.location.href;
			var a = lanUrl.indexOf('#');
			//$("#test").text(a);
			
			if (lan == "zh/") {
				lanUrl = lanUrl.replace("zh/", "");
			} else {
				if (a == -1)
					lanUrl = lanUrl + "zh/";
				else
					lanUrl = lanUrl.replace("#", "zh/#");
			}
			$(".lanSwitch a").attr("href", lanUrl);
		
		}
		function moveRight() {
			var n = $(".menu li.current").nextAll().length;
			if (n > 0) { 
				lock = true;
				resetSubpage(1);
				$(".menu li.current").removeClass("current").next().addClass("current");				
				var p = $(".menu li.current").position();
				var w = $(".menu li.current").width();
				var l = ((origin.left + 25) + p.left + w/2);
				setSub($(".menu li.current").attr("id"));
				setLanSwitch();
				$("#scrollContent").animate({ "left": "-="+contentLength}, 1100, "easeOutExpo");
				$(".menu-arrow").animate({ "left": l}, 1100, "easeOutExpo", function() {			
					xx = $(".menu-arrow").position();
					if (Browser.Version() == 7) {$("."+sub).css("left", xx.left-32);} else {$("."+sub).css("left", xx.left-10);}
					
					$("."+sub).fadeIn("fast");	
						
					lock = false;
				});
			}
		}
		
		function moveLeft() {
			var n = $(".menu li.current").prevAll().length;
			
			if (n > 0) { // if there are elements on the left
				lock = true;
				resetSubpage(1);
				$(".menu li.current").removeClass("current").prev().addClass("current");	
				var p = $(".menu li.current").position();
				var w = $(".menu li.current").width();
				var l = ((origin.left + 25) + p.left + w/2);
				setSub($(".menu li.current").attr("id"));	
				setLanSwitch();
				$("#scrollContent").animate({ "left": "+="+contentLength}, 1100, "easeOutExpo");
				$(".menu-arrow").animate({ "left": l}, 1100, "easeOutExpo", function() {
					xx = $(".menu-arrow").position();
					if (Browser.Version() == 7) {$("."+sub).css("left", xx.left-32);} else {$("."+sub).css("left", xx.left-10);}
					$("."+sub).fadeIn("fast");
	
					lock = false;
				
				});
			}					
		}
		
		
		$(document).ready(function() {
			
			init();			
			
			$("#rightArrow").click(function(){
				if (!lock) { moveRight(); }
			});
			$("#leftArrow").click(function(){
				if (!lock) { moveLeft(); }
			});
			
			$(".menu li").click(function(){			
				if (!lock){						
					lock = true;
					resetSubpage(1);
					$(".menu li.current").removeClass("current");
					$(this).addClass("current");
					var n = $(".menu li.current").prevAll().length;
					var contentPos = n * contentLength;
					var p = $(".menu li.current").position();
					var w = $(".menu li.current").width();
					var l = ((origin.left + 25) + p.left + w/2);
					setSub($(".menu li.current").attr("id"));
					
					$("#scrollContent").animate({ "left": -contentPos}, 1100, "easeOutExpo");
					$(".menu-arrow").animate({ "left": l}, 1100, "easeOutExpo", function() {
						xx = $(".menu-arrow").position();
						if (Browser.Version() == 7) {$("."+sub).css("left", xx.left-32);} else {$("."+sub).css("left", xx.left-10);}
						$("."+sub).fadeIn("fast");	
						setLanSwitch();
						lock = false;
					});
				}
				
			});
			$(".subnav li").click(function(){
				if (!lock) {
					lock = true;
					resetSubpage(2);
					$("."+sub+" li.current").removeClass("current");
					$(this).addClass("current");
					var n = ($(".subnav li.current").prevAll().length + 1);				
					if (Browser.Version() < 8) {
						$("#"+sub+" .page" + n).css({"display": "block"});
						lock = false;
						setLanSwitch();
												
					} else {				
						$("#"+sub+" .page" + n).fadeIn("fast", function(){
							lock = false;
							setLanSwitch();
						});
					}
				
				}
			});
			
			$("#logo").click(function(){
				window.location.hash = "";
				location.reload(true);

			});
			
			$(document).keydown(function(event) {
	  			if (event.keyCode == '9') {
	  				if ($(".menu li.current").nextAll().length != 0)
		    			event.preventDefault();
	   			}
	   			if (event.keyCode == '39') {
	   				if ($(".about-us li.current").nextAll().length != 2) { // if not management page for cover flow
	   					if (!lock) { moveRight(); }
	   				}
	   			}
	   			if (event.keyCode == '37') {
	  	   			if ($(".about-us li.current").nextAll().length != 2) { // if not management page for cover flow
	   					if (!lock) { moveLeft(); }
	   				}
	   			}

	   		});
	   		
	   		$("#footer li").click(function() {
	   		
		   		var n = $(this).prevAll().length;
		   		openFooter(n);

	   		});
	   
	   	
	   			   		
// -------------------- NEWSBOX -------------------- //

			$("#newsBox a").click(function(event) {
				openFooter(4);
				//$(".footBoxContent").css({"display":"none"});
   				event.preventDefault();   
   				url = $(this).attr("href");		
   				$(".footBoxContent").load(url, null, function() {
   				if (Browser.Version() < 9) {var h = $(".footBoxContent").height()+60;$("#ieShadow").height(h);}
	   				$(".footBoxContent").css({"display":"block"});
	   				if (lan == "zh/") {
   						$(".footRight").html("<a class='back'>返回</a>&nbsp;&nbsp; <a class='print'>列印</a>&nbsp;&nbsp; <a class='close'>关闭</a>");		
   					} else {
   						$(".footRight").html("<a class='back'>BACK</a>&nbsp;&nbsp; <a class='print'>PRINT</a>&nbsp;&nbsp; <a class='close'>CLOSE</a>");
   					}
   					$("a.back").click(function() {$(".footBoxContent").css({"display":"none"});loadAjax("news");});	 
   					$("a.close").click(function() {closeFooter();});
   					$("a.print").click(function() {
   						//alert(url);
   						openPrint(url + '?x=x');
   					});
   				});
			});





// -------------------- SEARCH -------------------- //

	   		$(".search").focus(function(event) {
	   			$(this).val("");
	   			event.preventDefault();
	   		});
	   		
	   		$(".search").blur(function() {
	   			//$(this).val("SEARCH");
	   			//$(".ajaxSearch").html("");
	   		});
	   		$(".search").keydown(function(event) {
		   		if (event.keyCode == 13) {event.preventDefault();}
	   		});
	   		$(".search").keyup(function() {
		   		if ($(this).val().length == 0) {
		   			$(".ajaxSearch").html("");
		   			$(".ajaxSearch").css({"display": "none" });
		   		} else {
		   			$(".ajaxSearch").css({"display": "block" });
			   		if (lan == "zh/") {
			   			var thisUrl = "http://www.chapmancraig.com/zh/?s=+" + $(this).val();
			   		} else {
			   			var thisUrl = "http://www.chapmancraig.com/?s=+" + $(this).val();
			   		}
		   			$(".ajaxSearch").load(thisUrl, null, function() {
			   			$(".ajaxSearch a.l").click(function() {
			   				window.location.href = $(this).attr("href");
			   				window.location.reload(true);
			   			});		 
			   			$(".ajaxSearch .close").click(function() {
				   			$(".ajaxSearch").html("");
				   			$(".ajaxSearch").css({"display": "none" });
			   			});  				
		   			
		   			});
				}
	   			//$('#s').liveUpdate('ajaxSearch').focus();

	   		
	   		});
	   		
	   		
	   		
	   		
// -------------------- SERVICES -------------------- //

	   		$(".s1").hover(function() {
		   		$(".fundamental").html("");
	   			$(".fundamental").css({"display":"block"});
	   			$(".fundamental").load("http://www.chapmancraig.com/" + lan + "fundamentals/relationship/", null, function() {
	   				$(".fundamental").css({"background":"none"});	   			
	   			});
	   			$(".services-graphic").css({"background-position": "40px -0px"});	
	   		}, function() {
	   			$(".fundamental").css({"display":"none"});
	   			$(".services-graphic").css({"background-position": "40px -885px"});	
	   			$(".fundamental").css({"background":"url('http://www.chapmancraig.com/wp-content/themes/chapman/assets/images/ajax-loader.gif') 150px 30px no-repeat"});	   			
	   		});
	   		
			$(".s2").hover(function() {
		   		$(".fundamental").html("");
				$(".fundamental").css({"display":"block"});
	   			$(".fundamental").load("http://www.chapmancraig.com/" + lan + "fundamentals/performance/", null, function() {
	   				$(".fundamental").css({"background":"none"});	   			
	   			
	   			
	   			});
	   			
	   			$(".services-graphic").css({"background-position": "40px -581px"});	
	   		}, function() {
	   			$(".fundamental").css({"display":"none"});	   
	   			$(".services-graphic").css({"background-position": "40px -885px"});		
	   			$(".fundamental").css({"background":"url('http://www.chapmancraig.com/wp-content/themes/chapman/assets/images/ajax-loader.gif') 150px 30px no-repeat"});	
	   		});
	   		
			$(".s3").hover(function() {
		   		$(".fundamental").html("");
	   			$(".fundamental").css({"display":"block"});
	   			$(".fundamental").load("http://www.chapmancraig.com/" + lan + "fundamentals/transparency/", null, function() {
	   				$(".fundamental").css({"background":"none"});	   			
	   			
	   			
	   			});

	   			$(".services-graphic").css({"background-position": "40px -293px"});	
	   		}, function() {
	   			$(".fundamental").css({"background":"url('http://www.chapmancraig.com/wp-content/themes/chapman/assets/images/ajax-loader.gif') 150px 30px no-repeat"});	
	   			$(".services-graphic").css({"background-position": "40px -885px"});
	   			$(".fundamental").css({"display":"none"});	   			   		
	   		});
	   		
	   		
	   		
			
			
		});
