/*
 * Handler for external links
 */
function processExternalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}

function removeAnchorFocusRings() {
     // for any 'a' element
     // take focus off of the link when it's clicked
     $('a').click(function() {
       this.blur();
     });	
}

/*
 * Navigation stuff
 */

var menuitems = {
	"home" : ["home.html", "internal", "no-scroll"],
	"bio" : ["bio.html", "internal", "scroll"],
	"press" : ["press.html", "internal", "scroll"],
	"shop" : ["shop.html", "internal", "scroll"],
	"contact" : ["contact.html", "internal", "scroll"],
	"links" : ["links.html", "internal", "scroll"],
	"myspace" : ["http://www.myspace.com/jacobzoid", "external", "no-scroll"]
}
	
function openPage(item) {
	
	var url = menuitems[item][0];
	var mode = menuitems[item][1];
	var scrollpane = menuitems[item][2] == "scroll";
	
	switch (mode) {
		case "internal":
			$("div#content").empty();
			$("div#content").fadeOut(100, function(){
				if (scrollpane) {
					$("div#content").append('<div id="pane"></div>');
					$("div#pane").load("content/" + url);
					
				} else {
					$("div#content").load("content/" + url);
				}
				
				$("div#content").fadeIn(500);
			});				
			break;
		
		case "external":
			window.open(url, item);
			break;
	}
	
}

/*
 * Executes when page is finished loading
 */
$(document).ready(function(){
	processExternalLinks();
	removeAnchorFocusRings();

	$('div#content').jScrollPane();

	$("div.jScrollPaneContainer").addClass("jScrollPaneContainerOverride");
});


