/* Copyright (c)2002 ELR Software Pty Ltd. http://www.elr.com.au   */
/*                                                                 */
/* This program is free software; you may use, redistribute and/or */
/* modify it under the terms of the GNU General Public License as  */
/* published by the Free Software Foundation; either version 2 of  */
/* the License, or (at your option) any later version.             */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of  */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.            */
/* See the GNU General Public License for more details.            */
/* http://www.fsf.org/home.html                                    */


/* LiteracyGame Object - contains generic game methods */
function taskMaster () {
  this.Pal0         = new Array('#ffcccc','#ffcc00','#ffff99','#99ff99','#ccffff','#66ffcc','#cc99cc');
  this.Pal1         = new Array('#ff9999','#ff9900','#ffcc33','#33cc66','#0099cc','#009999','#cc66cc');
  this.HAlign       = new Array('left','center','right');
  this.VAlign       = new Array('top','middle','bottom');
  this.Data         = new Object();  /* Holder for a user data record */
  this.randInt      = function(n){return(Math.round(Math.random()*n))};
  this.shuffleA     = function(A){var tmp,j;for (var i=A.length-1;i>0;i--){j=Math.round(Math.random()*i);tmp=A[i];A[i]=A[j];A[j]=tmp;} return(A)};
  this.minMax       = function(n,min,max){return(Math.min(max,Math.max(n,min)))};
  this.Counter      = -1;
  this.Firsttime    = true;
  this.HotKey       = new Array();
  this.HotKey[0]    = 32; /* space - others may be added by caller */
  this.doHotKey     = function(){for (var i=0;i<LG.HotKey.length;i++) {if (event.keyCode == LG.HotKey[i]) {doItem(event.keyCode)}}};
  this.randbgColor  = this.Pal0[this.randInt(this.Pal0.length)];
  this.matchColor   = function(c){var n=0; for (var i=0; i<=this.Pal1.length; i++) {if (c.toLowerCase() == this.Pal0[i]) {n = i}}return(this.Pal1[n]);}
  this.vcr          = VCRTABLE;
  this.goBtn        = GOTABLE;
  this.SpeakOn      = true;
  this.AgentYN      = new Array(3);  /* Generic yesno answers for MSAgent speak */
  this.AgentYN[0]   = 'Well done!|Right on!|You got it!|That\'s the one!|Great!|You beauty!|Excellent!|Fantastic!';
  this.AgentYN[1]   = 'Sorry, try again!|Are you sure?|Better check that!|Oops, not that one!';
  this.AgentYN[2]   = 'You have already done this one.|Try another one.';
  this.ScreenWidth  = (window.screen.width == 0)  ? window.screen.width  : 800;
  this.ScreenHeight = (window.screen.height == 0) ? window.screen.height : 600;
  this.getHashParam = function() {return(location.hash.substr(1,location.hash.length))}
}/* End Object */

/* Some useful specials */
String.prototype.getCount = GetCount;
function GetCount(x) {
  var text = this;
  var count = 0;
  var index = text.indexOf(x);
  while(index != -1) {
    count++;
    var temp = text.substring(index+1, text.length);
    text = temp;
    index = text.indexOf(x);
  }
  return count;
}


/* HTML for VCR buttons */
var VCRTABLE =
'<table border="0" cellspacing="0" cellpadding="0"><tr>'+
'<td><img id="vcr0" src="./common/vcr0.gif" onClick="doVCR(0)"  height="64" width="64" border="0" class="mouse_Off" onmouseover="WC.toggleWC(0);this.className=\'mouse_On\'" onmousedown="this.className=\'mouse_Down\'" onmouseup="this.className=\'mouse_Up\'" onmouseout="WC.toggleWC(1);this.className=\'mouse_Off\'" alt=""></td>'+
'<td><img id="vcr1" src="./common/vcr1.gif" onClick="doVCR(-1)" height="64" width="64" border="0" class="mouse_Off" onmouseover="WC.toggleWC(0);this.className=\'mouse_On\'" onmousedown="this.className=\'mouse_Down\'" onmouseup="this.className=\'mouse_Up\'" onmouseout="WC.toggleWC(1);this.className=\'mouse_Off\'" alt=""></td>'+
'<td><img id="vcr2" src="./common/vcr2.gif" onClick="doVCR(1)"  height="64" width="64" border="0" class="mouse_Off" onmouseover="WC.toggleWC(0);this.className=\'mouse_On\'" onmousedown="this.className=\'mouse_Down\'" onmouseup="this.className=\'mouse_Up\'" onmouseout="WC.toggleWC(1);this.className=\'mouse_Off\'" alt=""></td>'+
'<td><img id="vcr3" src="./common/vcr3.gif" onClick="doVCR(2)"  height="64" width="64" border="0" class="mouse_Off" onmouseover="WC.toggleWC(0);this.className=\'mouse_On\'" onmousedown="this.className=\'mouse_Down\'" onmouseup="this.className=\'mouse_Up\'" onmouseout="WC.toggleWC(1);this.className=\'mouse_Off\'" alt=""></td>'+
'</tr><tr>'+
'<td align="center" class="sysnoteB">Start</td>'+
'<td align="center" class="sysnoteB">Back</td>'+
'<td align="center" class="sysnoteB">Next</td>'+
'<td align="center" class="sysnoteB">End</td>'+
'</tr></table>';

/* HTML for GO button */
var GOTABLE =
'<table border="0" cellspacing="0" cellpadding="0"><tr>'+
'<td><img id="go0" src="./common/go0.gif" onClick="doItem()" tabindex="1" height="64" width="64" border="0" class="mouse_Off" onmouseover="WC.toggleWC(0);this.className=\'mouse_On\'" onmousedown="this.className=\'mouse_Down\'" onmouseup="this.className=\'mouse_Up\'" onmouseout="WC.toggleWC(1);this.className=\'mouse_Off\'" alt=""></td>'+
'</tr><tr>'+
'<td align="center" class="sysnoteB">Go</td>'+
'</tr></table>';

/* Create a LiteracyGame object */
var LG = new taskMaster();

/* Create a MSAgent object if possible */
if (''+typeof(MSAgent) != 'undefined') {var MSA = new MSAgent('',18)}

