/* When window loads, activate these functions */
onload = function() {
	changeCurrentLink();
	externalLinks();
}

function externalLinks() {   
 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";   
 }   
}   


/* Returns the string of the current page */
function currentPage() {
	var pagePath = window.location.pathname;
	return pagePath.substring(pagePath.lastIndexOf('/') + 1);
}

/* Sets current page menu link to look different from other pages. */
function changeCurrentLink() {
	var path = window.location.pathname;
	var currentPage = path.substring(path.lastIndexOf('/') + 1);
	
	switch(currentPage) {
		case "index.html":
			document.getElementById("indexMenu").setAttribute("class", "menu selected");
		break;
		case "promotions.html":
			document.getElementById("promotionsMenu").setAttribute("class", "menu selected");
		break;
		case "products.html":
			document.getElementById("productsMenu").setAttribute("class", "menu selected");
		break;
		case "staff.html":
			document.getElementById("staffMenu").setAttribute("class", "menu selected");
		break;
		case "contact.html":
			document.getElementById("contactMenu").setAttribute("class", "menu selected");
		break;
	}
}	
