
function InitGames()
{
	document.panel1.imulti1.value=GMS(m1, n1, 1, b1, 'multig1.htm');
	document.panel2.imulti2.value=GMS(m2, n2, 2, b2, 'multig2.htm');
	document.panel3.imulti3.value=GMS(m3, n3, 3, b3, 'multig3.htm');
	document.panel4.imulti4.value=GMS(m4, n4, 4, b4, 'multig4.htm');
}

function MoveForwardAnim()
{

	if ( nMoves[1] < m1.length / 2 )
		b1=MF(m1, n1, 1, b1, 'multig1.htm');
	else
		b1=GoStart(m1, n1, 1, b1, 'multig1.htm');
	document.panel1.imulti1.value=GMS(m1, n1, 1, b1, 'multig1.htm');
	if ( nMoves[2] < m2.length / 2 )
		b2=MF(m2, n2, 2, b2, 'multig2.htm');
	else
		b2=GoStart(m2, n2, 2, b2, 'multig2.htm');
	document.panel2.imulti2.value=GMS(m2, n2, 2, b2, 'multig2.htm');
	if ( nMoves[3] < m3.length / 2 )
		b3=MF(m3, n3, 3, b3, 'multig3.htm');
	else
		b3=GoStart(m3, n3, 3, b3, 'multig3.htm');
	document.panel3.imulti3.value=GMS(m3, n3, 3, b3, 'multig3.htm');
	if ( nMoves[4] < m4.length / 2 )
		b4=MF(m4, n4, 4, b4, 'multig4.htm');
	else
		b4=GoStart(m4, n4, 4, b4, 'multig4.htm');
	document.panel4.imulti4.value=GMS(m4, n4, 4, b4, 'multig4.htm');
	window.setTimeout( "MoveForwardAnim()", 1000 );
}
// Copyright 98,99 by ChessBase GmbH, Germany
function Init( path )
{ gifs = new Array(6);
	for ( var i=0; i< 26; i++)
		gifs[i]= new Image();
	gifs[0].src = path + "b.gif";
	gifs[1].src = path + "bbb.gif";
	gifs[2].src = path + "bbw.gif";
	gifs[3].src = path + "bkb.gif";
	gifs[4].src = path + "bkw.gif";
	gifs[5].src = path + "bqb.gif";
	gifs[6].src = path + "bqw.gif";
	gifs[7].src = path + "brb.gif";
	gifs[8].src = path + "brw.gif";
	gifs[9].src = path + "bnb.gif";
	gifs[10].src = path + "bnw.gif";
	gifs[11].src = path + "wbb.gif";
	gifs[12].src = path + "wbw.gif";
	gifs[13].src = path + "wrb.gif";
	gifs[14].src = path + "wrw.gif";
	gifs[15].src = path + "wqb.gif";
	gifs[16].src = path + "wqw.gif";
	gifs[17].src = path + "wkb.gif";
	gifs[18].src = path + "wkw.gif";
	gifs[19].src = path + "wnb.gif";
	gifs[20].src = path + "wnw.gif";
	gifs[21].src = path + "wpb.gif";
	gifs[22].src = path + "wpw.gif";
	gifs[23].src = path + "bpb.gif";
	gifs[24].src = path + "wpb.gif";
	gifs[25].src = path + "b.gif";
}
function SyncPicture( base, basename )
{	if ( base > -1 ) return base;
	for ( i=0; i < document.images.length; i++ )
	{	if ( document.images[i].name != "" )
			if ( document.images[i].name == basename )
				return i;
			else if ( document.images[i].name.substring(0,3) == basename.substring(0,3) )
				i+= 63;
	}
	return -1;
}
function MF5( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	for ( i=0; nMoves[nm] < moves.length / 2 && i < 10; i++ )
		MF( moves, names, nm, base );
	return base;
}
function MB5( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	for ( i=0; nMoves[nm] > 0 && i < 10; i++ )
		MB( moves, names, nm, base );
	return base;
}
function GoStart( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	while ( nMoves[nm] > 0 )
		MB( moves, names, nm, base );
	return base;
}
function GoEnd( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	while ( nMoves[nm] < moves.length / 2 )
		MF( moves, names, nm, base );
	return base;
}
function MF( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	if ( nMoves[nm] < moves.length / 2 )
	{	var n = nMoves[nm]*2;
		var from = moves[ n ] & 0x3f;
		var to = moves[ n+1 ] & 0x3f;
		names[ n   ] = document.images[ base + from ].src;
		names[ n+1 ] = document.images[ base + to ].src;
		var len = names[n].length;
		var nn = (Math.floor(( to / 8 )) + ( to % 8 ));
		var dest = ( nn % 2 ) == 1 ? "b" : "w";
		var piece = names[n].substring(len-6,len-5);
		if (( moves[ n ] & 0x380 ) == 0x80 )
			piece = "q";
		else if (( moves[ n ] & 0x380 ) == 0x100 )
			piece = "n";
		else if (( moves[ n ] & 0x380 ) == 0x180 )
			piece = "b";
		else if (( moves[ n ] & 0x380 ) == 0x200 )
			piece = "r";
		document.images[ base + to ].src = names[n].substring(0,len-6) + piece + dest + names[n].substring(len-4,len);
		nn = (Math.floor(( from / 8 )) + ( from % 8 ));
		if (( nn % 2 ) == 1 )
			document.images[ base + from ].src = EmptyBlackPath;
		else
			document.images[ base + from ].src = EmptyWhitePath;
		nMoves[nm]++;
		if ( nMoves[nm] < moves.length / 2 && ( moves[ nMoves[nm]*2 ] & 0x40 ) == 0x40 )
			MF( moves, names, nm, base );
	}
	return base
}
function MB( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	if ( nMoves[nm] > 0 )
	{	nMoves[nm]--;
		var from = moves[ nMoves[nm]*2 ] & 0x3f;
		var to = moves[ nMoves[nm]*2+1 ] & 0x3f;
		document.images[ base + from ].src = names[ nMoves[nm]*2 ];
		document.images[ base + to ].src = names[ nMoves[nm]*2+1 ];
		if (( moves[ nMoves[nm]*2 ] & 0x40 ) == 0x40 )
			MB( moves, names, nm, base );
	}
	return base;
}
function GMS( moves, names, nm, base, basename )
{	base = SyncPicture( base, basename );
	if ( nMoves[nm] > 0 && nMoves[nm] <= moves.length / 2 )
	{	var n = (nMoves[nm]-1)*2;
		var from = moves[ n ] & 0x3f;
		var to = moves[ n+1 ] & 0x3f;
		var len = document.images[ base + to ].src.length;
		var piece = document.images[ base + to ].src.substring(len-6,len-5);
		if ( piece == "q" )
			piece = pieces.substring(1,2);
		else if ( piece == "r" )
			piece = pieces.substring(4,5);
		else if ( piece == "b" )
			piece = pieces.substring(3,4);
		else if ( piece == "n" )
			piece = pieces.substring(2,3);
		else if ( piece == "k" )
			piece = pieces.substring(0,1);
		else piece = pieces.substring(5,6);
		var piece2 = "";
		if (( moves[ n ] & 0x380 ) == 0x80 )
			piece2 = pieces.substring(1,2);
		else if (( moves[ n ] & 0x380 ) == 0x100 )
			piece2 = pieces.substring(2,3);
		else if (( moves[ n ] & 0x380 ) == 0x180 )
			piece2 = pieces.substring(3,4);
		else if (( moves[ n ] & 0x380 ) == 0x200 )
			piece2 = pieces.substring(4,5);
		var lines = "abcdefgh";
		var rows = "87654321";
		var fromLine = from%8;
		var fromRow = Math.floor(from/8);
		var toLine = to%8;
		var toRow = Math.floor(to/8);
		var off=1;
		for ( i=0; i <= n; i += 2 )
			if (( moves[i] & 0x40 ) == 0x40 )
				off = off+1;
		var result = (Math.floor((nMoves[nm]-off)/2)+1).toString() + ". ";
		if ( document.images[ base + to ].src.substring(len-7,len-6) == "b" )
			result = result + "... ";
		if ( n >= 2 && (( moves[n] & 0x40 ) == 0x40 ))
		{	if (( moves[n-1] == 62 ) || ( moves[n-1] == 6 ))
				result = result + "0-0"
			else if (( moves[n-1] == 2 + 7 * 8 ) || ( moves[n-1] == 2 + 0 * 8 ))
				result = result + "0-0-0"
			else
			{	var sep = "x";
				from = moves[ n-2 ] & 0x3f;
				to = moves[ n-1 ] & 0x3f;
				fromLine = from%8;
				fromRow = Math.floor(from/8);
				toLine = to%8;
				toRow = Math.floor(to/8);
				result = result	+ lines.substring( fromLine, fromLine+1 ) + rows.substring( fromRow, fromRow+1 )
										+ sep
										+ lines.substring( toLine, toLine+1 ) + rows.substring( toRow, toRow+1 )
										+ piece2 + " ep";
			}
		}
		else
		{	var len = names[ n+1 ].length;
			var substr = names[ n+1 ].substring( len-6, len );
			var sep = (( substr == "/w.gif" ) || ( substr == "\\w.gif" ) ||
						  ( substr == "/b.gif" ) || ( substr == "\\b.gif" )) ? "-" : "x";
			if ( piece2 != "" ) piece = "";
			result = result + piece.toUpperCase() + lines.substring( fromLine, fromLine+1 ) + rows.substring( fromRow, fromRow+1 )
				+ sep
				+ lines.substring( toLine, toLine+1 ) + rows.substring( toRow, toRow+1 )
				+ piece2;
		}
		return result;
	}
	return "";
}
