var	TMR_PROJ            = 0; 

var	TMR_SCENE			= 1; 

var	PS_UNINITIALIZED	= 0;
var PS_INITIALIZED		= 1;
var	PS_RUNNING			= 2;
var PS_COMPLETE			= 3;
var	k_iDefaultTickRate = 100; 

var g_fOSNT = navigator.appVersion.indexOf("NT") >= 0 ? true : false;	

var g_strPlatform = new String (navigator.platform);
g_strPlatform = g_strPlatform.toLowerCase ();
var g_fMac        = ("mac" == g_strPlatform.substring (0,3) ? true : false);
var g_Timer       = new Timer ();
var g_ProjState   = PS_UNINITIALIZED;
var g_nScenes     = -1;
var g_FrameBtns   = null;
var g_FramePage   = null;
var g_FrameDocMain = null;
var g_FrameSounds = null;
var g_fNavigator  = ("Netscape" == navigator.appName ? true : false);
var g_iIEVersion  = -1;
var g_MainPageLoaded = false;
var g_Initialized = false;
if (!g_fNavigator)
{
var iStart = navigator.appVersion.indexOf("MSIE");
var iEnd   = navigator.appVersion.indexOf(";", iStart+4);
if (iStart >= 0 && iEnd >= 0)
{
var strNumber = new String (navigator.appVersion.substring (iStart+4, iEnd));
g_iIEVersion = parseInt (strNumber, 10);
}
}
window.onload  = OnLoad;
window.onerror = OnError;
function Project (tickRate, startScene, stopScene, autoStart, delay, webpage)
{
this.tickRate     = tickRate;
this.startScene   = startScene;
this.stopScene    = stopScene;
this.autoStart    = autoStart;
this.delay        = delay;
this.webpage      = webpage;
this.currentScene = -1;
}
function Page (strIEPage, strNavPage)
{
this.strIEPage  = strIEPage;
this.strNavPage = strNavPage;
}
function GetPage (iIndex)
{
if (null == Pages[iIndex])
return null;
if (g_fNavigator)
return Pages[iIndex].strNavPage;
return Pages[iIndex].strIEPage;
}
function OnError ()
{
alert("There has been an unidentified error in this file's script. You may be able to fix this problem by refreshing your browser.");
return true;
}
function ExtractFrames()
{
if (!g_fNavigator)
return;
document.frames = new Array;
for (var intFrameIndx = 0; intFrameIndx < window.frames.length; intFrameIndx++)
{
var frame = window.frames[intFrameIndx];
document.frames[frame.name] = frame;
}
}
function GetFrameObj(strFrameName)
{
if (g_fNavigator)
return top.frames[strFrameName];
return document.frames[strFrameName];
}
function OnLoad ()
{
if (g_Initialized)
return;
g_Initialized = true;
ExtractFrames();
if ((Project.delay != null) && (Project.delay != 0))
{
setTimeout ("ProjectInit();", Project.delay * 1000); 
}
else
{
ProjectInit ();
}
}
function ProjectInit ()
{
g_FrameBtns   = GetFrameObj("TrafficCopButtonFrame");
g_FrameSounds = GetFrameObj("TrafficCopProjectDataFrame");
g_FramePage = GetFrameObj("TrafficCopPageFrame");
StatusChange ();
while (null != Pages[++g_nScenes]);
if (null == Project.startScene)	

Project.startScene = 0;		

if (g_fNavigator)
g_FramePage.location.href = MainPage.strNavPage;
else
document.all["TrafficCopPageFrame"].src = MainPage.strIEPage;
setTimeout ("Setup();", 1); 
}
function Setup () 
{  
if (!g_MainPageLoaded)
{
setTimeout ("Setup();", 100); 
return;
}
else
{
if (g_fNavigator)
g_FrameDocMain = g_FramePage.kDocMain;
else
g_FrameDocMain = document.frames["TrafficCopPageFrame"].document.frames["kDocMain"];
}
g_Timer.StartTicking ();								
StatusChange (PS_INITIALIZED);
ProjectStart ( );
}
function ProjectStart (startScene)
{
if (null != startScene)
ChangeScene (startScene);
else
ChangeScene (Project.startScene);
StatusChange (PS_RUNNING);
}
function ProjectComplete ()
{
StopProjectBehaviors ();
StatusChange (PS_COMPLETE);
}
function ChangeScene (nextSceneNumber)
{
if (null == Pages[nextSceneNumber])
return; 

Project.currentScene = nextSceneNumber;
StopSceneTimers ();
if (g_fNavigator)
{
g_FrameDocMain.location.href = GetPage (nextSceneNumber);
}
else
g_FramePage.document.all["kDocMain"].src = GetPage (nextSceneNumber);
StatusChange ();
UpdateNavBars(nextSceneNumber);
}
function UpdateNavBars(nextSceneNumber)
{
if (g_fNavigator)
return;
var objFrames = g_FramePage.document.frames;
var iCount = objFrames.length
for (var iIndx = 0; iIndx < iCount; iIndx++)
{
if (objFrames[iIndx].UpdateTables != null)
{
objFrames[iIndx].UpdateTables(nextSceneNumber);
}
}
}
function DocSceneExit (iNextSceneNumber)
{
var iNextScene = (null == iNextSceneNumber ? Project.currentScene + 1 : iNextSceneNumber);
g_FrameDocMain.StopEverythingOnScene ();
StopAllTimers();
if (iNextScene >= Project.startScene &&
iNextScene <= Project.stopScene &&
null != Pages[iNextScene])
{
ChangeScene (iNextScene);
return;
}
else
{
ProjectComplete ();
}
}
function Start ()
{
ProjectStart (Project.startScene);
}
function Stop ()
{
location.reload();
}
function Forward ()
{
if (null != Pages[Project.currentScene+1])
ChangeScene (Project.currentScene+1);
}
function Backward()
{
var PreviousScene = Project.currentScene;
if (null != Pages[Project.currentScene-1])
PreviousScene--;
ProjectStart (PreviousScene);
}
function Webpage()
{
window.open (Project.webpage);
}
function SceneStatus ()
{
StatusChange ();
}
function StatusChange (NewStatus)
{
var Spaces = "         ";
if (null != NewStatus)
g_ProjState = NewStatus;
var	stsPage  = null;	

if (PS_UNINITIALIZED == g_ProjState)
{
stsPage  = Spaces;
}
else if (PS_INITIALIZED == g_ProjState)
{
stsPage  = Spaces;
}
else if	(PS_RUNNING == g_ProjState)
{
stsPage  = (Project.currentScene + 1) + " / " + g_nScenes + "  ";
}
else if	(PS_COMPLETE == g_ProjState)
{
stsPage  = (Project.currentScene + 1) + " / " + g_nScenes + "  ";
}
if (null != g_FrameBtns &&
null != g_FrameBtns.document.all["SceneStatus"] &&
null != stsPage)
{
g_FrameBtns.document.all["SceneStatus"].value = stsPage;
}
}
function Timer ()
{
if (null == Project.tickRate)
this.tickRate = k_iDefaultTickRate;
else
this.tickRate = Project.tickRate;
this.oneShots       = new Array ();
this.animations     = new Array ();
this.tickCounter    = 0;						

this.ticksPerSecond = 1000 / (this.tickRate);	

this.timerID        = null;
this.StartTicking   = StartTicking;
this.StopTicking    = StopTicking;
}
function StartTicking ()
{
if (null == this.timerID)
this.timerID = setInterval ("TimerTick()", this.tickRate);
}
function StopTicking ()
{
if (null != this.timerID)
clearInterval (this.timerID);
this.timerID = null;
}
function TimerTick ()
{
var timerEvent;
for (var ii=0; ii < g_Timer.animations.length; ii++)		

{
if ((timerEvent = g_Timer.animations[ii]) == null)		

continue;											

if (timerEvent.callback (timerEvent.callbackObj) == true)	

g_Timer.animations[ii] = null;							

}
++g_Timer.tickCounter;
var length = g_Timer.oneShots.length;
for (var ii=0; ii < length && (g_Timer !=null ); ii++ )	
{
if ((timerEvent = g_Timer.oneShots[ii]) == null)	

continue;										

if (timerEvent.time <= g_Timer.tickCounter)		

{
g_Timer.oneShots[ii] = null;					

timerEvent.callback (timerEvent.callbackObj);	

}
}
}
function StartOneShotTimer (obj, time, callback, type)
{
var	timerIndex;									

var timerEvent = new Object();					

timerEvent.callbackObj = obj;					

timerEvent.callback = callback;					

timerEvent.type = type;							

timerEvent.time = g_Timer.tickCounter + (time * g_Timer.ticksPerSecond);
for (timerIndex = 0; g_Timer.oneShots[timerIndex] != null; timerIndex++);
g_Timer.oneShots[timerIndex] = timerEvent;	

}
function StartAnimationTimer (obj, callback)
{
var timerIndex; 
timerEvent = new Object();
timerEvent.callbackObj = obj;					

timerEvent.callback = callback;					

for (timerIndex = 0; g_Timer.animations[timerIndex] != null; timerIndex++);
g_Timer.animations[timerIndex] = timerEvent;
}
function StopSceneTimers()
{
for (var ii = 0; ii < g_Timer.oneShots.length; ii++)	

{
if (g_Timer.oneShots[ii] == null)					

continue;
if (g_Timer.oneShots[ii].type == TMR_SCENE)
g_Timer.oneShots[ii] = null;					

}
for (var ii = 0; ii < g_Timer.animations.length; ii++)	

g_Timer.animations[ii] = null;
}
function StopAllTimers()
{
for (var ii = 0; ii < g_Timer.oneShots.length; ii++)	

{
if (g_Timer.oneShots[ii] != null)					

g_Timer.oneShots[ii] = null;					

}
for (var ii = 0; ii < g_Timer.animations.length; ii++)	

g_Timer.animations[ii] = null;
}
function KillTimer ()
{
if (null != g_Timer)
{
window.clearTimeout (g_Timer.timerID);	

g_Timer = null;							

}
}
function StopProjectBehaviors ()
{
if (ProjectBhv != null)
{
var bhvIdx = 0;
while (ProjectBhv[bhvIdx])
{
ProjectBhv[bhvIdx].StopEverything (ProjectBhv[bhvIdx]);
bhvIdx++;
}
}
}
var ST_WAV					= 1;	

