$(document).ready(function(){
  if (document.all) {
      $("#nav li").hoverClass ("sfHover");
			$("div#nav li li:last-child a").addClass("noBorder"); // Hide Last Border
  }

	$("#nav li").hover (function() { $(this.parentNode).addClass("sfHover"); }, function() { $(this.parentNode).removeClass("sfHover"); });
	
	$("span.email").each(function(){
		$(this).html("<a href=\"mailto:" + $(this).html().replace(/( \[at\] )/g, "@").replace(/( \[(dot|period)\] )/g, ".").replace(/( \[dash\] )/g, "-") + "\" title=\"Send an email\">" + $(this).html().replace(/( \[at\] )/g, "@").replace(/( \[(dot|period)\] )/g, ".").replace(/( \[dash\] )/g, "-") + "<\/a>");
	});

	$("a[@rel=external]").not("[@onclick]")
		.click(function(){
			window.open(this.getAttribute("href"));
			return false;
		})
		.each(function(){ this.title += ((this.title.length > 0) ? "" : this.innerHTML) + " (opens in a new window)"; }
	);
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};  

function formCallBefore(x) { 
  $("body").addClass("curWait");
	$(".error").removeClass("error");
  return true;
}
function formCallAfter(xml) { 
	$("body").removeClass("curWait");
	strError = "Unable to submit form. Please try again later...";
	strFocus = null;
	strRedirect = "";
	oReturnJSON = eval("data=" + xml);
	if (oReturnJSON) {
		strRedirect = oReturnJSON.redirecturl;
		strError = oReturnJSON.error.replace(/(&#9;)/g, "\t").replace(/(&#10;)/g, "\n");
		arrFocus = oReturnJSON.focus;
	}
	if (strError.length == 0) {
		window.location = strRedirect;
	} else {
		$("div.formErrors").html("<h3>Error<\/h3><ul>" + strError.replace(/(\t)(.+)/g, "<li>$2<\/li>") + "<\/ul>").filter(":hidden").fadeIn("normal");
		for (i=0;i<arrFocus.length;i++) {
			$("#" + arrFocus[i]).addClass("error");
		}
		alert("The following errors were encountered:\n" + strError);
		if ($(".error").get(0)) {
			$(".error").get(0).focus();
		}
	}
	return false; 
}

/* From: http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype */
$.create = function() {
   var ret = [], a = arguments, e, o, i=0, j, jq = $();
      a = a[0] instanceof Array ? a[0] : a;
      for (; i<a.length; i++) {
      if (a[i+1] instanceof Object) {
         e = ret[ret.length] = document.createElement(a[i]);
         for (j in a[++i]) { $.attr(e, j, a[i][j]); }
         if (a[i+1] instanceof Array) {
            o = $.create(a[++i]).cur;
            for (j=0; j<o.length; j++) { e.appendChild(o[j]); }
         }
      } else { ret[ret.length] = document.createTextNode(a[i]); }
   }
   jq.cur = ret;
   return jq;
}