
function stopErrors(emsg,eurl,eline)
{
	return true; // ignore all errors
}
window.onerror = stopErrors;
document.onerror = stopErrors;

// INTERNET REAL PLAY MODE
//var the_dcr_url =  "intro.dcr"; // VIDEO and streaming downloader for the game
//var downloadthis = "whisperide_ms2_final.dcr"; // if intro.dcr is used this is what gets run

// NO INTRO (WORKS LOCALLY - NO WEBSERVER REQUIRED)
var the_dcr_url =  "whisperide_ms2_final.dcr";
var downloadthis = "";
var thisuser = '';
var thisdebug = '';

// LOCALHOST DEBUG MODE
//var the_dcr_url =  "whisperide_ms2_final.dcr" + "?randy="+Math.random();  // WORKS
//var downloadthis = '';
//var thisuser = 'christer';
//var thisdebug = 'debugconsole';

if (thisdebug == 'debugconsole') document.write("<div id='debugconsole'>DEBUG MODE</div>");

var shockwave_background = "#000000"; //"#48562E";
var shock_w = '940'; // '100%'
var shock_h = '480'; // '100%'

try
{
	var shockedhtml = "<OBJECT id='shockobjectid' classid='clsid:233C1507-6A77-46A4-9443-F871F945D258' "+
	"codebase='http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,0' "+
	"ID='amagam' "+
	"WIDTH='"+shock_w+"' "+
	"HEIGHT='"+shock_h+"' "+
	"VIEWASTEXT>"+
	"<param name='src' value='"+the_dcr_url+"'>"+
	"<param name='sw1' value=\""+downloadthis+"\">"+ //value='amagam.dcr'>"+
	"<param name='sw2' value=\""+thisuser+"\">"+
	"<param name='sw3' value=\""+thisdebug+"\">"+
	//"<param name='sw4' value=\""+thisdata+"\">"+
	//"<param name='sw5' value=\"loadlevel('"+thislvl+"');\">"+
	//"<param name='sw5' value='"+thislvl+"'>"+
	//"<param name='swStretchStyle' value='fill'>"+
	"<param name='swStretchStyle' value='stage'>"+
	"<param name='swRemote' value=\"swSaveEnabled='true' swVolume='true' swRestart='false' swPausePlay='false' swFastForward='false' swContextMenu='true' \">"+
	"<param name='PlayerVersion' value='11'>"+
	"<PARAM NAME='bgColor' VALUE='"+shockwave_background+"'>"+
	//"<PARAM NAME='logo' VALUE='FALSE'>"+
	"<EMBED id='shockembedid' SRC='"+the_dcr_url+"' "+
	"sw1='"+downloadthis+"' "+ //"sw1='amagam.dcr' "+
	"sw2='"+thisuser+"' "+
	"sw3='"+thisdebug+"' "+
	//"sw4='"+thisdata+"' "+
	//"sw5=\"loadlevel('"+thislvl+"');\" "+
	//"sw5='"+thislvl+"' "+
	"bgColor='"+shockwave_background+"' "+
	//"logo='FALSE' "+
	"WIDTH='"+shock_w+"' "+
	"HEIGHT='"+shock_h+"' "+
	"swRemote=\"swSaveEnabled='true' swVolume='true' swRestart='false' swPausePlay='false' swFastForward='false' swContextMenu='true' \" "+
	//"swStretchStyle='fill' "+
	"swStretchStyle='stage' "+
	"TYPE='application/x-director' "+
	"PlayerVersion='11' "+
	"PLUGINSPAGE='http://www.macromedia.com/shockwave/download/'>"+
	"</EMBED></OBJECT>"+
	"<NOEMBED><div class='errormessage'><b>Whisperide 3d Game</b><br><br>This 3d game requires shockwave to be enabled in your browser.	Please change your internet options to allow scripting and plugins, and make sure to download the newest version on shockwave.  If you are using IE locally (from a CD-ROM), you will probably have to 'allow blocked content' by clicking a yellow bar at the top. This game has been tested to work on IE7, IE8, Chrome, Opera 9, Safari 3 and Firefox 3, on Windows XP, Vista and Mac OSX using the Adobe Shockwave version 11.5.<br><br>You can get the latest shockwave at <a href='http://get.adobe.com/shockwave/'>http://get.adobe.com/shockwave/</a>.</div></NOEMBED>";
	//if (ele) ele.innerHTML = ""; // hmm bugfix for some browsers nop

	document.write(shockedhtml);
}
catch(anerr)
{
	alert('ERROR trying to init shockwave.');
}


var debugmessage_ele = null;
var debugdata = [];
var debugdatacount = 0;
var debuglogmaxlines = 500; //256; // just to stop lag
var startstamp = 0;
function timestring(ms)
{
	try
	{
		secs = ''+parseInt(ms/1000);
		if (secs.length==2) secs = '0'+secs;
		else if (secs.length==1) secs = '00'+secs;
		mss = ''+parseInt(ms - (secs*1000));
		if (mss.length==2) mss = '0'+mss;
		else if (mss.length==1) mss = '00'+mss;
		return secs+':'+mss;
	}
	catch(anerr)
	{
		alert('ERROR in timestring');
	}
	return '';
}
function mytimestamp()
{
	try
	{
		if (!startstamp) startstamp = parseInt(new Date().getTime());
		return timestring(parseInt(new Date().getTime()) - startstamp);
	}
	catch(anerr)
	{
		alert('ERROR in mytimestamp');
	}
	return '';
}
function debugmessagecontains(haystack,needle) // CaSe ignored
{
	try
	{
	    if ((!haystack) || (!needle)) return false;
	    if ((!haystack.length) || (!needle.length)) return false;
	    haystack = haystack.toLowerCase();
	    needle = needle.toLowerCase();
	    return (haystack.indexOf(needle) > -1);
	}
	catch(anerr)
	{
		alert('ERROR in debugmessagecontains');
	}
	return false;
}
function debugmessage(astr)
{
	try
	{
		if (!debugmessage_ele) debugmessage_ele = document.getElementById('debugconsole');
		if (debugmessage_ele) 
		{
			var str=astr;
			if (debugmessagecontains(astr,'debug')) str = '<font color=white><b>' + str + '</b></font>';
			if (debugmessagecontains(astr,'error')) str = '<font color=red>' + str + '</font>';
			if (debugmessagecontains(astr,'GAME OVER')) str = '<font color=red>' + str + '</font>';
			if (debugmessagecontains(astr,'ajax')) str = '<font color=yellow>' + str + '</font>';
			if (debugmessagecontains(astr,'download')) str = '<font color=yellow>' + str + '</font>';
			if (debugmessagecontains(astr,'http')) str = '<font color=yellow>' + str + '</font>';
			str = '<font color=silver>'+mytimestamp() + ':</font>' + str;
			var pNode = document.createElement("p");
			pNode.innerHTML = str;
			var firstchild = debugmessage_ele.firstChild;
			if (firstchild)	debugmessage_ele.insertBefore(pNode,firstchild);
			else debugmessage_ele.appendChild(pNode);
			debugdatacount++;
			return;
		}
	}
	catch(anerr)
	{
		alert('ERROR in debugmessage');
	}
}

