// Run the following once the DOM is ready.
$(function() {
  // Change the background so that it is closer to the second random color.
  // If it becomes the second random color, create a new color.
  var color1 = Color("FFF"), color2 = Color("hsl(240,100,50)"), percent = -10;
  (function() {
    // If reaching 100% at this point, generate the next color and set the
    // percentage back to zero.
    if((percent += 10) >= 100) {
      color1 = color2.clone();
      color2.h(parseInt(Math.randomIn(0,241)));  // Disallow shades of pink.
      percent = 0;
    }
    
    // Calculate the colors for the background and foreground.
    var bg = color1.combine(color2, percent);
    var fg = bg.getSafeColor();
    
    // Change the background color.
    $("#head-bg").css("backgroundColor", bg);
    
    // Make sure the title can be seen in front of the background color.
    $("#headCell").css({
      color : fg,
      textShadow : "0px 0px 9px " + bg.combine(fg, 75)
    });
    
    // If the in the middle of combining colors, call this function again in 100
    // ms, otherwise call this in 2 secs.
    setTimeout(arguments.callee, percent == 0 ? 2000 : 100);
  })();
  
  // Make sure the first element in the body will have a top margin of 0 pixels.
  for(var elem, i = 0, elems = $("#body > *"); elem = elems[i]; i++) {
    if(elem.offsetWidth > 0) {
      $(elem).css("margin-top", "0px");
      break;
    }
  }
  
  // Change all occurrences of "Save Target As..." to the correct phrase for the
  // user's browser.
  $(".saveAs").text({"Internet Explorer" : "Save Target As...",
    "Firefox" : "Save Link As...",
    "Safari" : "Download Linked File As..."}[$.browser]
    || "Save Target As...");
});
