
var tN = {
/* ******definition of the library object ***************** */
/* ******SET STRING VARIABLES HERE ******* */
divWithAnchors: 'divTabLinks', // The div that holds that the tab links
divWithTabBoxes: 'divInTabsBody', // the containor div that holds the div's that swap
divTabsId: 'dTabs', // the class of the divs that swap, they all must have this class

/* ******METHODS HERE ******************** */
addEvent: function(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
},

init: function() {
	if (!document.getElementsByTagName || !document.getElementById) return;
	
	var getAnchors = document.getElementById(tN.divWithAnchors);
	var aObjs = getAnchors.getElementsByTagName('a');
	
	var getBoxes = document.getElementById(tN.divWithTabBoxes);
	var divList = getBoxes.getElementsByTagName('div');
	
	for (a=0; a<aObjs.length; a++) {
		tN.addEvent(aObjs[a], 'click', tN.swap, false);
		aObjs[a].onclick = tN.cancelClickSafari;
		
	}
	
	var counter = 0;
	var arrayNum = 0;
	while (counter<divList.length) {
		if (divList[counter].className==tN.divTabsId) {
			tN.liDivs[arrayNum] = divList[counter];
			counter++;
			arrayNum++;
		} else {
			counter++;
		}	
	}
},

swap: function(e) {
	//get the object
	if (e && e.target) {
		link = e.target;
		link.blur();
	}
	if (window.event && window.event.srcElement) {
		link = window.event.srcElement;
	}
	if (!link) return;
	var link = tN.ascendDOM(link, 'a'); //make sure it's the A
	
	var linkContainer = tN.ascendDOM(link, 'div');
	if(linkContainer == null) return;
	var allAnchors = linkContainer.getElementsByTagName('a'); //get all A's
	for (i=0; i<allAnchors.length; i++) { // set the classes to off and swap images
		allAnchors[i].className = "off";
			if (allAnchors[i].childNodes &&
			    allAnchors[i].childNodes[0].nodeName.toLowerCase() == 'img') {
					img_tag = allAnchors[i].childNodes[0];
					if (img_tag.src.indexOf('_on') != -1) {
						img_tag.src = img_tag.src.replace(/_on(\.[^.]+)$/, '_off$1');
					}
			} else {
				var linkLiOff = tN.ascendDOM(allAnchors[i], 'td');
				linkLiOff.className = "offTab";
			}
	} // turned off all A's
	
	link.className = "current"; //set clicked on A's class for checking later
	var linkLi = tN.ascendDOM(link, 'td');
	linkLi.className = "currentTab";

	var newDivList =  tN.liDivs; // get all tab DIV's
	if (newDivList==null) alert('no array');
	for (b=0; b<newDivList.length; b++) {
		newDivList[b].style.display = "none";
	} // turn them off
	
	if (allAnchors.length!=newDivList.length) alert('no match');
	
	for (d=0; d<allAnchors.length; d++) {
		if (allAnchors[d].className == "current") {
			newDivList[d].style.display = "block";
			tN.loadAjax(d+1); //Load the ajax
		} //turn on tabbed DIV
	}
	
	// keep links from working
	if (window.event) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	} else if (e) {
		e.stopPropagation();
		e.preventDefault();
	}
	
},
// this is special case for Safari to stop the links when clicked
cancelClickSafari: function() {
	return false;
	
},

// this is special case to load ajax when clicked
loadAjax: function(n) {
	eval("dTabsAjaxLoad" + n + "();");
	return false;
	
},
ascendDOM: function(e, target) {
	while (e.nodeName.toLowerCase() != target && e.nodeName.toLowerCase() != 'html') {
		e = e.parentNode;
	}
return (e.nodeName.toLowerCase() == 'html')? null : e;
},

liDivs: []
/* ******end of the library object ***************** */
}

tN.addEvent(window, 'load', tN.init, false);
