// AtmosphereInterfaceAddon v.1.3
// 
// Rolu, www.roce.org, CR 2003-jan-16, LU 2003-june-14
//
// Additional code by M.Judd
//
// Easy access to the MTS plugin object from within Atmo.
//
MTSPlugin.prototype.pluginObjects=new Array();
MTSPlugin2=MTSPlugin;
MTSPlugin=function(file,width,height,bkey,alt,parmsc)
{
    this.realMTSPlugin=new MTSPlugin2(file,width,height,bkey,alt,parmsc);
    this.pluginObjects.push(this.realMTSPlugin);
    this.name=this.realMTSPlugin.name;
    this.LN=this.realMTSPlugin.LN;
    this.ImageLink=this.realMTSPlugin.ImageLink;
}
MTSPlugin.prototype=MTSPlugin2.prototype;

function injectPluginIndices()
{
    var i;
    
    for(i=0;i<MTSPlugin.prototype.pluginObjects.length;i++)
    {
        MTSPlugin.prototype.pluginObjects[i].sendJS("pluginIndex="+i);
    }  
}

function getMTSPluginObject(index)
{
    return MTSPlugin.prototype.pluginObjects[index];
}

MTSPlugin.prototype.getPluginObject=function()
{
    var pn=this._mtsPID(), pobj;

    if(VET_Mac&&VET_IE)
    {
        // Sorry, doesn't work here.
    }
    else
    {
        if(VET_Win&&VET_IE)
            pobj=eval('document.all.'+pn);
        else
        {
            if(this.LN==VET_Ln)
                pobj=eval('document.embeds.'+pn)
            else
            {
                if(VET_Gecko)
                    pobj=eval('document.embeds.'+pn)
                else
                    pobj=eval('document.'+this.LN+'.document.embeds.'+pn)
            }
        }
    }
    
    return pobj;
}

//
// Javascript injector.
//
MTSPlugin.prototype.sendJS=function(ajs)
{
    var vpc=this.getPluginObject(),
        eajs=ajs;

    // Prepare string.
    eajs="eval(\"" + eajs.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "\\\'").replace(/\r\n/g, "\\n").replace(/\n/g, "\\n").replace(/\r/g, "\\n") + "\");";

    if(VET_Mac&&VET_IE)
    {
        // Sorry, doesn't work here.
    }
    else
    {
        if(VET_Win&&VET_IE)
            vpc.PluginCommand(eajs, 0, 0);
        else
            vpc.DoCommand(eajs);
    }
}
// ======================================================================================
var gTimer = null;
var TimerCount = 0;
var ScreenCount = 1;
var vpc
var AtmoLoadDone = false;
var openscreen = false;
var firstscreen = false;
var not_done = true;
var pics_set = false;
var active_page = "";
var flash_control = false;

function Do_Shift(picnum) 
{
if (!pics_set) 
	{
	pics_set = true;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="map" width="100% " height="100%" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="map.swf" /><param name="loop" value="false" /><param name="play" value="false" /><param name="scale" value="exactfit" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="map.swf" loop="false" play="false" quality="high" bgcolor="#000000" width="100%" height="100%" swLiveConnect=true id="map" name="map" align="middle" scale="exactfit" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>	');
	myflash = eval("document.map");
	vpc = vmp.getPluginObject();
	active_page = vpc;
	}
if (picnum == 0) // Shift to title pic
	{
	if (!not_done) 
		{
		parent.Left.left.GotoFrame(picnum);
		parent.Top.tvtop.GotoFrame(picnum);
		parent.Bottom.tvbottom.GotoFrame(picnum);
		parent.Right.right.GotoFrame(picnum);
		}
    active_page.style.position="absolute";
    active_page.style.left="-500%";
	myflash.style.position="static";
	myflash.style.left="0%";
	active_page = myflash;
	}
if (picnum == 1 && not_done) // Shift to Opening pic
	{
	parent.World.map.GotoFrame(picnum);
	parent.Left.left.GotoFrame(picnum);
	parent.Top.tvtop.GotoFrame(picnum);
	parent.Bottom.tvbottom.GotoFrame(picnum);
		if (!flash_control)
		{
		parent.Right.right.GotoFrame(picnum);
		}
	active_page = myflash;
	}
if (picnum == 2 && not_done) // Shift to Car.jpg
	{
	parent.World.map.GotoFrame(picnum);
	parent.Left.left.GotoFrame(picnum);
	parent.Top.tvtop.GotoFrame(picnum);
	parent.Bottom.tvbottom.GotoFrame(picnum);
	if (!flash_control)
		{
		parent.Right.right.GotoFrame(picnum);
		}
	active_page = myflash;
	}
if (picnum == 3 && not_done) // Shift to Plugin
	{
	not_done = false;
	parent.Left.left.GotoFrame(9);
	parent.Top.tvtop.GotoFrame(9);
	parent.Bottom.tvbottom.GotoFrame(9);
	if (!flash_control)
		{
		parent.Right.right.GotoFrame(8);
		}
	if (flash_control)
		{
		parent.Right.right.GotoFrame(9);
		}
	active_page.style.position="absolute";
	active_page.style.left="-500%";
	vpc.style.position="static";
	vpc.style.left="0%";
	active_page = vpc;
	flash_control = true;
	}
if (picnum == 4 && not_done) // Shift to Flash Map
	{
	parent.World.map.GotoFrame(8);
	parent.World.map.play();
	parent.Left.left.GotoFrame(12);
	parent.Top.tvtop.GotoFrame(12);
	parent.Bottom.tvbottom.GotoFrame(12);
	if (!flash_control)
		{
		parent.Right.right.GotoFrame(12);
		}
	active_page.style.position="absolute";
	active_page.style.left="-500%";
	myflash.style.position="relative";
	myflash.style.left="0%";
	active_page = myflash;
	}
}

function Timer()
{
if(!vmp)
   return;
if (!openscreen) 
	{
	Do_Shift(0);
	openscreen = true;
	vmp.sendJS("if(stageModel.bounds!=undefined) sendJS('AtmoLoadDone=true');");
	}

if(AtmoLoadDone)
  {	
  if(!firstscreen)
  	{
  	firstscreen = true;
	Do_Shift(ScreenCount);
	}
  TimerCount++;
  if(TimerCount >= 20)
  	{	
  	ScreenCount++;
	Do_Shift(ScreenCount);
	TimerCount = 0;
	}
	if (ScreenCount == 2)
	   {
		return;
		}
	  gTimer = window.setTimeout("Timer()",1000);
	}
	else
	  {
	  gTimer = window.setTimeout("Timer()",1000);
	  vmp.sendJS("if(stageModel.bounds!=undefined) sendJS('AtmoLoadDone=true');");
	  }
}

function Restore()
{
	if(document.cookie == '')
		{
		return;
		}
	else
		{
		restoregame = document.cookie;
		restoregame = restoregame.substring(0,37);
		vmp.sendJS("Get_Restore_Data('" + restoregame + "')");
		}
}