﻿function nhChangeTabBox(strBoxId, intWhichTab) {
	var boxObj = document.getElementById(strBoxId);
	var nestedDivs = boxObj.getElementsByTagName('div');
	var nestedImgs = boxObj.getElementsByTagName('img');
	var containerObj = boxObj.parentNode;
	var containerDivs = containerObj.getElementsByTagName('div');
	var boolLS;
	
	for(i=0;i<containerDivs.length;i++) { // set containerDiv indexes
		if(containerDivs[i].id == "nhTabContentOne") { var contentIndex1 = i; }
		if(containerDivs[i].id == "nhTabContentTwo") { var contentIndex2 = i; }	
	}

	if(intWhichTab == 1) {
		boxObj.style.backgroundPosition = "0 -86px";
	}
	else {
		boxObj.style.backgroundPosition = "0 -59px";
	}

	// change the active class & display/hide content
	switch(intWhichTab) {
		case 0: //user clicked on tab 1
			nestedDivs[0].className = "active";
			nestedDivs[1].className = "";

			containerDivs[contentIndex2].style.display = "none";
			containerDivs[contentIndex1].style.display = "block";			
			break;
		
		case 1: //user clicked on tab 2
			nestedDivs[0].className = "";
			nestedDivs[1].className = "active";

			containerDivs[contentIndex2].style.display = "block";
			containerDivs[contentIndex1].style.display = "none";			
			break;
	}

	// swap the image label
	for (i=0;i<nestedImgs.length;i++) {
		if(nestedImgs[i].id) {
			if (i == intWhichTab) {
				nhImgSwap(nestedImgs[i].id,1);
			} else {
				nhImgSwap(nestedImgs[i].id);
			}
		}
	}
	
	// append the onmouseover, onmouseout
	for(i=0;i<nestedImgs.length;i++) {
		var parentObj = nestedImgs[i].parentNode;
		if(intWhichTab != i) {
			parentObj.onmouseover = function() { nhTabBoxDivMouseOver(this); }
			parentObj.onmouseout = function() { nhTabBoxDivMouseOut(this); }
		}
		else {
			parentObj.onmouseout = function() {}
			parentObj.onmouseover = function() {}
		}
	}	
}

function nhTabBoxDivMouseOver(whichDiv) {
	if(whichDiv.childNodes[0]) {
		if(whichDiv.childNodes[0].nodeName.toLowerCase() == 'img') {
			var strSrc = whichDiv.childNodes[0].src;
			if (strSrc.indexOf('_over.gif') == -1) {
				intChop = strSrc.length - 4;	
				strEnd = '_over.gif';
			}
			if (typeof(intChop) != "undefined") {
				newSrc = strSrc.substring( 0, intChop );
			}
			if (typeof(strEnd) != "undefined") {
				whichDiv.childNodes[0].src = newSrc + strEnd;
			}
		}
	}
}

function nhTabBoxDivMouseOut(whichDiv) {
	if(whichDiv.childNodes[0]) {
		if(whichDiv.childNodes[0].nodeName.toLowerCase() == 'img') {
			var strSrc = whichDiv.childNodes[0].src;
			if (strSrc.indexOf('_over.gif') > -1) {	
				intChop = strSrc.length - 9;	
				strEnd = '.gif';
			}
			if (typeof(intChop) != "undefined") {
				newSrc = strSrc.substring( 0, intChop );
			}
			if (typeof(strEnd) != "undefined") {
				whichDiv.childNodes[0].src = newSrc + strEnd;
			}
		}
	}
}


function nhImgSwap( strId, intSwap ) {
	// assumes 2 images: image.gif and image_over.gif
	var imgObj = document.getElementById( strId );
	var strTemp = imgObj.src;
	var intStrLength = strTemp.length;
	var intChop, strEnd; 
	
	if ( intSwap ) {
		if (strTemp.indexOf('_over.gif') == -1) {
			intChop = intStrLength - 4;	
			strEnd = '_over.gif';
		}
	} else {
		if (strTemp.indexOf('_over.gif') > -1) {	
			intChop = intStrLength - 9;	
			strEnd = '.gif';
		}
	}
	
	if (typeof(intChop) != "undefined") {
		strTemp = strTemp.substring( 0, intChop );
	}
	
	if (typeof(strEnd) != "undefined") {
		imgObj.src = strTemp + strEnd;
	}	
}


