/* 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                                    */


/***********************************************/
var Wordset = new Array();
var count   = -1;
Wordset.Initialize = wordset_initialize;
/***********************************************/
/* Generic word sets                           */
/***********************************************/
Wordset[++count] = new WordsetData(
  "Numbers",
  0,
  "Numbers zero to nine",
  "zero|one|two|three|four|five|six|seven|eight|nine",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Numbers",
  10,
  "Numbers ten to nineteen",
  "ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Numbers",
  20,
  "Numbers twenty, thirty ... to one hundred",
  "twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|one hundred",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Numbers",
  100,
  "Numbers one to nineteen, and twenty to one hundred",
  "NUMBERS_0~NUMBERS_10~NUMBERS_20",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Days",
  1,
  "Days of the week",
  "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Months",
  1,
  "Months of the year",
  "January|February|March|April|May|June|July|August|September|October|November|December",
  "",
  true
  );
Wordset[++count] = new WordsetData(
  "Calendar Words",
  1,
  "Day and months names",
  "DAYS_1~MONTHS_1",
  "",
  true
  );
/***********************************************/
/* Literacy online project word sets           */
/***********************************************/
/* Work Education Group #2 */
/* Words */

Wordset[++count] = new WordsetData(
  "Sport Words",
  2,
  "",
  "football|tennis|basketball|cricket|swimming|diving|sailing|bowling|golf",
  "sport1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Words",
  2,
  "",
  "music|dancing|painting|art|television|video|band|party",
  "art2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Words",
  5,
  "",
  "bread|cake|apple|carrot|hamburger|pizza|pie|cooking|recipe|biscuit",
  "food1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Words",
  2,
  "",
  "bread|wine|cheese|pear|glass",
  "food1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Words",
  2,
  "",
  "computer|internet|web|home|menu|back|forward|print|search|google",
  "computer.jpg",
  true
  );
/* Wordbook */
Wordset[++count] = new WordsetData(
  "Wordbook",
  2,
  "",
  "SPORT_WORDS_2~FUN_WORDS_2~FOOD_WORDS_2~COMPUTER_AND_INTERNET_WORDS_2",
  "",
  true
  );
/* Sentences */
Wordset[++count] = new WordsetData(
  "Sport Sentences",
  2,
  "",
/*  "The big match is tomorrow.|I have tickets.|Hope it doesn't rain.|My team won last week.|They have the tallest player", */
  "The big game is tomorrow.|I have tickets.|I plan to go on the bus.|My team won last week.|They have the tallest player",
  "sport2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Sentences",
  2,
  "",
/*  "I like dancing.|The movie was about a dancing lady.|She won the dancing competition.|The music was great.|We got home late.|We had take-away pizza", */
  "I like dancing.|The star of the movie was a dancing lady.|She won the dancing competition.|The music was great.|I got home late.|I had a pizza and beer.",
  "showtime.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Sentences",
  2,
  "",
  /* "We had a dinner party last night.|There were six of us.|We cooked pasta.|It had sea food in it.|We all ate too much", */
  "We had a party last night.|There were six of us.|We cooked spaghetti.|It had sea food in it.|We ate a big plate full.",
  "food2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Sentences",
  2,
  "",
/*  "I use email to talk to my friends.|Some of them live in other countries.|It takes only a second to get there.|Even to the other side of the world.|I still have a lot to learn", */
  "I like to get on the internet.|I see things from other countries.|It is quick to connect to other places in the world.|I want to learn anything I can.",
  "earth.jpg",
  true
  );

/* General Education Group #3 */
/* Words */
Wordset[++count] = new WordsetData(
  "Sport Words",
  3,
  "",
  "SPORT_WORDS_2",
  "sport1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Words",
  3,
  "",
  "FUN_WORDS_2",
  "art2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Words",
  3,
  "",
  "FOOD_WORDS_2",
  "food1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Words",
  3,
  "",
  "COMPUTER_AND_INTERNET_WORDS_2",
  "computer.jpg",
  true
  );
/* Wordbook */
Wordset[++count] = new WordsetData(
  "Wordbook",
  3,
  "",
  "SPORT_WORDS_3~FUN_WORDS_3~FOOD_WORDS_3~COMPUTER_AND_INTERNET_WORDS_3",
  "",
  true
  );
/* Sentences */
Wordset[++count] = new WordsetData(
  "Sport Sentences",
  3,
  "",
  "SPORT_SENTENCES_2",
  "sport2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Sentences",
  3,
  "",
  "FUN_SENTENCES_2",
  "showtime.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Sentences",
  3,
  "",
  "FOOD_SENTENCES_2",
  "food2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Sentences",
  3,
  "",
  "COMPUTER_AND_INTERNET_SENTENCES_2",
  "earth.jpg",
  true
  );

