/**
 * Kabsel-Objekt zur Anzeige eines Modalen Dialogs, welcher die Landeswahl-Karte
 * fuer e-va.com enthaelt und jederzeit geoeffnet werden kann.
 */
CountryChanger = {
	hovermapInitialized : false,
	map : null,

	/**
	 * Initialisiert die HoverMap-Komponente fuer die Laendergrafik
	 */
	initHovermap : function() {
		// bisherige Kartenbereiche an die neue Karte anpassen (es muss nur
		// fuer alle das Offset angepasst werden, die relationen sind diesselben):
		mapLocations.cz.offset     = mapLocations.de.offset     = mapLocations.at.offset     = [-8,-26];
		mapLocations.btn_cz.offset = mapLocations.btn_de.offset = mapLocations.btn_at.offset = [-7,-27];

		// Fuer die Buttons muessen zusaetzlich die Koordinaten noch angepasst
		// werden, da sonst der Hover-Bereich nicht passt
		mapLocations.btn_cz.coords = [17,115,  125,115, 125,130, 17,130, 17,115];
		mapLocations.btn_de.coords = [17,61,   92,61,   92,77,   17,77,  17,61];
		mapLocations.btn_at.coords = [17,89,   81,89,   81,105,  17,105, 17,89];

		// Karte initialisieren und die auch schon bei der initialen Laenderauswahl
		// verwendeten Event-Verknuepfungen erzeugen
		var map = new HoverMap('countrychanger_laenderauswahl', mapLocations);
		map.setOverlayImage("http://www.e-va.com/le/de/media/neu_1/img/hovermap/blank.gif");

		map.addLocationEvent("de", "onmouseover", function(e, l) { map.showLocation("btn_de", false); });
		map.addLocationEvent("de", "onmouseout",  function(e, l) { map.hideLocation("btn_de"); });
		map.addLocationEvent("at", "onmouseover", function(e, l) { map.showLocation("btn_at", false); });
		map.addLocationEvent("at", "onmouseout",  function(e, l) { map.hideLocation("btn_at"); });
		map.addLocationEvent("cz", "onmouseover", function(e, l) { map.showLocation("btn_cz", false); });
		map.addLocationEvent("cz", "onmouseout",  function(e, l) { map.hideLocation("btn_cz"); });

		map.addLocationEvent("btn_de", "onmouseover", function(e, l) { map.showLocation("de", false); });
		map.addLocationEvent("btn_de", "onmouseout",  function(e, l) { map.hideLocation("de"); });
		map.addLocationEvent("btn_at", "onmouseover", function(e, l) { map.showLocation("at", false); });
		map.addLocationEvent("btn_at", "onmouseout",  function(e, l) { map.hideLocation("at"); });
		map.addLocationEvent("btn_cz", "onmouseover", function(e, l) { map.showLocation("cz", false); });
		map.addLocationEvent("btn_cz", "onmouseout",  function(e, l) { map.hideLocation("cz"); });

		map.init();

		// Im IE unter 7.0 muss wird die KArte nach oben verschoben, weswegen wir
		// zur Korrektur das Top-Padding erhoehen muessen
		var ieVersion = map.getInternetExplorerVersion();

		if(ieVersion >= 5.5 && ieVersion < 7) {
			var frame = document.getElementById("countrychanger_frame");
			frame.style.height = "299px";
			frame.style.paddingTop = "155px";
		}

		// Die Karte darf nur einmal initialisiert werden, also die Flag auf
		// true setzen
		this.hovermapInitialized = true;
	},

	/**
	 * Oeffnet die Laenderauswahl
	 */
	open : function() {
		var canvas = document.getElementById("countrychanger_canvas");
		var frame = document.getElementById("countrychanger_frame");

		if(
			typeof canvas == "object" && canvas != null &&
			typeof frame == "object" && frame != null
		) {
			if(!CountryChanger.hovermapInitialized) CountryChanger.initHovermap();
	
			var windowWidth  = window.innerWidth;
			var windowHeight = window.innerHeight;

			if(!windowWidth && !windowHeight) {
				if(document.compatMode == 'BackCompat') {
					windowWidth = document.body.offsetWidth;
					windowHeight = document.body.offsetHeight;
				} else {
					windowWidth = document.documentElement.clientWidth;
					windowHeight = document.documentElement.clientHeight;
				}
			}

			frame.style.left = ((windowWidth - frame.offsetWidth) / 2) + "px";
			frame.style.top = ((windowHeight - frame.offsetHeight) / 2) + "px";
			
			canvas.style.display = "block";
			frame.style.visibility = "visible";
		}
	},

	/**
	 * Schliesst die Laenderauswahl
	 */
	close : function() {
		var canvas = document.getElementById("countrychanger_canvas");
		var frame = document.getElementById("countrychanger_frame");

		if(
			typeof canvas == "object" && canvas != null &&
			typeof frame == "object" && frame != null
		) {
			canvas.style.display = "none";
			frame.style.visibility = "hidden";
		}
	}
}
