d = document;

JJ = {
	"addEvent" : function(o, ev, h) {
		var i, j;
		if (typeof(o) == "string") o = [g(o)];
		if (typeof(ev) == "string") {
			ev = [ev];
			h = [h];
		}
		for (i=0;i<o.length;i++) {
			for (j=0;j<ev.length;j++) {
				try {
					o[i].addEventListener(ev[j], h[j], (argument.length == 4 ? arguments[3] : false));
				}
				catch(err) {
					o[i]["on" + ev[j]] = h[j];
				}
			}
		}
	}
};

(function () {
	var i, j, v = 0, p = navigator.plugins.length, ua = navigator.userAgent;
	for (i=0;i<p;i++) {
		if (navigator.plugins[i].name.indexOf("Flash") != -1) {
			for (j=6;j<21;j++) {
				if (navigator.plugins[i].description.indexOf(j + ".") != -1) {
					v = j;
					break;
				}
			}
		}
		if (v > 0) break;
	}
	if (v == 0) {
		for (i=20;i>5;i--) {
			try {
				x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				v = i;
			}
			catch(e) {}
			if (v > 0) break;
		}
	}
	JJ.flashVersion = v;
	JJ.flash = (v >= 6);

	if (d.selection && this.clientInformation) {
		if (this.XMLHttpRequest) {
			if (this.JSON) {
				JJ.ua = "ie8";
			}
			else {
				JJ.ua = "ie7";
			}
		}
		else {
			JJ.ua = "ie6";
		}
	}
	else if (this.clientInformation && ua.indexOf("Chrome") != -1) {
		JJ.ua = "sa-ch";
	}
	else if (this.clientInformation) {
		JJ.ua = "sa";
	}
	else if (d.selection) {
		JJ.ua = "op";
	}
	else if (ua.indexOf("Firefox") != -1) {
		JJ.ua = "fx" + parseFloat(ua.substr(ua.indexOf("Firefox/") + 8, 3));
	}
})();

JJ.addEvent([window], "load", function() {
	if (JJ.flash) {
		d.getElementById("map").innerHTML = '<embed id="map-file" src="/flash/game-reserve-map.swf" loop="false" menu="false" quality="best" wmode="opaque" bgcolor="#550000" width="100%" height="100%" type="application/x-shockwave-flash" />';
		JJ.doc = (JJ.ua.indexOf("sa") == 0 ? d.body : d.documentElement);
		d.documentElement.style.overflowX = "hidden";
		JJ.addEvent([window], "resize", function() {
			var w = JJ.doc.offsetWidth;
			with (d.getElementById("map-file")) {
				width = w + "px";
				height = Math.floor(w * 362 / 375) + "px";
			}
		});
		window.onresize();
	}
	else {
		d.getElementById("map").innerHTML = '<img src="/images/game-reserve-map.png" alt="Map of iSimagaliso Wetland Park and Hluhluwe/Umfolozi Game Reserves in KwaZulu-Natal, South Africa" title="" />';
	}
});
