var opacity=0; // prevents problems with retarded internet explorer
//internal functions - do not modify

function SlideShow(label)
{
  preloadImages();
  setTimeout('shuffle("' + label + '")', 2500);
  return
}

function preloadImages()
{
  I = new Image;
  for (i=1; i<=count; i++)
  {
    currentimage=imagearray[i].split(",");
    I.src=currentimage[0];
  }
  for (i=1; i>1; 0)
  {
    if (I.complete)
      i++;
  }
  return;
}

function shuffle(label)
{
  rand=random(0, count);
  currentimage=imagearray[rand].split(",");
  var cmdstring="shuffle('" + label + "')";
  var TO=setTimeout(cmdstring, Math.floor(interval*1000));
  var time = Fade(0, steps, label);
  setTimeout('UpdateImage("' + label + '")', time);
  setTimeout('FadeBG("' + ((currentimage[3]==undefined) ? defaultcolor : currentimage[3]) + '", ' + Math.floor(steps) + ')', 2 * time / 3);
  setTimeout('Fade(1, steps, "' + label + '")', time * 1.5);
}

function Fade(end, steps, id)
{
  var start = opacity;
  var delta = end - start;
  for(t=1; t<=steps; t=t+1)
  {
    alpha = (Math.floor((start+(t*delta/steps))*100));
    if (alpha <= 0)
      alpha = 1;
    if (navigator.appName == "Microsoft Internet Explorer")
      setTimeout('document.getElementById("' + id + '").filters.alpha.opacity=' + alpha, t * 30);
    else
      setTimeout('document.getElementById("' + id + '").style.opacity=' + (start+(t*delta/steps)), t * 30);
  }
  opacity=end;
  return (t * 30);
}

function UpdateImage(label)
{ 
  document.getElementById(label).src=currentimage[0];
  document.getElementById(label).width=currentimage[1];
  document.getElementById(label).height=currentimage[2];
}

function random(min,max)
{
  if (max<min){return "error";}
  n=Math.random();
  n=Math.floor((max-min+1)*n)+min;
  if (n>max){n=random(min,max);}
  return n;
}

function FadeBG(endBG, steps)
{
  var startR = parseInt(document.bgColor.substr(1, 2), 16);
  var startG = parseInt(document.bgColor.substr(3, 2), 16);
  var startB = parseInt(document.bgColor.substr(5, 2), 16);
  var deltaR = (parseInt(endBG.substr(1, 2), 16) - startR) / steps;
  var deltaG = (parseInt(endBG.substr(3, 2), 16) - startG) / steps;
  var deltaB = (parseInt(endBG.substr(5, 2), 16) - startB) / steps;
  for(t=1; t<=steps; t=t+1)
  {
    color = ((startR + t * deltaR < 16) ? '0' + Math.floor(startR + t * deltaR).toString(16) : Math.floor(startR + t * deltaR).toString(16)) + ((startG + t * deltaG < 16) ? '0' + Math.floor(startG + t * deltaG).toString(16) : Math.floor(startG + t * deltaG).toString(16)) + ((startB + t * deltaB < 16) ? '0' + Math.floor(startB + t * deltaB).toString(16) : Math.floor(startB + t * deltaB).toString(16));
    setTimeout('document.bgColor="#' + color + '"', t * 30);
  }
  return (t * 30);
}
  
