/********************************************************************/
/*                        Core functions                            */
/********************************************************************/

/* 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 = "loader";
	return isIE() ? window[flashid] : document[flashid];
}

/* Get the inner width of the window */
function getInnerWidth() {
	return isIE() ? document.documentElement.clientWidth-33 : window.innerWidth;
}

/* Get the inner height of the window */
function getInnerHeight() {
	return isIE() ? document.documentElement.clientHeight-92 : window.innerHeight;
}

/* Resize the size of the flash object */
function onFlashResize(width,height) {
	getFlashMovie().width = width;
	getFlashMovie().height = height;
}

/* Get the size of the page */
function getPageSize(size) {
	size.width = getInnerWidth();
	size.height = getInnerHeight();
}

/* Show/hide scrolbars */
function showScrollbars(vis) {
	if (vis)
		document.body.style.overflow='visible';
	else
		document.body.style.overflow='hidden';
}

/* Format and return the content of the player object */
function buildPlayerObject(base, puzzleFile, bgColor) {
	var movie = base + '/core/genloader.swf'
	return (
		'<object id="loader" type="application/x-shockwave-flash" data="' + movie + '" width="200" 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" />' +
		'</object>');
}
