var gameId = 0;
var SWFObjHTML = null;

function SWFConstructedObject(id,b64Code,width,height)
{
	SWFObjHTML = decode64(b64Code);
	var gameFrameLoc = SWFGetFrameLoc();
	document.write("<iframe src=\"" + gameFrameLoc + "/gameFrame.php?id="+id+"\" frameborder=\"0\" scrolling=\"no\" style=\"border-width: 0px; width: " + width + "px; height: " + height +"px;\"><"+"/iframe>");
}

function SWFGetFrameLoc()
{
	var winLoc = window.location.toString();
	if( winLoc.indexOf("/game/") > -1 )
	{
		return winLoc.substring(0,winLoc.indexOf("/game/"));
	}
	else
	{
		return winLoc.substring(0,winLoc.lastIndexOf("/"));		
	}	
}

function SWFObject(url,id,width,height,objectVersion,xParam,yParam)
{	
	this.id = id;
	this.url = url;
	this.width = width;
	this.height = height; 
	this.objectVersion = objectVersion;
	this.xParam = xParam;
	this.yParam = yParam;
	this.swfFile = ( url.indexOf(".swf") > -1 );
	gameId = id;
	var xMargin = 0, yMargin = 0;
	if( GetQueryStringValue("fullscreen") == 1 )
	{
			var winSize = GetWinSize();	
			if( url.indexOf(".dcr") > -1 || url.indexOf(".dir") > -1 )
			{
				width = Math.floor((width/height)*winSize[1]);
				xMargin = Math.floor((winSize[0]-width));
			}
			else
			{
				width = winSize[0];
			}
			height = winSize[1]-3;		
			document.body.style.background = "";
	}
	var objectParams = "";
	var embedParams = "";
	if( xParam != null && xParam.length > 0 )
	{
		 var xParamArr = xParam.split("&");
		 for( var i=0; i<xParamArr.length; i++ )
		 {
		 	  var paramName = xParamArr[i].substring(0,xParamArr[i].indexOf("=")); 
		 	  var paramValue = xParamArr[i].substring(xParamArr[i].indexOf("=")+1); 
		 		objectParams += '\n<param name="' + paramName + '" value="' + paramValue + '">';		 
		 		embedParams += ' ' + paramName + '="' + paramValue + '"';
		 }
	}	

	if( !this.swfFile )
	{
		if( this.objectVersion == "11,5,7,609" )
		{
			SWFObjHTML = '<div style="float: left; margin-left: '+xMargin+'px; margin-top: '+yMargin+'px;"><object classid="clsid:233C1507-6A77-46A4-9443-F871F945D258" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,5,7,609" width="'+width+'" height="'+height+'">'
		    +'<param name="src" value="'+url+'">'
		    +'<param name="quality" value="high">'
		    +'<param name="swStretchStyle" value="meet">'
		    +'<param name="wmode" value="window">'
		    +'<param name="bgColor" value="#000000">'
		    +'<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">'
		    + objectParams
		    +'<embed src="'+url+'" playerversion="11" quality="high" wmode="window" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" '+embedParams+' pluginspage="http://www.macromedia.com/shockwave/download/" type="application/x-director" width="'+width+'" height="'+height+'"><'+'/embed>'
				+'<'+'/object><'+'/div>';				
		}
		else
		{
			SWFObjHTML = '<div style="float: left; margin-left: '+xMargin+'px; margin-top: '+yMargin+'px;"><object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,0" width="'+width+'" height="'+height+'">'
		    +'<param name="src" value="'+url+'">'
		    +'<param name="quality" value="high">'
		    +'<param name="wmode" value="window">'
		    +'<param name="swStretchStyle" value="meet">'
		    +'<param name="bgColor" value="#000000">'
		    +'<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">'
		    + objectParams
		    +'<embed src="'+url+'" playerversion="11" quality="high" wmode="window" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" '+embedParams+' pluginspage="http://www.macromedia.com/shockwave/download/" type="application/x-director" width="'+width+'" height="'+height+'"><'+'/embed>'
				+'<'+'/object><'+'/div>';	
		}	
	}
	else if( typeof(loadTimeout) != "undefined" && loadTimeout > 0 )
	{
		SWFObjHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+width+'" height="'+height+'">'
	    +'<param name="movie" value="'+url+'">'
	    +'<param name="quality" value="high">'
	    +'<param name="wmode" value="window">'
	    + objectParams
	    +'<embed src="'+url+'" wmode="window" quality="high" '+embedParams+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"><'+'/embed>'
			+'<'+'/object>';
	}	
	else
	{
		SWFObjHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+width+'" height="'+height+'">'
	    +'<param name="movie" value="'+url+'">'
	    +'<param name="quality" value="high">'
	    + objectParams
	    +'<embed src="'+url+'" quality="high" '+embedParams+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"><'+'/embed>'
			+'<'+'/object>';
	}

	var gameFrameLoc = SWFGetFrameLoc();
	document.write("<iframe id=\"gameFrame\" name=\"gameFrame\" src=\"" + gameFrameLoc + "/gameFrame.php?id="+id+"\" frameborder=\"0\" scrolling=\"no\" style=\"border-width: 0px; width: " + width + "px; height: " + height +"px;\"><"+"/iframe>");
}
