// main function that starts this all off
function initMap() {
  var allHokies = getElementsByClass('birdLoc');
  for(i = 0; i < allHokies.length; i++) {
    var theHokie = allHokies[i];
    theHokie.onclick     = clickHokie;
    theHokie.onmouseover = mouseOverHokie;
    theHokie.onmouseout  = mouseOutHokie;
  }
}

// returns whatever property you want to define for each node
function getProperty(id) {
  switch(id) {
    case 'hokie1' :
      return '#0000aa';
    case 'hokie2' :
      return '#00aa00';
    case 'hokie3' :
      return '#aa0000';
    default :
      return '#ffffff';
  }
}

function picFrameShow(argument) {
  var theFrame = document.getElementById('picFrame');
  theFrame.style.backgroundColor = argument;
  theFrame.style.display = 'block';
}

function picFrameHide() {
  document.getElementById('picFrame').style.display = 'none';
}

// by Dustin Diaz: http://www.dustindiaz.com/getelementsbyclass/
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;
}

// get the DOM node of the clicked-on span
function getDomNode(e) {
  var targ;
  if(e.target) {              // Gecko
    targ = e.target;
  } else if(e.srcElement) {    // Evil Empire
    targ = e.srcElement;
  } else {                    // Weird -- abort
    return null;
  }
  if(targ.nodeType == 3) {    // Cupertino hipsters
    targ = targ.parentNode;
  }
  
  return targ;
}

function clickHokie(e) {
  // now 'e' gives access to the event in all browsers
  if (!e) var e = window.event;
  
  // get the DOM node of the clicked-on span
  var targ = getDomNode(e);
  if(!targ) { return true; }
  
  alert("You clicked on a location.  A future\nedition will load the full-size picture.");
  return false;
}

function mouseOverHokie(e) {
  // now 'e' gives access to the event in all browsers
  if (!e) var e = window.event;
  
  // get the DOM node of the clicked-on span
  var targ = getDomNode(e);
  if(!targ) { return true; }
  
	picFrameShow(getProperty(targ.id));
	return false;
}

function mouseOutHokie(e) {
  // now 'e' gives access to the event in all browsers
  if (!e) var e = window.event;
  
  // get the DOM node of the clicked-on span
  var targ = getDomNode(e);
  if(!targ) { return true; }
  
  picFrameHide();
	return false;
}
