// v2
// -------------------------- object: list

function list(str, splitchar)
{
  if(splitchar) this.splitter = splitchar;
  else this.splitter = "|";
  this.array = str.split(this.splitter);
  // methods
  this.getRandom = list__getRandom;
  this.all = list__all;
  this.sort = list__sort;
}

function list__getRandom()
{
  return this.array[random(this.array.length)-1];
}

function list__getRandomFmt()
{
  return " " + this.array[random(this.array.length)-1];
}

function list__all()
{
  this.sort();
  var l = "";
  for(i=0;i<this.array.length;i++) l = l + "<br>" + this.array[i];
  return l;
}

function list__sort() { this.array.sort(); }


// -------------------------- object: wordmaker

function wordmaker()
{
  this.prefix = new list("disincli deplora disso aggra infesta ulce malevo maligni xeno loathe nausea nause subme synco gramo melo disco minor semi slumber garga mam coma lethar lackadaisi undu grote sordi despica wretche vile magnifi beau opti deso melancho sini deje brilli dim murk sombe oppre electri insta letha drip drear necro dismal repel morti", " ");

  this.suffixNoun = new list("sance pion rument pathy sonance note bre chord quaver nity pulsion vulsion pugnance ror horrence mony rion tone ence mine cation", " ");

  this.suffixAdj = new list("fensive gusting some ful loth verse xious gust pellant cal monic phagus tonic matic dle phonous ding dious", " ");

  this.listParts = function _listParts()
  { 
    var list = "";
    list = this.prefix.all() + this.suffixNoun.all() + this.suffixAdj.all() + "<BR>";
    document.write(list);
  }

  this.makeNoun = function _makeNoun()
  { return this.prefix.getRandom() + this.suffixNoun.getRandom(); }

  this.makeAdj = function _makeAdj()
  { return this.prefix.getRandom() + this.suffixAdj.getRandom(); }

  this.makeWord = function _makeAWord()
  {
    if(random(2)==1) return this.makeNoun();
    else return this.makeAdj();
  }
}


// -------------------------- phrasemaker

function formatForA(theWord)
{
  var vowels = "a e i o u";
  var firstLetter = theWord.charAt(0);
  if(vowels.indexOf(firstLetter) != -1) return " an " + theWord;
  else return " a " + theWord;
}

function makePhrase()
{
  var youlooklike = new list("You are hairier than|I wish you were more like|I like you more than|You look like|You smell like|You sound like|You act like|You remind me of");
  var words = new wordmaker();
  return youlooklike.getRandom() + formatForA(words.makeAdj()) +" "+ words.makeNoun() +"!";
}


// -------------------------- misc

function chooseUnique(b, c, d, range)
{
  a = random(range)-1;
  if(a == b || a == c || a == d) a = chooseUnique(b, c, d, range);
  return a;
}

function random(range) { return (Math.floor(Math.random() * range) + 1); }


