// kitmap/km_chalon.js
// (C) 2001-2006 Henri Médot
// dernière révision le 18.10.2006

KM_HOST = (location.host == 'plan.chalon.local') ? 'plan.chalon.local' : 'plan.chalon.fr';
KM_MAP_WIDTH = 630;
KM_MAP_HEIGHT = 630;
KM_FRONT_URL = 'http://' + KM_HOST + '/flash/index.html';
KM_FRONT_MOVIE_NAME = 'km_chalon.swf';
KM_FRONT_MOVIE_WIDTH = KM_MAP_WIDTH;
KM_FRONT_MOVIE_HEIGHT = KM_MAP_HEIGHT + 70;
KM_FRONT_WIDTH = KM_FRONT_MOVIE_WIDTH;
KM_FRONT_HEIGHT = KM_FRONT_MOVIE_HEIGHT;
KM_CUSTOM_URL = 'http://' + KM_HOST + '/flash/km_chalon_custom.php';
KM_CUSTOM_MOVIE_WIDTH = KM_MAP_WIDTH;
KM_CUSTOM_MOVIE_HEIGHT = KM_MAP_HEIGHT + 22;
KM_CUSTOM_WIDTH = KM_CUSTOM_MOVIE_WIDTH;
KM_CUSTOM_HEIGHT = KM_MAP_HEIGHT + 70;
Kitmap.win = null;
Kitmap.scrollbarWidth = 0;
Kitmap.chromeWidth = 0;
Kitmap.chromeHeight = 0;
new Kitmap();

function Kitmap() {}

Kitmap.closeWin = function() {
	try {
		if ((Kitmap.win != null) && (!Kitmap.win.closed)) {
			Kitmap.win.close();
		}
	}
	catch (ex) {
	}
	Kitmap.win = null;
};

Kitmap.openWin = function(url, width, height) {
	Kitmap.closeWin();
	if (Kitmap.chromeHeight == 0) {
		Kitmap.win = window.open('about:blank', '_blank', 'width=200,height=200,menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
		var win = Kitmap.win;
		win.document.open();
		win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
			+ '<html><head><title></title></head><body style="margin:0px;border:0px none;height:100%;">&nbsp;</body></html>');
		win.document.close();
		win.resizeTo(200, 200);
		if (win.innerWidth) {
			Kitmap.chromeWidth = 200 - win.innerWidth;
			Kitmap.chromeHeight = 200 - win.innerHeight;
		}
		else {
			Kitmap.chromeWidth = 200 - win.document.body.clientWidth;
			Kitmap.chromeHeight = 200 - win.document.body.clientHeight;
		}
		win.document.open();
		win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
			+ '<html><head><title></title></head><body style="margin:0px;border:0px none;">'
			+ '<div style="height:100px;overflow:scroll;"><img src="about:blank" width="1" height="500" /></div></body></html>');
		win.document.close();
		Kitmap.scrollbarWidth = 200 - Kitmap.chromeWidth - win.document.getElementsByTagName('div')[0].clientWidth;
	}
	if (height + Kitmap.chromeHeight > window.screen.availHeight) {
		height = window.screen.availHeight - Kitmap.chromeHeight;
		width += Kitmap.scrollbarWidth;
	}
	if (width + Kitmap.chromeWidth > window.screen.availWidth) width = window.screen.availWidth - Kitmap.chromeWidth;
	var left = Math.round((window.screen.availWidth - width - Kitmap.chromeWidth) / 2);
	if ((Kitmap.win == null) || (Kitmap.win.closed)) {
		var feat = 'width=' + width + ',height=' + height + ',left=' + left
			+ ',top=0,menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no';
		Kitmap.win = window.open(url, '_blank', feat);
	}
	else {
		Kitmap.win.moveTo(left, 0);
		Kitmap.win.resizeTo(width + Kitmap.chromeWidth, height + Kitmap.chromeHeight);
		Kitmap.win.location.href = url;
	}
};

Kitmap.hasOpener = function() {
	try {
		return (window.opener);
	}
	catch (ex) {
		return true;
	}
};

Kitmap.cookieToSearch = function() {
	var s = '?' + location.search.substr(1);
	var p = document.cookie.split('; ');
	for (var i = 0; i < p.length; i++) s += '&' + p[i];
	return s;
};

Kitmap.writeSwf = function(movie, width, height) {
	var html =
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"' +
		' width="' + width + '" height="' + height + '">' +
		'<param name="movie" value="' + movie + '" />' +
		'<param name="loop" value="false" />' +
		'<param name="menu" value="false" />' +
		'<param name="quality" value="high" />' +
		'<param name="bgcolor" value="#FFFFFF" />' +
		'<embed src="' + movie + '"' +
		' loop="false" menu="false" quality="high" bgcolor="#FFFFFF" width="' + width + '" height="' + height + '"' +
		' type="application/x-shockwave-flash"' +
		' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' +
		'</embed>' +
		'</object>';
	/*
	if (Kitmap.hasOpener()) {
		document.body.style.height = '100%';
		var divHeight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
		html = '<div style="height:' + divHeight + 'px;overflow:auto;">' + html + '</div>';
	}
	*/
	document.write(html);
};

Kitmap.writeFrontSwf = function() {
	Kitmap.writeSwf(KM_FRONT_MOVIE_NAME + Kitmap.cookieToSearch(), KM_FRONT_MOVIE_WIDTH, KM_FRONT_MOVIE_HEIGHT);
};

Kitmap.open = function() {
	var url = KM_FRONT_URL;
	if (arguments.length > 0) url += '?pid=' + arguments[0];
	Kitmap.openWin(url, KM_FRONT_WIDTH, KM_FRONT_HEIGHT);
};

Kitmap.openCustom = function() {
	if (Kitmap.hasOpener()) {
		location.href = KM_CUSTOM_URL;
	}
	else {
		Kitmap.openWin(KM_CUSTOM_URL, KM_CUSTOM_WIDTH, KM_CUSTOM_HEIGHT);
	}
};
