var Sales = {	

	classExt : " personSelected",
	areaPrefix : "area_",
	personPrefix : "person_",

	currentPerson: "",
	
	createHighlighter: function() {
		//go through and find all areas, add onmouseover and onmouseout
		var map = document.getElementById("salesAreaMap");
		var areas = map.getElementsByTagName("area");
		for (var i=0; i < areas.length; i++) {
			var a = areas[i];			
			var f = this.toggle.bindWith(this, [a]);
			EventUtil.addListener(a, "mouseover", f);
			EventUtil.addListener(a, "mouseout", f);
			//EventUtil.addListener(a, "click", f);
		}
		
	},

	clear: function() {
		if (this.currentPerson == "") return;

		this.doSwitch(this.currentPerson);
	},

	toggle: function(elemRef) {
		//alert("clicked by : " + elemRef.id);
		var idStub = elemRef.id.substr(this.areaPrefix.length);
		var personId = this.personPrefix + idStub;
		//alert("person id : " + personId);		
		this.doSwitch(personId);
	},

	doSwitch: function(personId) {
		
        if (personId == this.currentPerson) {
			this.currentPerson = "";
            this.setPersonSelected(personId, false);
		} else { 
			if (this.currentPerson != "") {
				this.setPersonSelected(this.currentPerson, false);
			}
			this.setPersonSelected(personId, true);
			this.currentPerson = personId;
		}
	},

	setPersonSelected: function(personId, selected) {
		var ref = document.getElementById(personId);
		var pos = ref.className.indexOf(this.classExt);
		
		var isSelected = (pos != -1);

		if (isSelected == selected) return;

        
        if (selected) {
			ref.className += this.classExt;
		} else {
			ref.className = ref.className.substr(0, pos);
		}
	},

	isPersonSelected: function(personId) {
		var ref = document.getElementById(personId);

		return (ref.className.indexOf(this.classExt) != -1);
	}
};

