//------------------------------------------------------------------
//MoveLib: DHTML Extension library to CBDHTML.JS
//(C) 1998 Joe Cincotta Euro RSCG Partnership
//	Version 0.41 [28.12.1998]
//------------------------------------------------------------------

var ml_debug=false;
var ml_degrade=false;
//Detect older generation systems and don't allow animation
if ((navigator.platform == 'Win16')||(navigator.platform == 'Mac68k'))
	ml_degrade=true;

//------------------------------------------------------------------
//Object prototypes
//------------------------------------------------------------------
function ml_pathObject(cbLayer,mlLabel,arrayX,arrayY)
{
	this.cbLayer=cbLayer;
	this.mlLabel=mlLabel;
	this.arrayX=arrayX;
	this.arrayY=arrayY;
	this.activeFlag=false;
	this.deltaSpeed=30;
	this.loopFlag=false;
	this.offsetPointer=0;
	this.stopOffset=0;
	this.xOffset=0;
	this.yOffset=0;
	this.setXoffset=ml_setXoffset;
	this.setYoffset=ml_setYoffset;
	this.getXoffset=ml_getXoffset;
	this.getYoffset=ml_getYoffset;
	this.startPath=ml_startPath;
	this.resumePath=ml_resumePath;
	this.pausePath=ml_pausePath;
	this.stopPath=ml_stopPath;
	this.movePath=ml_movePath;
	this.isActive=ml_isActive;
}

function ml_animObject(mlLabel,targetObject,objectSourcebase,frames)
{
	this.mlLabel=mlLabel;
	this.targetObject=targetObject;
	this.objectSourcebase=objectSourcebase;
	this.frames=frames;
	this.codeSpawn=null;
	this.semaphore=null;
	this.offset=1;
	this.stepFlag=true;
	this.delay=30;
	this.startAnimate=ml_startSequence;
	this.stopAnimate=ml_killSequence;
	this.stepAnimate=ml_stepSequence;
	this.setCode=ml_setCode;
	this.setFrame=ml_setFrame;
}	
//------------------------------------------------------------------
//Lib initialisation for capturing keyboard events
//------------------------------------------------------------------
function ml_init() {
        document.onkeydown = keyDown
        document.onkeyup = keyUp
        if (ns4) document.captureEvents(Event.KEYDOWN | Event.KEYUP)
}
//------------------------------------------------------------------
//Lib initialisation for anim frames
//------------------------------------------------------------------
function ml_batchPreload(objectBase,nameBase,xSize,ySize,frames)
{
	var i=1;
	if(ml_degrade)
	{
		eval("window."+objectBase+i+"=new Image("+xSize+","+ySize+");");
		eval("window."+objectBase+i+".src='"+nameBase+i+".gif';");
		eval("window."+objectBase+frames+"=new Image("+xSize+","+ySize+");");
		eval("window."+objectBase+frames+".src='"+nameBase+frames+".gif';");
	}else{
		for (i=1;i<frames+1;i++)
		{
			eval("window."+objectBase+i+"=new Image("+xSize+","+ySize+");");
			eval("window."+objectBase+i+".src='"+nameBase+i+".gif';");
		}
	}
}
//------------------------------------------------------------------
//Animation functions
//------------------------------------------------------------------

function ml_setCode(codeString)
{
	this.codeSpawn=codeString;
}

function ml_setFrame(frameNumber)
{
	this.offset=frameNumber;
}

function ml_killSequence()
{
	window.clearTimeout(this.semaphore);
	this.semaphore=null;
}

function ml_startSequence(stepFlag,delay)
{
		window.clearTimeout(this.semaphore);
		this.semaphore=null;
		this.stepFlag=stepFlag;
		this.delay=delay;
		this.stepAnimate();
}

