// SHOW AND HIDE NAVIGATION
function showNav(nav) {
	// Hide all navigation
	switch (nav) {
		case 'offerings':
			document.getElementById('clientstories').style.height='14px';		
			document.getElementById('ourstory').style.height='14px';		
		break;
		case 'clientstories':
			document.getElementById('offerings').style.height='14px';		
			document.getElementById('ourstory').style.height='14px';			
		break;		
		case 'ourstory':
			document.getElementById('offerings').style.height='14px';		
			document.getElementById('clientstories').style.height='14px';			
		break;	
	}	
	// Show selected navigation
	document.getElementById(nav).style.height='auto';
}

// OPEN A PAGE IN A NEW WINDOW
// Create the new window
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {		
		var newWindow = window.open(this.getAttribute('href'), '', 'width=780, height=500, scrollbars=yes, resizable=yes, toolbar=yes, location=yes, directories=no, menubar=yes, copyhistory=no');
		if (newWindow) {
		    // For IE 8
			try {
		        if (newWindow.focus()) {
			        newWindow.focus();
			    }
		    }
		    catch(err) {		        
		        return false;		        
		    }	
		return false;
		}
	return true;
	}
}

// CALL THIS FUNCTION TO INITIATE FUNCTION THAT OPENS CERTAIN LINKS IN NEW WINDOWS
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {			
		// Find all links
		var link;
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html" - Use for PDF documents and the like
			if (/\bnon\-html\b/.test(link.className)) {				
				link.onclick = openInNewWindow;
			}
			// Find all links with a class name of "off-site" 
			else if (/\boff\-site\b/.test(link.className)) {				
				link.onclick = openInNewWindow;
			}			
		}	
	}
}

// LOOK FOR CLOAKED LINKS AND MAKE THEM CLICKABLE
// Hopefully this will help hide e-mail addresses from spam spiders
function createMailtoLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {			
		var email; // E-mail address
		var mailto; // The mailto hyperlink
		var cloak; // The mailto span element
		var spans = document.getElementsByTagName('span'); // Array of span elements
		for (var i = 0; i < spans.length; i++) {
			cloak = spans[i];
			// Find all span elements with a class name of "cloak"
			if (/\bcloak\b/.test(cloak.className)) {				
				email = cloak.innerHTML;
				cloak.innerHTML = "";									
				mailto = document.createElement('a');															
				mailto.href = 'mailto:' + email;
				mailto.innerHTML = email;
				cloak.appendChild(mailto);			
			}
		}	
	}
}

// ADD CLASSES
// Requires jQuery
function addClasses() {
	// Add classes to different types of links to control behavior
	$("a[href^=http://],a[href^=https://]").addClass("off-site");
	// Build selector for current host check
	var currentDomainSelector = "a[href*=" + window.location.host + "]";
	// Exclude certain links from off-site behavior
	$(currentDomainSelector).removeClass("off-site");
	$("a[href$=pdf],a[href$=jpg],a[href$=gif],a[href$=png],a[href$=sflb]").addClass("non-html");	
	$("a[href$=pdf,a[href*=PDFs").addClass("pdf");
}

// ON-LOAD EVENTS 
// Requires jQuery
$(document).ready(function() {
	addClasses();
	getNewWindowLinks();	
});