// Rediware Software 2002
// variables
var blueleft = 3;
var redleft = 3;
var blueright = 0;
var redright = 0;
var direction = "right"
var movered = 0;
var moveblue = 0;

var moves = 0;

var blankman = new Image();
blankman.src="blankman.gif";
var blueman = new Image();
blueman.src = "blueman.gif";
var redman = new Image();
redman.src="redman.gif";
var transportleft = new Image();
transportleft.src = "transportleft.gif";
var transportright = new Image();
transportright.src = "transportright.gif";
var transportbroken = new Image();
transportbroken.src = "transportbroken.gif";

// *******************************************************************
function movered_click(quan) {


movered = quan;
}
// ********************************************************************
function moveblue_click(quan) {
moveblue = quan;
}
// ********************************************************************
function movem_click() {

moves = (moves + 1);

if (direction=="lost") {
alert("Your game is over! You lost, remember?\nPress reset to play a new game."); }

else if (direction=="won") {
alert("Your game is over! You won, remember?\nPress reset to play a new game."); }

else if (direction=="right") {
var Tblueleft=(blueleft-moveblue);
var Tblueright=(blueright+moveblue);
var Tredleft=(redleft-movered);
var Tredright=(redright+movered); 
direction="left"  }

else if (direction=="left") {
var Tblueleft=(blueleft+moveblue);
var Tblueright=(blueright-moveblue);
var Tredleft=(redleft+movered);
var Tredright=(redright-movered); 
direction="right" }

if ((direction != "won") && (direction != "lost")) {
	if ((moveblue+movered)>2) {
	alert("Only two can fit into the transport!\nYou broke it!");
	lose(); }
	else if ((movered+moveblue)==0) {
	alert("If no one's going, who'll operate the transport?\nIt departed empty!");
	lose(); }
	else if ((Tblueleft<0) || (Tblueright<0)) {
	alert("I don't see that many bluemen to move!\nA vicious fight broke out and 	damaged the transport!"); 
	lose();  }
	else if ((Tredleft<0) || (Tredright<0)) {
	alert("I don't see that many redmen to move!\nThis caused tempers to flare and 	the transport was damaged during the ruckus!"); 
	lose(); }
	else {
	blueleft=Tblueleft;
	blueright=Tblueright;
	redleft=Tredleft;
	redright=Tredright;
	changeImage(); 
	 if (((redleft>blueleft) && (blueleft!=0)) || (redright>blueright) && 	(blueright!=0)) {
	alert("The redmen outnumber the bluemen!\nIt's dinnertime!!");
	lose(); } }

	if ((blueleft==0) && (redleft==0)) {
	win(); }

	if (direction=="left") {
	document.transport.src=transportleft.src;
	playasound(0); }
	else if (direction=="right") {
	document.transport.src=transportright.src;
	playasound(0); }
	else if (direction=="lost") {
	document.transport.src=transportbroken.src; }
	else if (direction=="won") {
	document.transport.src=transportleft.src; }  }

}
// ***********************************************************************

function changeImage() {
// NOTE: for Netscape to work, indexes of arrays MUST be in square brackets!!

for (x=0; x<3; x++) {

//document.images[x+3].src = blankman.src;
vspotleftleft[x].src=blankman.src; 

//document.images[x+6].src = blankman.src;
vspotleftright[x].src=blankman.src;

//document.images[x+10].src = blankman.src;
vspotrightleft[x].src=blankman.src; 

//document.images[x+13].src = blankman.src; }
vspotrightright[x].src=blankman.src; }


for (x=0; x<(blueleft); x++) {
//document.images[x+3].src = blueman.src;}
vspotleftleft[x].src=blueman.src; }

for (x=0; x<=(redleft-1); x++) {
//document.images[x+6].src=redman.src; }
vspotleftright[x].src=redman.src; }

for (x=0; x<=(blueright-1); x++) {
vspotrightleft[x].src=blueman.src; }
//document.images[x+10].src=blueman.src; }

for (x=0; x<=(redright-1); x++) {
vspotrightright[x].src=redman.src; }
//document.images[x+13].src=redman.src; }



}

// *********************************************************************
function lose() {
blueleft = -1;
blueright = -1;
redleft = -1;
redright = -1;
direction = "lost";
document.formTransport.transport.src=transportbroken.src;
alert("you lose!\nPress reset to play again.");
playasound(1);

}

// ******************************************************************************
function win() {

blueleft = 0;
redleft = 0;
blueright = 0;
redright = 0;
movered = 0;
moveblue = 0;
direction = "won"
playasound(2); 

if (moves > 11) {
alert("You have beaten TRANSPORT, but unfortunately \nare not entitled to join our winner's circle.\nTo do so, you must beat Transport in 11 moves or less. \nTry again!"); }
else {
var WinWin = window.open("transportform.htm");
alert("You have beaten TRANSPORT and are hereby invited to join our winner's circle!\nTo post your name in the winner's circle, simply enter your name or screen name \nin the following form and click the submit button!"); 
var TodayBlock = WinWin.document.WINFORM.MYTODAY;	
TodayBlock.value = new Date(); 
var ScreennameBlock = WinWin.document.WINFORM.SCREENNAME;	
ScreennameBlock.focus(); }
}

// ******************************************************************************
function newgame() {
// layout graphics
for (x = 0; x<3; x++) {
	document.write("<img name=\"spotleftleft\" src=\"blueman.gif\" >"); }

for (x = 0; x<3; x++) {
	document.write("<img name=\"spotleftright\" src=\"redman.gif\" >"); }

document.write("<img name=\"transport\" src=\"transportright.gif\" >"); 

for (x = 0; x<3; x++) {
	document.write("<img name=\"spotrightleft\" src=\"blankman.gif\" >"); }
for (x = 0; x<3; x++) {
	document.write("<img name=\"spotrightright\" src=\"blankman.gif\" >"); }

blueleft = 3;
redleft = 3;
blueright = 0;
redright = 0;
direction = "right"
movered = 0;
moveblue = 0;
moves = 0;

}


// **********************************************************************
// sound
var aySound = new Array();
// Below: source for sound files to be preloaded
aySound[0] = "transport.wav";
aySound[1] = "explode.wav";
aySound[2] = "winner.wav";

// DO NOT edit below this line
document.write('<BGSOUND ID="auIEContainer">');
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>";
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"));
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
// ******************************************************************************
function playasound(soundnumber) {
playSound(soundnumber);

}
// *******************************************************************************

// start the script

newgame();
// these variables must be set up AFTER they are drawn on the screen!!
var vspotleftleft = new Array(3);
vspotleftleft=document.formTransport.spotleftleft;

var vspotleftright = new Array(3);
vspotleftright = document.formTransport.spotleftright;

var vspotrightleft = new Array(3);
vspotrightleft = document.formTransport.spotrightleft;

var vspotrightright = new Array(3);
vspotrightright = document.formTransport.spotrightright;

