$(document).ready(function() {
  // make sure the image is below the content
  var relocateBanner = function() {
    $("#pageBackground").css("backgroundPosition",
      $("#content").offset().left + "px top");
  };

  $(window).resize(relocateBanner); // TODO not good enough in safari
  relocateBanner();

  // switcher stuff
  var switchBanner = function(imgSrc) {
    $("#pageBackground").css("backgroundImage", "url(" + imgSrc + ")");
    $("#printBanner").attr("src", imgSrc);
  }

  //if ($("#content .switcher").hasClass("hidden")) {
  var images = $("#content .switcher img");

  if (images.length > 1) {
    var imageSources = [];

    for (i = 0; i < images.length; i++)
      imageSources.push($(images[i]).attr("src"));

    var interval = 20000; // slideshow interval (20 seconds)

    var autoSwitch = function() {
      switchBanner(imageSources[1]);

      imageSources.push(imageSources.shift());
      setTimeout(autoSwitch, interval);
    }

    setTimeout(autoSwitch, interval);
  }
  //} else {
  $("#content .switcher img").mouseover(function() {
    switchBanner($(this).attr("src"));
  });
//}
});

