/**
* This script is similar to the pinball functionality.  It looks for all
* elements containing specified class and assigns onmouseover, onmouseout, and
* onmouseclick events.  This class adds the 'hover' class when moused over.  Be
* sure to have appropriate CSS for the 'hover' class.  When clicking on the
* element it will look for an anchor tag with an href attribute.  If no anchor
* tag or href attribute exist, the click will do nothing.  If more than one
* anchor tag with href exist in the element you will be sent to the location of
* the last href.  Call this script with the class of the elements to be clicked
* on.
* For example:
* var myAreaLinks = new AC.AreaLink('pinball-scoop');
*
* @author: stephanie trimble
*
*/        

if (typeof(AC) == "undefined") { AC = {}; }  

AC.AreaLink = Class.create();
AC.AreaLink.prototype = {

	linkHref: null,
	contentAreas: null,
	
	initialize: function(contentAreaClass) {

		this.contentAreas = document.getElementsByClassName(contentAreaClass);
		
		this.setMouseEvents();
		
	},
	
	setMouseEvents: function() {
		
		for(var i=this.contentAreas.length-1, area; area = this.contentAreas[i]; i--) {
			area.onmouseover = this.processMouseOver.bind(this, area);
			area.onmouseout = this.processMouseOut.bind(this, area);
			area.onclick = this.processMouseClick.bind(this, area);
		}
		
	},
	
	processMouseOver: function(area) {

		if(!Element.hasClassName(area, 'hover')) Element.addClassName(area, 'hover');
		
		return false;
	},
	
	processMouseOut: function(area) {
	
		if(Element.hasClassName(area, 'hover')) Element.removeClassName(area, 'hover');
		
		return false;
	},
	
	processMouseClick: function(area) {
	
		var areaElements = area.getElementsByTagName('*');
		for(var i=0, element; element = areaElements[i]; i++) {
			if(element.tagName.toLowerCase() == 'a') {
				var url = element.getAttribute('HREF');
				if(url != '' && url != null) window.location = url;
			}
		}
	
		return false;
	}
}