/* Arts Education Group #4 */
/* Words */
Wordset[++count] = new WordsetData(
  "Sport Words",
  4,
  "",
  "SPORT_WORDS_2",
  "sport1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Words",
  4,
  "",
  "FUN_WORDS_2",
  "art2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Words",
  4,
  "",
  "FOOD_WORDS_2",
  "food1.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Words",
  4,
  "",
  "COMPUTER_AND_INTERNET_WORDS_2",
  "computer.jpg",
  true
  );
/* Wordbook */
Wordset[++count] = new WordsetData(
  "Wordbook",
  4,
  "",
  "SPORT_WORDS_4~FUN_WORDS_4~FOOD_WORDS_4~COMPUTER_AND_INTERNET_WORDS_4",
  "",
  true
  );
/* Sentences */
Wordset[++count] = new WordsetData(
  "Sport Sentences",
  4,
  "",
  "SPORT_SENTENCES_2",
  "sport2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Fun Sentences",
  4,
  "",
  "FUN_SENTENCES_2",
  "showtime.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Food Sentences",
  4,
  "",
  "FOOD_SENTENCES_2",
  "food2.jpg",
  true
  );
Wordset[++count] = new WordsetData(
  "Computer and Internet Sentences",
  4,
  "",
  "COMPUTER_AND_INTERNET_SENTENCES_2",
  "earth.jpg",
  true
  );


/* WordsetDat Object definition */
function WordsetData(title, item, descrip, data, imagesrc, speak) {
  this.title     = (title)       ? title    : "Unspecified";
  this.item      = (""+item >"") ? ""+item  : 0;
  this.data      = (data)        ? data     : "example";
  this.descrip   = (descrip)     ? descrip  : "No description";
  this.imagesrc  = (imagesrc)    ? imagesrc : "yourpic.gif";
  this.speak     = (speak)       ? true     : false;
  this.subtitles = '';           /* Filled dynamically during initialization */
  /* alert(this.makeCode()); */ /* Wordset[this.makeCode()] = this; */
}
  WordsetData.prototype.FieldSep    = '|'; /* Field separator */
  WordsetData.prototype.RecordSep   = '~'; /* Record separator */
  WordsetData.prototype.CodeSep     = '_'; /* Macro code separator */
  WordsetData.prototype.makeCode    = wordsetdata_makecode;
  WordsetData.prototype.split2Array = wordsetdata_split2array;

function wordsetdata_makecode() {
  var s = this.title.toUpperCase()+this.CodeSep+this.item;
  var ss = '';
  for (var i=0; i<s.length; i++) {
    ss += (s.charAt(i) == ' ') ? this.CodeSep : s.charAt(i);
  }
  return(ss);
}

function wordsetdata_split2array(str) {
  str = (str) ? str : 'data';
  var sep = (this[str].indexOf(this.RecordSep)>=0) ? this.RecordSep : this.FieldSep;
  var A = this[str].split(sep);
  return(A);
}

/* Wordset Object definition */
function wordset_initialize() {
  var sep = "\x01"; /* A working separator - anything not used in data! */
  var S = s = key = ''; var A;
  /* Set up an alternative associative array */
  for (var i=0; i<this.length; i++) {
    key = this[i].makeCode();    /* Make our unique (should be) key field */
    this[key] = this[i];         /* This key value is equivalent to the index value */
  }
  /* Collect the sub-titles for Wordbook type entries */
  for (var i=0; i<this.length; i++) {
    var regexp = new RegExp("[A-Z][A-Z"+this[i].CodeSep+"]+"+this[i].CodeSep+"[0-9]+","g");
    this[i].subtitles = this[i].title;               /* If a mono-set subtitle=title */
    if (this[i].data.match(regexp) != null) {        /* Are we dealing with data containing a key macro? */
      A = this[i].split2Array(); /* alert(A); */
      for (var j=0; j<this.length; j++) {            /* Examine the referred to keys */
        if (typeof(this[A[j]]) == 'object') {        /* and concat titles with separator as needed */
          this[i].subtitles = (j==0) ? this[A[j]].title : (this[i].subtitles + this[i].FieldSep + this[A[j]].title)
        }
      }
    }
  }
  /* Finally go through data again expanding macros in data fields */
  for (var i=0; i<this.length; i++) {                 /* First make all data a single string */
    S = (i==0) ? this[i].data : (S+sep+this[i].data); /* - separated by something unique */
  } /* alert(S); */
  key = S.match(regexp);                              /* Then search for keys in string */
  while (key != null) {                               /* as long as there are some and a data key exists */
    s = (typeof(this[key[0]]) == 'object') ? this[key[0]].data : "Error!";
    S = S.replace(key[0],s);                          /* replace them with expanded form - or error */
    key = S.match(regexp);
  } /* alert(S); */
  S = S.split(sep);                                   /* Then, split our string back to an array */
  for (var i=0; i<this.length; i++) {
    this[i].data = S[i];                              /* and re-assign data whence it came */
  }
}

/*************************************/
Wordset.Initialize();  /* Initialise */
/*************************************/

