/*
rollover functions

pulls in the image path and appends the on/off state suffixes
'e' is most easily referenced by 'this'.

'imgname' is easily referenced by 'this.id', where the id attribute is the same
as the image's filename sans the _on/_off formats.

*/

function onImg(e,imgname)
{
	var img = e.src;
	var base = img.substring(0,img.lastIndexOf('/')) + '/';
	var iName = base + imgname + "_on.gif";
	e.src = iName;
}

function offImg(e,imgname)
{
	var img = e.src;
	var base = img.substring(0,img.lastIndexOf('/')) + '/';
	var iName = base + imgname + "_off.gif";
	e.src = iName;
}


function addParents(targetTag, targetClass, parentTag, howMany) {

	/*
	 *  addParents v1.4
	 *      by Kevin C. Smith <http://centricle.com>
	 *
	 *  Latest Version:
	 *      <http://centricle.com/lab/dom/add-parents/>
	 *
	 *  Parameters:
	 *  ===========
	 *    targetTag
	 *        Which elements are affected.
	 *    targetClass
	 *       Constrain to elements with a specific className.
	 *       If false, all `targetTag` elements are affected.
	 *    parentTag
	 *       What kind of elements used for parent(s).
	 *    howMany
	 *       Number of parent elements added.
	 *  
	 *  Description:
	 *  ============
	 *  This function wraps `howMany` elements around all `targetTag`
	 *  elements with a className matching targetClass. Each new
	 *  parent element is given a className based on `targetClass`.
	 *  
	 *  If `targetClass` is false, the parents' className is based
	 *  on `targetTag`.
	 *
	 *  Usage:
	 *  ======
	 *  Calling the function thus:
	 *  
	 *  window.onload = function() {
	 *      addParents('abbr', 'foo', 'span', 3);
	 *      addParents('p', 'bar', 'div', 4);
	 *      addParents('em', false, 'span', 2);
	 *  }
	 *
	 *  creates the following when the page loads:
	 *  
	 *  1. three new SPANs (span.foo1, span.foo2, and span.foo3)
	 *     around all ABBR elements with a className of 'foo',
	 *  2. four new DIVs (div.bar1, div.bar2, div.bar3, div.bar3, 
	 *     div.bar4) around all P elements with a className of 'bar'.
	 *  3. two new SPANs (span.em1 and span.em2) around *all* EM 
	 *     elements, regardless of their className.
	 *  
	 */

	var theElements = document.getElementsByTagName(targetTag);

	var workingSet = new Array();

	for ( var i = 0; i < theElements.length; i++ ) {
		if ( !targetClass || theElements[i].className == targetClass ) {
			workingSet[workingSet.length] = theElements[i];
		}
	}

	for ( var i = 0; i < workingSet.length; i++ ) {

		// grab target element's info
		var theID = workingSet[i].id;
		var theClassName = workingSet[i].className;
		var theGuts = workingSet[i].innerHTML;

		// make a copy (Safari chokes on cloneNode())
		var theClone = document.createElement(targetTag);
		if ( theID != '' ) // don't give it an empty ID
			theClone.id = theID;
		if ( theClassName != '' ) // or an empty className
			theClone.className = theClassName;
		theClone.innerHTML = theGuts;

		var wrap = new Array();

		for ( var c = 1; c < howMany+1; c++ ) {

			wrap[c] = document.createElement(parentTag);

			wrap[c].className = ( targetClass != '' )
				? targetClass + c : targetTag + c;

			if ( c == 1 ) { // first run
				// replace target element with a wrapper
				elParent = workingSet[i].parentNode;
				elParent.replaceChild(wrap[c], workingSet[i]); 
			} else {
				// insert previous wrapper
				wrap[c-1].appendChild(wrap[c]);
			}

			if ( c == howMany ) { // end of the line
				// bring back the [clone of the] target element
				wrap[c].appendChild(theClone);
			}

		}
	}
}
/* end add parents */



window.onload = function() {
	addParents('div', 'blue', 'div', 3);
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

}	