var	ST_MID					= 2;	

function GetProjectSoundHtml(fileName, soundType, fCreate)
{
var id;
if (null == g_FrameSounds)
return null;
var i = fileName.lastIndexOf(".");
id = fileName.substring(0,i);
if (g_fNavigator)
{
objBGSound = g_FrameSounds.document.embeds[id];
}
else
{
var iLength = g_FrameSounds.document.all.length;
var iIndx;
for (iIndx = 0; iIndx < iLength; iIndx++)
{
var hpsound = g_FrameSounds.document.all[iIndx].hpsound;
var hpsoundFileName;
if (null != hpsound)
{
var i = hpsound.lastIndexOf("\\");
if (i == -1)
hpsoundFileName = hpsound;
else
hpsoundFileName = hpsound.substr(i + 1);
}
if (hpsoundFileName == fileName)
{
objBGSound = g_FrameSounds.document.all[iIndx];
break;
}
}
}
var bhvIdx = 0;
while (ProjectBhv[bhvIdx] && ProjectBhv[bhvIdx].fileName != fileName) {bhvIdx++}
if (null == ProjectBhv[bhvIdx])
ProjectBhv[bhvIdx] = new ProjectSound(soundType, fileName); 
return objBGSound;
}
function ProjectSound(soundType, fileName)
{
this.Stop = StopProjectSound;
this.StopEverything = StopEverythingOnProjectSounds;
this.soundType = soundType;
this.fileName = fileName;
}
function StopProjectSound(objSound)
{
objSound.html.loop = 0;
objSound.html.src = "";             

if ( objSound.soundType == ST_WAV )
objSound.html.volume = -10000;
}
function StopEverythingOnProjectSounds(objSound)
{
objSound.html = GetProjectSoundHtml(objSound.fileName, objSound.soundType, false);
if (objSound.html != null)
{
if (g_fNavigator)
{
objSound.html.stop();
}
else
{
StopProjectSound (objSound);
if (g_fOSNT)						

objSound.html.volume = -500;	

}
}
}

