// array of messages to pop up

var messages = new Array(
  "High quality music<br><img src='pic/25x5.gif'>typesetting",
  "Jazz",
  "New music",
  "Scholarly editions",
  "Medi&aelig;val music",
  "Choral music",
  "Web sites",
  "Integrated volumes of<br><img src='pic/25x5.gif'>text and music",
  "Font design",
  "Typographic design",
  "Web sites"
);

var messageInd=0;
var lastmessageInd=messageInd;
var messageStr= new String();
var strtoshow= new String();

// array of font sizes and faces (relying on spans in main.css to set size)
var fsize = new Array(
  "<span class=s0>",
  "<span class=s1>",
  "<span class=s2>",
  "<span class=s3>",
  "<span class=s4>",
  "<span class=s5>",
  "<span class=s6>",
  "<span class=s7>"
);
var fsizeInd=(Math.round(Math.random()*10))%(fsize.length-1);

// array of font styles

var fstyle = new Array(
  "",
  "<i>",
  "<b>",
  "<b><i>"
);
var fstyleInd=(Math.round(Math.random()*10))%(fstyle.length-1);


// array to cancel font styles
var fstylecancel = new Array(
  "",
  "</i>",
  "</b>",
  "</b></i>"
);

// array to hold colours
var colours = new Array(
  "#ffffff",
  "#eeeeee",
  "#dddddd",
  "#cccccc",
  "#bbbbbb",
  "#aaaaaa",
  "#999999",
  "#888888",
  "#777777",
  "#666666",
  "#555555",
  "#444444",
  "#333333",
  "#222222",
  "#111111",
  "#000000"
)
var coloursInd=0;
var colourCount=0;

function generateMessage(){
  messageInd=(Math.round(Math.random()*10))%(messages.length-1);
  if(lastmessageInd==messageInd){
     messageInd=(messageInd+1)%(messages.length-1);
  }
  lastmessageInd=messageInd;

  messageStr=fsize[fsizeInd]+fstyle[fstyleInd]+messages[messageInd]+fstylecancel[fstyleInd]+"</span>";

  fstyleInd=(Math.round(Math.random()*10))%(fstyle.length-1);
  fsizeInd=(Math.round(Math.random()*10))%(fsize.length-1);
  return messageStr;
}

// Create the two DynEl objects that we'll use in the program.
// These must be created in the <HEAD> of the document, because
// the DynEl() constructor outputs a style sheet.

// NB this starts with empty message

var baseind=400;
var dynel0 = new DynEl(window, "d0", "", 0, 0);
var dynel1 = new DynEl(window, "d1", "", baseind, 20);



function displaymessage(){
  randomsetup();
  setInterval("fadefunc()",50);
}

function fadefunc(){
  dynel1.setBody("<font color="+colours[colourInd]+">"+messageStr+"</font>");
  colourCount=colourCount+1;
  if(colourCount<colours.length){colourInd=colourCount;}
  if(colourCount>32){colourInd--;}
  if(colourInd<0){
    colourCount=0;
    randomsetup();
  }
}


function randomsetup(){
  generateMessage();

  var innerwidth=window.innerWidth;

  if(typeof(innerwidth)!="number"){  // this means we are using IE

    innerwidth=window.document.body.offsetWidth;
  }
  var availablespace=innerwidth-baseind;

  if(messageStr.length > 18){
    var dx=(Math.random())*availablespace*0.3;
    }
  else{
    var dx=(Math.random())*availablespace*0.8;
  }
  if(messageStr.indexOf("<br>")==-1){
    var dy=(Math.random()-0.5)*20;
    }
  else{
    var dy=(Math.random()-0.5)*10;
  }

  dynel1.moveTo(dynel1.initial_left+dx,dynel1.initial_top+dy);
  colourInd=0;
}

