
// zakness - common functions
// Author: Zach Linder
// Feel free to grab any (small) part of this code, I hope you'll find it useful!


// hide email address from spiders
function email(show) {
	a="zak"; b="ness"; c="@"; d=".com"; e="gma"; f="il";
	addy = a+b+c+e+f+d;
	document.write("<a href=\"mailto:"+addy+"\" title=\""+addy+"\">"+show+"</a>");
}

function homeLink(evt) {
	window.location.href="http://www.zakness.com/";	
}

// active subnav title list item
var act_sub = null;

// display item title on mouseover
function subnavOver(evt) {
	if (act_sub) document.getElementById(act_sub).style['display'] = 'none';
	var node;
	if (evt) node = evt.target; // good browsers
	else node = window.event.srcElement; // bad browsers
	while (node) {
		if (node.nodeName == "LI") break;
		node = node.parentNode;
	}
	var id = 's' + node.attributes.getNamedItem('id').nodeValue;
	document.getElementById(id).style['display'] = 'inline';
	act_sub = id;
}

// clear subnav title
function subnavOut(evt) {
	if (act_sub) {
		document.getElementById(act_sub).style['display'] = 'none';
		act_sub = null;
	}
}

// initialize event listeners
function setup() {
	// zakness logo link to index
	var obj = document.getElementById('home-link');
	if (obj.addEventListener) { // good browsers
		obj.addEventListener('click',homeLink,false);
	} else { // bad browsers
		obj.onclick = homeLink;
	}
	
	// subnav title mouseovers
	var sn = document.getElementById('subnav');
	if (sn && (sntitles = sn.getElementsByTagName('li'))) {
		for (var i=0; i<sntitles.length; i++) {
			var node = sntitles[i];
			var id = node.attributes.getNamedItem('id');
			// is the list item a title?
			if (id && id.nodeValue.indexOf('t') == 0) {
				if (node.addEventListener) {	// good browsers
					node.addEventListener('mouseover',subnavOver,false);
					node.addEventListener('mouseout',subnavOut,false);
				} else {	// bad browsers
					node.onmouseover = subnavOver;
					node.onmouseout = subnavOut;
				}
			}
		}
	}
}
window.onload = setup;
