/* * * * * * *\ 
 * CONSTANTS *
\* * * * * * */
var NORTHWEST = 0;
var NORTHEAST = 1;
var SOUTHEAST = 2;
var CENTRAL   = 3;
var SOUTHWEST = 4;

/* * * * * * *\ 
 * FUNCTIONS *
\* * * * * * */
function Map() {
	var self = this;
	self.iRegion = null;
	self.oWindow = UI_Window("window", true, true, true);
	self.aMaps = new Array();
	self.oMapTable = document.getElementById("map_table");
	self.oAnimation = null;
	self.init = function() {
		self.aMaps.push(document.getElementById("map_north_west"));
		self.aMaps.push(document.getElementById("map_north_east"));
		self.aMaps.push(document.getElementById("map_east"));
		self.aMaps.push(document.getElementById("map_centre"));
		self.aMaps.push(document.getElementById("map_south_west"));

		self.oWindow.open = false;
		self.oAnimation = new Animation();
		self.oAnimation.addEvent(new AnimationEvent(self.aMaps[0], "opacity", 0.3, 0.9, 0, 500, AnimationAlgo.leaner, AnimationSetters.opacity));
		self.oWindow.windowPane.appendChild(self.generateCities());
	}
	self.mouseover = function(oEvent, iRegion) {
		oEvent = (oEvent?oEvent:event);
		if (self.iRegion == iRegion) return;
		self.oAnimation.aEvents[0].oObject = self.aMaps[iRegion];
		self.oAnimation.start(100);
		self.oMapTable.rows[iRegion+1].className = "map_table_row_over";
		self.iRegion = iRegion;
	}
	self.mouseout = function(oEvent, iRegion) {
		self.oMapTable.rows[iRegion+1].className = "map_table_row";
		AnimationSetters.opacity(self.aMaps[iRegion], null , 0.15);
		self.iRegion = null;
	}
	self.showRegion = function(sRegion) {
		self.oWindow.style.width = 500;
		self.oWindow.style.height = 500;
		UI.centerWindow(self.oWindow);
		var oAnimation = new Animation();
		oAnimation.addEvent(new AnimationEvent(self.oWindow, "opacity", 0.1, 0.9, 0, 500, AnimationAlgo.leaner, AnimationSetters.opacity));
		oAnimation.addEvent(new AnimationEvent(self.oWindow, "height", 20, 500, 0, 500, AnimationAlgo.leaner, AnimationSetters.style));
		oAnimation.start(100);
	}
	self.closeWindow = function() {
		self.oWindow.open = false;
		self.oWindow.style.display = "none";
	}
	self.generateCities = function(sRegion) {
		var oDiv = document.createElement("DIV");
		oDiv.className = "scrollpane";
		var oTable = oDiv.appendChild(document.createElement("TABLE"));
		oTable.className = "label";
		for (var i = 0; i < aCities.length; i++) {
			var oRow = oTable.insertRow(-1);
			var oCell =
			oRow.insertCell(-1).innerHTML = "<img src='styles/icons/open.png'/>";
			oRow.insertCell(-1).innerHTML =  aCities[i];
			if (aCities[i] == "Ottawa") {
				var oRow = oTable.insertRow(-1);
				oRow.insertCell(-1);
				var oCell = oRow.insertCell(-1);
				var sCity = "";
				for (var j = 0; j < aOttawa.length; j++) {
					sCity += "<tr><td><img src='styles/icons/open.png'/></td><td><a href=''>"+aOttawa[j]+"</a></td></tr>";
				}
				oCell.innerHTML = "<table class='label' style='white-space: nowrap;font-size:9pt'>" + sCity + "</table>";
			}
		}
		return oDiv;
	}

	self.init();
}