/* jQuery - execute these when the document is loaded. */
$(document).ready(function(){
	// * Set the background image on all Nav elements
	$("#menubar a").each(function(){
			// Use the ID as the background image file name and append '.jpg' to it
			$(this).css("background-image","url(images/"+$(this).attr('id')+".jpg)");
	})
	// Set the hover background image on all Nav elements
	.hover(function(e){
			$(this).css("background-image","url(images/"+$(this).attr('id')+"_f2.jpg)");
		},function(e){
			$(this).css("background-image","url(images/"+$(this).attr('id')+".jpg)");
		}
	);
	// Loop through the menu items and switch this page's image to the _f3 image 
	// First find the current page id
	var pageHref = window.location.pathname.replace(/^.*\/([^\/\?]*)/,"$1");
    $("#menubar a").each(function(i) {
    	//alert('pageHref = '+pageHref+', this href = '+$(this).attr("href")+', regexp='+$(this).attr("href").replace(/^.*\/([^\/\?]*)\??.*$/,"$1"));
		if ($(this).attr("href")==pageHref || 
				($(this).attr("href") == "/" && (pageHref=="" || pageHref=="index.html")) ||
				$(this).attr("href").replace(/^.*\/([^\/\?]*)\??.*$/,"$1")==pageHref)  {
			// this is the current page link - deactivate it and set the f3 image
			$(this).css("background-image",$(this).css("background-image").replace(/.jpg/,"_f3.jpg"))
			// Remove the link
			.removeAttr("href")
			// Unbind the mouseover and mouseout events on this so it doesn't hilite it when the mouse goes over
			.unbind("mouseover")
			.unbind("mouseout");
		}
	});
	// Preload hover images
	if (document.images) {
		home_f2 = new Image(126 ,53); home_f2.src = "images/home_f2.jpg";
		home_f1 = new Image(126 ,53); home_f1.src = "images/home.jpg";
		about_f2 = new Image(139 ,53); about_f2.src = "images/about_f2.jpg";
		about_f1 = new Image(139 ,53); about_f1.src = "images/about.jpg";
		register_f2 = new Image(168 ,53); register_f2.src = "images/register_f2.jpg";
		register_f1 = new Image(168 ,53); register_f1.src = "images/register.jpg";
		contact_f2 = new Image(176 ,53); contact_f2.src = "images/contact_f2.jpg";
		contact_f1 = new Image(176 ,53); contact_f1.src = "images/contact.jpg";
	}
  
});

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

