/********************************************************************/
/*                        Core functions                            */
/********************************************************************/

var minFlashVersion = '9,0,45';
var loaderOid = 'loader';

/* Check whether the bowser is Internet Explorer */
function isIE() {
	return navigator.appName.indexOf('Microsoft') != -1 || navigator.appName.indexOf('Opera') != -1;
}

/* Check whether the bowser is Opera */
function isOpera() {
	return navigator.appName.indexOf('Opera') != -1;
}

/* Launch popup window */
function popup(url, resizable) {
	if (isOpera())
		window.open(url);
	else
		window.open(url, '', 'width=500,height=500,left=0,top=0,toolbar=No,scrollbars=Yes,location=No,status=No,resizable=Yes,fullscreen=No,menubar=No');
}

/* Launch new browser window */
function newWindow(url) {
	window.open(url, '', 'toolbar=Yes,location=Yes,directories=Yes,resizable=Yes,scrollbars=Yes,status=Yes,menubar=Yes');
}

/* Get the Flash movie */
function getFlashMovie() {
	var flashid = loaderOid;
	return isIE() ? window[flashid] : document[flashid];
}

/* Resize the size of the flash object */
function onFlashResize(width,height) {
	if (getFlashMovie().width.indexOf('%') == -1)
		getFlashMovie().width = width;
	getFlashMovie().height = height;
}

/* Format and return the content of the player object */
function buildPlayerObject(base, puzzleFile, bgColor, resizable) {
	var movie = base + '/core/genloader.swf';
	var width = resizable ? '400' : '100%';
	var suggestsize = resizable ? 'both' : 'height';
	var enablezoom = resizable ? 'true' : 'false';
	return (
		'<object id="' + loaderOid + '" type="application/x-shockwave-flash" data="' + movie + '" width="' + width + '" height="200">' +
			'<param name="quality" value="high" />' +
			'<param name="movie" value="' + movie + '" />' +
			'<param name="bgcolor" value="' + bgColor + '" />' +
			'<param name="base" value="' + base + '/" />' +
			'<param name="flashVars" value="cafurl=' + puzzleFile + '&amp;configurl=core/config.xml&amp;mode=player&amp;bgcol=' + bgColor + '&amp;loadurl=cookie&amp;saveurl=cookie&amp;suggestsize=' + suggestsize + '&amp;enablezoom=' + enablezoom + '" />' +
		'</object>');
}

/* Format and return the content of Flash player version check object */
function buildVersionCheckObject(base, url) {
	var movie = base + '/core/versioncheck.swf';
	return (
		'<object type="application/x-shockwave-flash" data="' + movie + '" width="1" height="1">' +
			'<param name="quality" value="high" />' +
			'<param name="movie" value="' + movie + '" />' +
			'<param name="flashVars" value="flashversion=' + minFlashVersion + '&amp;updateflashurl=' + url + '" />' +
		'</object>');
}
