// Calls 'func' on 'eventName' in 'obj'
function addEvent(obj, eventName, func)
{
	if(obj.addEventListener)
		return obj.addEventListener(eventName, func, true);
	else if(obj.attachEvent)
	{
		obj.attachEvent("on" + eventName, func);
		return true;
	}
	return false;
}


function setupRollovers() {
  if (!document.getElementsByTagName)
    return;
  var all_links = document.getElementsByTagName('a');
  for (var i = 0; i < all_links.length; i++) {
    var link = all_links[i]; 
    if (link.className && (' ' + link.className + ' ').indexOf(' rollover ') != -1) {
     // if (link.childNodes && link.childNodes.length == 1 && link.childNodes[0].nodeName.toLowerCase() == 'img' && link.childNodes[0].id != thispage) {
	  if (link.childNodes && link.childNodes.length == 1 && link.childNodes[0].nodeName.toLowerCase() == 'img') {
        link.onmouseover = mouseover;
        link.onmouseout = mouseout;
		// pre-load the 'over' image
		var img = link.getElementsByTagName("img");
		pic = new Image(); 
		pic.src = img[0].src.replace(/(\.[^.]+)$/, '_over$1');
      }
    }
  }
}

function setOnImage(){
	document.getElementById(thispage).src = document.getElementById(thispage).src.replace(/(\.[^.]+)$/, '_over$1');
}

function find_target(e)
{
  var target; 

  if (window.event && window.event.srcElement) 
    target = window.event.srcElement;
  else if (e && e.target)
    target = e.target;
  if (!target)
    return null;

  while (target != document.body &&
      target.nodeName.toLowerCase() != 'a')
    target = target.parentNode;

  if (target.nodeName.toLowerCase() != 'a')
    return null;

  return target;
}

function mouseover(e) {
  var target = find_target(e);
  if (!target) return;

  // the only child node of the a tag in target will be an img tag
  var img_tag = target.childNodes[0];

  // Take the "src", which names an image called "something.ext",
  // Make it point to "something_over.ext"
  img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '_over$1');
}

function mouseout(e) {
  var target = find_target(e);
  if (!target) return;

  // the only child node of the A-tag in |target| will be an IMG-tag
  var img_tag = target.childNodes[0];

  // Take the "src", which names an image as "something_over.ext",
  // Make it point to "something.ext"
  // This is done with a regular expression
  img_tag.src = img_tag.src.replace(/_over(\.[^.]+)$/, '$1');
}

// When the page loads, set up the rollovers
addEvent(window,"load",setupRollovers);
//addEvent(window,"load",setOnImage);


function getElementsByClass(searchClass,node,tag) 
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function highNav(el)
{
	var a = getElementsByClass("rollover");
	for (i=0; i < a.length; i++) {
		if(a[i].href.toLowerCase().indexOf(el.toLowerCase()) != -1){
			var img_tag = a[i].childNodes[0];
			img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '_over$1');
		}
	}
}

function unhighNav(el)
{
	var a = getElementsByClass("rollover");
	for (i=0; i < a.length; i++) {
		if(a[i].href.toLowerCase().indexOf(el.toLowerCase()) != -1){
			var img_tag = a[i].childNodes[0];
			img_tag.src = img_tag.src.replace(/_over(\.[^.]+)$/, '$1');
		}
	}
}

