function headerLink() {
	$("header.global").children('img','h1','h2').click(function() {
		window.location = "index.php";
	});
}

function highlightNav() {
	$("nav.global > ul > li").hover(
		function () {
			$(this).find("a:first").css({'text-decoration': 'underline', 'background-color': '#414141'});
		},
		function () {
			$(this).find("a:first").css({'text-decoration': 'none', 'background-color': '#000000'});
		}
	);
	$("nav.global > ul > li > ul > li").hover(
		function () {
			$(this).find("a").css({'background-color': '#414141'});
		},
		function () {
			$(this).find("a").css({'background-color': '#000000'});
		}
	);

	$("li.headlink a").click( function() {
		//Save original width of link
		if (typeof($(this).data('originW')) == 'undefined') {
			$(this).data('originW',$(this).width()); }
		var testWidth = $(this).data('originW');

		var n = $(this).siblings('ul').length;
		//if (typeof(openSubNav == 1)) { //Display sublinks
		if (n == 1) {
			$(this).animate({width: "160px"}, 400);
			$(this).siblings('ul').show(450);			
			$(this).parent().bind('mouseleave mouseup', function() {
				$(this).children('ul').hide(250);
				$(this).children('a').animate({width: testWidth}, 300);
			});
		}
		else {
			$(this).siblings('ul').hide(250);
			$(this).animate({width: testWidth}, 300);
		}
		
	});
}

function linkContent() {
 	$("a.sublink").click( function(event) {
		event.preventDefault();
		var pageToLoad = this.getAttribute('href');
		$("#siteContent").load(pageToLoad);
		//console.log(".load() fired by linkContent()");
		//$.address.value($(this).attr('href'));
		return false;
	});
}

function mainmenu(){
	$("nav.global ul ul").css({display: "none"}); // Opera Fix
}

/* function mainmenu(){
	$("nav.global ul ul").css({display: "none"}); // Opera Fix
} */

function parseUrl() {
	var data = "http://localhost/dev/drgriffies.old/httpdocs/gallery.asp";
    var e=/^((http|ftp):\/)?\/?[^:\/\s]+((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?$/;
	var f = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	
    if (data.match(f)) {
/*         return  {url: RegExp['$&'],
                protocol: RegExp.$2,
                host:RegExp.$2,
                path:RegExp.$3,
                file:RegExp.$4,
                hash:RegExp.$7};
 */		return data.match(f);
	}
    else {
        return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
    }
}

function getCurDir(lookDir) {
	var dir = lookDir.split('/');
	var cdir = dir[dir.length-2];
	//console.log(cdir);
	return cdir;
}

function loadHomePage(currentURL) {
	var lookHash = new RegExp("\\?+|#+");
	var lookHashEnd = new RegExp("\\?$|#$");
	if (!currentURL.match(lookHash)) {
		var lookIndex = new RegExp("\/index\.(php|htm|html)$|\/$");
		if (currentURL.match(lookIndex)) {
			$("#siteContent").load("home.php");
		}
	}
	else if (currentURL.match(lookHashEnd)) {
		$("#siteContent").load("home.php");
	}
	else {
		return false;
	}

}

function alternateEven() {
	$(this).addClass('alternate');
}


	$(window).live("load",function(){
		$('tr').attr("jsaction","dirapi.showMapBlowupForWaypoint").children().css("background-color","black");
	});

$(document).ready(function() {

	headerLink();
	mainmenu();
	highlightNav();
	loadHomePage(location.href);

	if($.browser.msie && $.browser.version == 8) {
	    $('#ie-info').text('You are using IE8 in version '+ document.documentMode +' compatible mode.');
	}

	$.history.init(function (hash) {
		if(hash) {
		    $("#siteContent").load(hash);
		} else {
		    // start page
		    $("#siteContent").load('home.php');
		}
		$('#hash-input').val(hash);
	});

	function loadHistory(hash) {
	    $.history.load(hash);
	}
	
	$("a.sublink").live("click", function() {
		var href = $(this).attr('href');
		hash = href.replace(/^.*?#/, '');
		loadHistory(hash);
		return false;
	});
    
   	$(".address").live("click", function() {
		var href = 'about.map.php';
		hash = href.replace(/^.*?#/, '');
		loadHistory(hash);
		return false;
	});
	
	$('.slideshow').cycle({
		fx:				'fade',
		random:			1,
		startingSlide:	0,
		pause:			1,
		prev:			'.slideshow img',
		requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded 
		requeueTimeout: 250 // ms delay for requeue 
	});

});

	
/* 	.live(function() {
		$("div#directions").children("table").removeAttr('style');
	}); */
	
/* 	$('tr').attr("jsaction","dirapi.showMapBlowupForWaypoint").each().live(function() {
		alert("success");
	});
 */

/* 	$('tr').attr("jsaction","dirapi.showMapBlowupForWaypoint").each().live(function() {
		this.removeAttr("style");
		//$('tr').attr("jsaction","dirapi.showMapBlowupForWaypoint").each().removeAttr("style");
	}); */
