   /*!
	* Shalom Counselling 
	* misc functions 
	* Copyright 2011 Wes Reimer 
	*/
	
	(function(window, document) { // Immediately-Invoked Function Expression to privatize vars and compress window & document refs
	
	
	 var Shalom = {
	  
		fixLinks : function() {
			var linkPath,
				indexPath,
				path = location.pathname.replace(/^\//, ""), // IE includes leading slash
				host = location.hostname;

			$("#nav a").each( function() {
				linkPath = this.pathname.replace(/^\//, "");
				indexPath = linkPath.replace(/index\.s?html?/, "");
			//	console.log(linkPath + " | " + indexPath  + " | " + path);
				if (indexPath==path || linkPath==path || path.indexOf(linkPath) > -1) {
					$(this).addClass("selected").parent().parent().prev().addClass("selected");
				}
			});
			
			$("#main a, footer a").each(function() {
				var a = this;
				// is it external or a PDF?
				if ( !a.target && 
					(a.hostname.indexOf(host) == -1 || /\.pdf$/i.test(a.pathname)) ) {
						//console.log(a.hostname, a.hostname.indexOf(hostName));
						 a.target = "_blank";
						if (!a.title) {
							a.title = "Opens in new tab or window";
						}
				}
			});
			
			$("#emailLink").click(function(e) {	
				e.preventDefault();
				var addr = Shalom.getAddr("admin");
				$(this).html(addr).attr("href", "mailto:" + addr).unbind();
		   });
			
			$("#vcfLink").attr("href", "shalom.vcf");
		},
		
		getAddr : function(name) {
			return name + String.fromCharCode(64) + location.hostname.replace("www.","");
		},
		
		setupForm : function() {
			var $form = $("#contact"),
				$name = $("#realname"),
				$phone = $("#phone"),
				$message = $("#message"),
				$spam = $("#comments"),
				$fineprint = $form.find(".fineprint"),
				origMsg = $fineprint.html(),
				btn = $("#submitBtn")[0];
				
			$form.submit( function(e) {
				if ( $spam.val() ) { //spam trap populated
					e.preventDefault();
					return false;
				}
				$spam.remove(); // remove fake 'comments' element so it doesn't get submitted
				if ( ! $.trim( $message.val() ) ) {
					$message.val("Please call me about counselling.");
				}
				this.recipient.value = Shalom.getAddr("admin");
				this.action = "http://www.execulink.com/cgi-bin/formmail.pl";
				
			}).find("input").keyup( function() {
				if ( $name.val().length > 1 && $phone.val().length > 6 ) {
					btn.disabled = false;
					$fineprint.html(" (click once) ");
				} else {
					btn.disabled = true;
					$fineprint.html(origMsg);
				}
			});
		}
	 
	 }; 
	 
	 
	 
	 
	 	$(function() {
			Shalom.fixLinks();
			Shalom.setupForm();
		});
	 
	 
	 
	})(this, document);
	
	
	
if (typeof console=="undefined") {
	console = { log : function(){} };
}
