var regions;
var states;
var toTarget;

function showInformation() {
  
  if (!document.getElementsByTagName || !document.getElementById) return false;
  
  regions = document.getElementById("map");
  states = regions.getElementsByTagName("area");
   
  regions.onmouseout = function(e) {
  
      if (!e) e = window.event;
      
      if (window.event) {
        toTarget = e.toElement;
      } else {
        toTarget = e.relatedTarget;
      }
      
      for (i = 0; i < states.length; i++) {
      
      if (document.getElementById("d" + states[0].id) != null) {
        
        if (toTarget != null && toTarget.getAttribute("class") != "active" && !contains(this, toTarget)) {
          var currentState = document.getElementById("d" + states[i].id);
          currentState.className = "inactive";
        }
      }
    }
  };

  for (var i=0; i<states.length; i++) {
      
      var divs = regions.getElementsByTagName("div");
      for (var j=0; j<divs.length; j++) {
        if (divs[j].getAttribute("rel") == states[i].id) {
          divs[j].id = "d" + states[i].id;
          states[i].onmouseover = function() {
            changeMe(this.id, "active");
          };
          
          states[i].onmouseout = function(e) {  //don't hide onmouseover of contact section
            currentContact = document.getElementById("d" + this.id);
            //alert(currentContact.id);
          
            if (!e) e = window.event;
            
            if (window.event) {
              toTarget = e.toElement;
            } else {
              toTarget = e.relatedTarget;
            }
            
            //console.log(toTarget);
            
            if (toTarget != null && toTarget.getAttribute("class") != "active" && !contains(currentContact, toTarget)) { 
              //console.log(toTarget);
              changeMe(this.id, "inactive");
            }
          };
        }
      }
    }  
}

function changeMe(idToChange, myClassName) {
 // var divs = regions.getElementsByTagName("div");
	//	for (var j=0; j<divs.length; j++) {
		//	if (divs[j].getAttribute("rel") == idToChange) {
        var itemToChange = document.getElementById("d"+idToChange);
          itemToChange.className = myClassName;
			//}
		//} 
}

// Return true if node a contains node b
function contains(a, b) {

    if (a != null & b != null) {
  
        while (b.parentNode) {
    
            if ((b = b.parentNode) == a) {
                return true;
            }
        }
    }
    return false;
}