$.MyTools = function () { }
$.MyTools.getPagefromHref = function (href) {
    try { 
		var Search = new RegExp(/index\.php/g);
        if (Search.test(href) === true) { 
			
			var hrefParts = href.split(/\?/);
			var pagePair = hrefParts[1].match(/page=[^\&]+/);
  			var pageParts = pagePair[0].split(/=/);
			var contentPage = pageParts[1];
		} else {
			
			var newHref = href.match(/.*\/(.+)/);
			var contentPage = newHref[1];
		}
    } catch(err) {
        return false;
    }
    var Search = null;
    return contentPage;
}

$.Navigation = function () { }
$.Navigation.initialize = function () {
    var contentDir  = "./content/";
    var previousTab = "home";
	var subNav      = false;


    $("a.nav").click( function() {
        //extract content from href
        var Page = $.MyTools.getPagefromHref(this.href);
		
        if (Page === false) {
            Page = "error.html";
        }
        
        var id = this.id;

        if (id != previousTab) {
            $("#" + previousTab).removeClass("active");
            $("#" + id).addClass("active");
            $("#content").load(contentDir + Page);
            previousTab = id;
			subNav = false;
        } else if ( subNav ) {
			$("#content").load(contentDir + Page);
		}
        return false;
    });
    
    $("a:not(.nav, [href^='mailto'])").live("click", function () {
        var Page = $.MyTools.getPagefromHref(this.href);
        var isExternal = /^http/g;

        if (Page === false) {
            Page = "error.html";
        }
        
        if (isExternal.test(Page)) {
			window.open(Page);
		} else {
			$("#content").load(contentDir + Page);
			subNav = true;
		}
		

        return false;
    });
}
