function GetUrlScriptname() {
	var test = location.pathname.lastIndexOf('/');
	var url = location.pathname.substring(test+1) + location.search;
	return decodeURI(url);
}

$(document).ready(function() {

	$('#nav a[href$="' + GetUrlScriptname() + '"]').each(function(){
		$(this).addClass('here');
		$(this).parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
		$(this).parent("LI").parent("UL").parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
	});

	/* Also say "Cart" in nav is "here" no matter the query string */
	var cartOn = false;
	$('#nav a[href$="cart.php"]').each(function(){
		if (GetUrlScriptname().split('?')[0] == 'cart.php')
		{
			$(this).addClass('here');
			$(this).parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
			$(this).parent("LI").parent("UL").parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
			cartOn = true;
		}
	});

	/* Always say portfolio is on when in /portfolio/ subdirectory */
	$('#nav a[href$="portfolio.php"]').each(function(){
		if (window.location.pathname.split('/')[1] == 'portfolio')
		{
			$(this).addClass('here');
			$(this).parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
			$(this).parent("LI").parent("UL").parent("LI").parent("UL").parent("LI").children("A").addClass('hereParent');
			cartOn = true;
		}
	});
	
	//Hide Client Access Menu (hack due to custom navigation set up - SAC 3/27/2011)
	if (cartOn) $('#nav a[href$="index.php"]').next("UL").hide();
	if (cartOn) $('#nav a[href$="contact.php"]').next("UL").hide();
	
	$(".popup").fancybox({
		'width'			: 550,
		'height'		: '75%',
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'			: 'iframe'
	});
	
	$(".popup-help").fancybox({
		'width'			: 550,
		'height'		: 200,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'			: 'iframe'
	});

	$(".popup-img").fancybox({
		'titleShow'     : false
	});
	
	/* External Links */
	$('a.external').click(function(e) {
		open(this.href);
		e.preventDefault();
	});
	$('FORM.external').click(function(e) {
		open(this.action);
		e.preventDefault();
	});
	$('A.external').append('<span class="externalIcon"></span>');
	
	
});
