  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 = $("ul.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)) {
			$("ul.nav li").removeClass("active");
			$(lis[i]).parent().addClass("active");
		}
	}
	// call this again to re-add the rules
	Cufon.replace('h1,h2,h3,.nav a');
  }

	$(document).ready(function() {
		highlightMenu();
		
		$('#select').Watermark('Postcode');
		$('#select3').Watermark('Enter email address');
		$('#searchbox').Watermark("Type here to search");
	});
	Cufon.replace('h1,h2,h3,.nav a');
