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

KM_MAP_WIDTH = 600;
KM_MAP_HEIGHT = 600;
//KM_FRONT_URL = 'http://fenouillet.local/flash/index.html';
KM_FRONT_URL = '/carte/flash/index.html';
KM_FRONT_MOVIE_NAME = 'km_fenou.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;
Kitmap.win = null;
Kitmap.scrollbarWidth = 0;
Kitmap.chromeWidth = 0;
Kitmap.chromeHeight = 0;
new Kitmap();

function Kitmap() {}

Kitmap.closeWin = function() {
	if (Kitmap.win == null) return;
	if (!Kitmap.win.closed) Kitmap.win.close();
	Kitmap.win = null;
};

Kitmap.openWin = function(url, width, height) {
	if (Kitmap.chromeHeight == 0) {
		Kitmap.win = window.open('about:blank', null, 'width=200,height=200,menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes');
		var win = Kitmap.win;
		win.document.open();
		win.document.write('<html><head><title></title></head><body style="margin:0px;border:0px none;overflow:hidden;">&nbsp;</body></html>');
		win.document.close();
		win.resizeTo(200, 200);
		Kitmap.chromeWidth = 200 - win.document.body.clientWidth;
		Kitmap.chromeHeight = 200 - win.document.body.clientHeight;
		win.document.open();
		win.document.write('<html><head><title></title></head><body style="margin:0px;border:0px none;"><img src="about:blank" width="1" height="500"></body></html>');
		win.document.close();
		Kitmap.scrollbarWidth = 200 - Kitmap.chromeWidth - win.document.body.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=yes,resizable=yes';
		Kitmap.win = window.open(url, null, feat);
	}
	Kitmap.win.moveTo(left, 0);
	Kitmap.win.resizeTo(width + Kitmap.chromeWidth, height + Kitmap.chromeHeight);
	Kitmap.win.location.href = url;
	Kitmap.win.focus();
};

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) {
	document.write(
	'<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>');
};

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);
};