function ml_stepSequence()
{
	var tmpMax=this.frames;
	tmpMax++;
	if((this.offset<tmpMax)&&(this.offset>0))
	{
		eval("setImgSrc('"+this.targetObject+"',"+this.objectSourcebase+this.offset+".src);");
		if(this.stepFlag)
		{
			this.offset++;
			if((ml_degrade)&&(this.offset<this.frames))
				this.offset=this.frames;
		}
		else
		{
			this.offset--;
			if((ml_degrade)&&(this.offset>1))
				this.offset=1;
		}
		this.semaphore=window.setTimeout("ml_irqlatchAnimate('"+this.mlLabel+"');",this.delay);
	}
	else
	{
		if(this.offset>this.frames)
			this.offset=this.frames;
		if(this.offset<1)
			this.offset=1;
		window.clearTimeout(this.semaphore);
		this.semaphore=null;
		if(this.codeSpawn!=null)
			eval(this.codeSpawn);
	}
}

function ml_irqlatchAnimate(objectName)
{
	eval("var tmpObject="+objectName+";");
	tmpObject.stepAnimate();
}

//------------------------------------------------------------------
//Path functions
//------------------------------------------------------------------
function ml_isActive()
{
	return this.activeFlag;
}

function ml_setXoffset(val)
{
	this.xOffset=val;
}

function ml_setYoffset(val)
{
	this.yOffset=val;
}

function ml_getXoffset()
{
	return this.xOffset;
}

function ml_getYoffset()
{
	return this.yOffset;
}

function ml_startPath(offset,endOffset,deltaSpeed,loop)
{
	if(!this.activeFlag)
	{
//error checking
		this.offsetPointer=offset;
		if((this.arrayX.length-1)<this.offsetPointer)
			this.offsetPointer=0;
		if(endOffset!=null)
			this.stopOffset=endOffset;
		else
			this.stopOffset=this.arrayX.length-1;
		if((this.stopOffset<this.offsetPointer)||((this.arrayX.length-1)<this.stopOffset))
			this.stopOffset=this.arrayX.length-1;
		moveLayer(this.cbLayer,(this.arrayX[this.offsetPointer]+this.xOffset),(this.arrayY[this.offsetPointer]+this.yOffset));
		this.deltaSpeed=deltaSpeed;
		this.loopFlag=loop;
		this.activeFlag=true;
		this.movePath();
	}
}

function ml_resumePath(offset,deltaSpeed,loop,method)
{
	if(!this.activeFlag)
	{
		this.deltaSpeed=deltaSpeed;
		this.loopFlag=loop;
		this.activeFlag=true;
		if(method=='slide')
			this.slidePath();
		if(method=='move')
			this.movePath();
	}
}

function ml_stopPath()
{
	this.activeFlag=false;
	this.offsetPointer=0;
}

function ml_pausePath()
{
	this.activeFlag=false;
}

function ml_movePath()
{
	if(this.stopOffset==this.offsetPointer)
	{
		this.offsetPointer=0;
		if(this.loopFlag)
			this.activeFlag=true;
		else
			this.activeFlag=false;	
	}
		
	if(this.activeFlag)
	{
		this.offsetPointer++;
		moveLayer(this.cbLayer,(this.arrayX[this.offsetPointer]+this.xOffset),(this.arrayY[this.offsetPointer]+this.yOffset));
		window.setTimeout("ml_irqlatchPathmove('"+this.mlLabel+"');",this.deltaSpeed);
	}
}

function ml_irqlatchPathmove(objectName)
{
	eval("var tmpObject="+objectName+";");
	tmpObject.movePath();
}

//------------------------------------unfinished

/*

//------------------------------------------------------------------
//Keyhandler stubs
//------------------------------------------------------------------
function ml_keyDown(e) {
        if (ns4) {var nKey=e.which; var ieKey=0}
        if (ie4) {var ieKey=event.keyCode; var nKey=0}
        if ((nKey==97 || ieKey==65) && !block.active) {   // if "A" key is pressed
                block.active = true
                slide()
        }
}

function ml_keyUp(e) {
        if (ns4) {var nKey=e.which; var ieKey=0}
        if (ie4) {var ieKey=event.keyCode; var nKey=0}
        if (nKey==97 || ieKey==65) {
                block.active = false   // if "A" key is released
        }
}

*/
