function getUrlVars(url) {
		var vars = [], hash;
		var hashes = url.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
  String.prototype.startsWith = function(str){
    return (this.indexOf(str) === 0);
}

  function highlightMenu() {
	var editMode = false;
	var url = window.location.pathname;
	if (url.startsWith('/editor')) {
		url = getUrlVars(window.location.href)["page"];
		editMode = true;
	}
	else {
		url = url.replace("http://", "").replace(window.location.host, "");
	}
	// loop the menus
	var lis = $("#nav li a");
	for (i =0; i < lis.length; i++) {
		var matchy;
		if (editMode) {
			matchy = getUrlVars(lis[i].href)["page"];}
		else {
			matchy = lis[i].href.replace("http://", "").replace(window.location.host, "");
		}
		
		matchy = matchy.substring(0, matchy.lastIndexOf("/"));
		if (url.startsWith(matchy)) {
			$("#nav li").removeClass("selected");
			$(lis[i]).parent().addClass("selected");
		}
	}
	// loop the submenus
/*	var slis = $("#subnav ul li a");
	for (i =0; i < slis.length; i++) {
		var matchy;
		if (editMode) {
			matchy = getUrlVars(slis[i].href)["page"];}
		else {
			matchy = slis[i].href.replace("http://", "").replace(window.location.host, "");
		}
		
		matchy = matchy.substring(0, matchy.lastIndexOf("/"));
		
		if (url.startsWith(matchy)) {
			$("#subnav ul li").removeClass("selected");
			$(slis[i]).parent().addClass("selected");
		}
	}*/
	
	// loop the third menus
/*	var thirdNav = $('.thirdnav');
	if (thirdNav.length > 0) {
		var slis = $(".thirdnav ul li a");
		for (i =0; i < slis.length; i++)
		{
			var matchy;
			if (editMode) {
				matchy = getUrlVars(slis[i].href)["page"];}
			else {
				matchy = slis[i].href.replace("http://", "").replace(window.location.host, "");
			}
			
			matchy = matchy.substring(0, matchy.lastIndexOf("/"));
			
			if (url.startsWith(matchy)) {
				$(".thirdnav ul li").removeClass("selected");
				$(slis[i]).parent().addClass("selected");
			}
		}
	}*/
  }

$(document).ready(function() {
	highlightMenu();

	$(".menucontent").slideToggle(10);
	$(".menutoggle").html("Open Menu")

	Cufon.replace('h1, h2, h3, .nav, .subnav, .thirdnav, p.intro');
	$('#searchbox').Watermark("Type here to search");

  //toggle the componenet with class msg_body
  $(".menutoggle").click(function()
  {  
	 if($(".menutoggle").html() == "Close Menu"){
		$(".menutoggle").html("Open Menu")
	 }
	 else{
		$(".menutoggle").html("Close Menu")
	 }
	 
	 $(".menu").toggleClass("extended");
	 $(".menutoggle").toggleClass("open");

    $(".menucontent").slideToggle(500);
  });
  
  $(".col1 p:first").addClass("intro");
   $(".col1home p:first").addClass("intro");
});

Cufon.replace('h1, h2, h3, h4, #navigation, #subnav, .thirdnav, p.intro');
