// JavaScript Document

// Evans careers javascript
// Relies on jquery.js stored in the /javascript directory of the Evans WCS store
// Last updated	11 March 2008

var Arcadia = {
	
	init : function() {
		Arcadia.highlightActiveNav();
		Arcadia.addToggles();
		Arcadia.addTargets();
		},
		
	// toggle each submenu
	addToggles : function() {
		$(".navtoggle/a").click( function() {
			$(this).siblings(".togglecontent").toggle();
			return false;
			});
		},
		
	// attach popup() function to a elements	
	addTargets : function() {
		$(".new_window").each( function() {
			this.title += " (this link will open in a new window)";
			$(this).click( function() {
				Arcadia.popup(this.href);
				return false;
				});
			});
		},
	
	// spawn a new browser window
	popup : function(url) {
		// declare width and height variables
		var w, h; 
		// specific window sizes
		if (url.toLowerCase().match("arcadia.evanslogin")) w = 610, h = 495;
		else if (url.toLowerCase().match("arcadia.evanscategories")) w = 800, h = 600;
		// build window attributes based on window specs above if required
		var attr = w ? "width=" + w + ",height=" + h + ",screenX=100,screenY=100,scrollbars=yes" : "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes";
		// open url in new window, focus and return false to cancel underlying link element action
		var win = window.open(url, "popup", attr);
		// focus on the window in case it's already open
		win.focus();
		},
		
	// add class name to feature menu links that match the current browser location
	highlightActiveNav : function() {
		// get each link within a feature menu that matches the current page url, and add a class to its parent element
		var url = location.href.toLowerCase(), rel = $("ul.subnav").attr("rel") || null;
		// update url to match home index file if we don't have an html page in the url
		if (! url.match(".html")) url = "/careers/index.html";
		if (rel) rel = rel.toLowerCase();
		$("#mainnav//a").each( function() {
			if (this.href.match(url) || this.href.match(rel)) {
				$(this).parents("li").addClass("navselect");
				$(this).parents(".togglecontent").toggle();
				}
			});
		}
	
	}
	
$(document).ready( function() {
	Arcadia.init();
	});
