//Support functions for Web Hotspots media maps
//Copyright (c) 1997-1998 1Automata  www.1automata.com
//
//License is granted to publish this code on a Web site
//under conditions specified with the Web Hotspots
//software program.


//class hsAction
//{
//      int      nDelay;
//      int      nType;
//}
//
//class hsActionFrame : hsAction
//{
//      Image    Frame;
//}
//
//class hsActionLink : hsAction
//{
//      string   sURL;
//}
//
//class hsActionRun : hsAction
//{
//      string   sCode;
//}
//
//class hsActionAudio : hsAction
//{
//      string   sAudioClip;
//}
//
//class hsActionMsg : hsAction
//{
//      string   sMsg;
//}
//
//class hsActionPlay : hsAction
//{
//      string   sPlayName;
//}
//
//class hsPlay
//{
//      string   sPlayName;
//      hsAction Actions[];
//      int      nActionCount;
//      string   sParentPlayName;
//}
//
//class hsMap
//{
//      hsPlay   Play;
//      int      nCurArea;
//      int      nCurEvent;
//}
		

// ------------------
//  hsAction classes
// ------------------

function hsactDoNothing( Img )
{
}

function hsAction( nDelay, nType )
{
	this.nDelay = nDelay;
	this.nType = nType;
	this.Do = hsactDoNothing;
}

function hsactframeDo( Img )
{
	Img.src = this.Frame.src;
}

function hsActionFrame( nDelay, sBase, sExt )
{
	this.Action = new hsAction( nDelay, 0 );
	this.Frame = new Image();
	this.Frame.src = sBase + sExt;
	this.Do = hsactframeDo;
}

function hsActionImg( nDelay, sImg )
{
	this.Action = new hsAction( nDelay, 0 );
	this.Frame = new Image();
	this.Frame.src = sImg;
	this.Do = hsactframeDo;
}

function hsactlinkDo( Img )
{
	window.location = this.sURL;
}

function hsActionLink( nDelay, sURL )
{
	this.Action = new hsAction( nDelay, 1 );
	this.sURL = sURL;
	this.Do = hsactlinkDo;
}

function hsactrunDo( Img )
{
	Exec( this.sCode );
}

function hsActionRun( nDelay, sCode )
{
	this.Action = new hsAction( nDelay, 2 );
	this.sCode = sCode;
	this.Do = hsactrunDo;
}

function hsactaudioDo( Img )
{
	if ( (navigator.javaEnabled != null) && 
	     (navigator.javaEnabled()) )
		document.hsAudio.playSoundtrack( this.sAudioURL );
}

function hsActionAudio( nDelay, sURL )
{
	this.Action = new hsAction( nDelay, 3 );
	this.sAudioURL = sURL;
	this.Do = hsactaudioDo;
}

function hsactmsgDo( Img )
{
	window.status = this.sMsg; 
}

function hsActionMsg( nDelay, sMsg )
{
	this.Action = new hsAction( nDelay, 4 );
	this.sMsg = sMsg;
	this.Do = hsactmsgDo;
}

function hsactplayDo( Img )
{
	Exec( this.sCode );
}

function hsActionPlay( nDelay, sCode )
{
	this.Action = new hsAction( nDelay, 5 );
	this.sCode = sCode;
	this.Do = hsactplayDo;
}


// --------------
//  hsPlay class
// --------------

function hsplayNext( Img, sCode )
{
	if (this.nCurAction >= this.nActionCount)
		return;
	nAct = this.nCurAction;        
	this.Actions[nAct].Do( Img );
	this.nCurAction++;
	if (this.nCurAction >= this.nActionCount)
		if (this.fLoop)
			this.nCurAction = 0;
		//else
		//        if (this.ParentPlay != null)
		//        {
		//                this.ParentPlay.nCurAction =
		//                                  this.nParentAction;
		//                this.ParentPlay.Next( Img, this.sCode );
		//        }
	if (this.Actions[nAct].Action.nType != 0)
		setTimeout( sCode, this.GetDelay() );
}

function hsplayStart( Img, sCode )
{
	this.nCurAction = 0;
	this.Next( Img, sCode );
}

function hsplayGetDelay()
{
	if (this.nCurAction >= this.nActionCount)
		return 10;
	if (this.Actions[this.nCurAction].Action.nDelay < 10)
		return 10;
	return this.Actions[this.nCurAction].Action.nDelay;
}

//Constructor for hsPlay class
function hsPlay( ActionList, nActionCount, fLoop )
{
	this.Actions = ActionList;
	this.nActionCount = nActionCount;
	this.nCurAction = 0;
	this.fLoop = fLoop;
	//Setup member functions
	this.Start = hsplayStart;
	this.Next = hsplayNext;
	this.GetDelay = hsplayGetDelay;
}



// -------------
//  hsMap class
// -------------

function hsmapGetDelay()
{
	return this.Play.GetDelay();
}

function hsmapNext()
{
	if (this.Img == null)
		return;
	this.Play.Next( this.Img, this.sCode );
}

function hsmapStart( P, nArea, nEvent )
{
	if (this.Img == null)
		return true;
	//if ( (this.nCurArea == nArea) && (this.nCurEvent == nEvent) )
	//        return true;
	this.nCurArea = nArea;
	this.nCurEvent = nEvent;
	this.Play = P;
	P.Start( this.Img, this.sCode );
	return true;
}

//Constructor for hsMap class
function hsMap( LoadPlay, sCode )
{
	this.Play = LoadPlay;
	this.nCurArea = -1;
	this.nCurEvent = 0;
	this.sCode = sCode;
	this.Img = null;
	//Setup member functions
	this.Start = hsmapStart;
	this.Next = hsmapNext;
	this.GetDelay = hsmapGetDelay;
}
////////////////////
