// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - ( event listener ) - - - - - - - -
// by Scott Andrew - http://scottandrew.com
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function addEvent(obj, evType, fn)
	{
	if (obj.addEventListener)
		{
		obj.addEventListener(evType, fn, false); 
		return true;
		}
	else if (obj.attachEvent)
		{
		var r = obj.attachEvent('on'+evType, fn);
		return r;
		}
	else
		{
		return false;
		}
	}

// http://www.themaninblue.com/experiment/ResolutionLayout/
function checkBrowserWidth()
{
// adjusted
	var corps = document.getElementsByTagName('body')[0];
	var theWidth = getBrowserWidth();

	if (theWidth <= 850)
	{//.replace(/(narrow)+/g, '')
		corps.className = bodCls;
		corps.className += ' narrow';
	} else if (theWidth > 1030 ) {
		corps.className = bodCls;
		corps.className += ' wide';
	} else {
		corps.className = bodCls;
	}
	
	return true;
}

// http://www.themaninblue.com/experiment/ResolutionLayout/
function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
}


function hideClick(e) {
 resetEverything();
 if(e.preventDefault) { e.preventDefault(); e.stopPropagation(); }
 return false;
}


// run all the onload scripts
function runScripts()
	{
	bodCls = document.getElementsByTagName('body')[0].className;
	var clicker = document.getElementById('mail-link');

	if(clicker) runCPrep();

	checkBrowserWidth();
	runLSPrep();
	xLinks();
	}

//http://www.sitepoint.com/article/standards-compliant-world/
//function externalLinks() {
function xLinks() {
 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";
 }
}

var bodCls;

window.onload = runScripts;

// http://www.themaninblue.com/experiment/ResolutionLayout/
window.onresize = checkBrowserWidth;