// Requires: scripts/utils.js to set/get cookies

var backgrounds = [
  "paper.gif",
  "marble.png",
  "ice.png",
  "purple_marble.png",
  "pink_marble.jpg",
  "black_marble.jpg",
  "moss.jpg",
  "burlwood.jpg",
  "wood.png",
  "bluemica.gif",
  "clouds.gif",
  "bluedots.gif",
  "purple_stuco.jpg",
  "pink_stuco.gif",
  "parch2.gif",
  "linen.jpg",
  "paper2.jpg",
  "manila_paper.png",
  "parch1.jpg",
  "#F8F8F8",
  "noise.png",
  "paper5.jpg",
  "paper01.jpg",
  "paper_flieder.png",
  "textured-white.jpg",
  "rough_paper.png",
  "paper6.jpg"
];
var backgroundColors = "white red orange yellow green blue purple".split(' ');
var backgroundText = [
  "black",      // paper
  "black",      // marble
  "black",      // ice
  "black",      // purble_marble
  "black",      // pink_marble
  "#FFFFFF",    // black_marble
  "#EFFFF0",    // moss
  "#F8F0D0",    // burlwood
  "black",      // wood
  "#001A3F",    // bluemica
  "#00001F",    // clouds
  "#00013F",    // bluedots
  "#00013F",    // purple_stuco
  "#1C1616",    // pink_stuco
  "black",      // parch2
  "black",      // linen
  "black",      // paper2
  "#1F1900",    // manila_paper
  "#1F1900",    // parch1
  "black",      // solid grey
  "black",      // noise
  "black",      // paper5
  "black",      // paper01
  "black",      // paper_fielder
  "black",      // textured-white
  "black",      // rough_paper
  "black"      // paper6
];

var backgroundTextLabels = 'HeaderTitle HeaderSubtitle Login username password signin contact';
var background = 0;

function SetTextColor(color) {
  if (typeof backgroundTextLabels == 'string') {
    backgroundTextLabels = backgroundTextLabels.split(' ');
  }
  for (i in backgroundTextLabels) {
    elem = document.getElementById(backgroundTextLabels[i]);
    if (elem) {
      elem.style.color = color;
      if (i >= 2 && i <= 7) {
        elem.style.fontWeight = (color.substring(0,1) == '#') ? 'bold' : 'normal';
      }
    }
  } 
}
function ChangeBackground(inc) {
  background += inc;
  if (background >= backgrounds.length) {
    background = 0;
  } else if (background < 0) {
    background = backgrounds.length - 1;
  }
  var bg = backgrounds[background];
  if (bg.charAt(0) == '#') {
    document.body.style.background = bg;
  } else if (bg.indexOf('.') > 0) {
    var url = "url(images/" + bg + ")";
    document.body.style.backgroundImage = url;
  } else if (bg.length == 0) {
    document.body.style.backgroundImage = 'none';
    document.body.style.background = 'white';
  } else {
    document.body.style.background = bg;
  }
  if (SetCookie)
    SetCookie("bgid",background);
  // Do this last, in case the function isn't defined
  //if (typeof(SetTextColor) == 'function')
    SetTextColor(backgroundText[background]);
  //else
  //  alert("Missing function: SetTextColor");
}
function ChangeColor() {
  if (++background >= backgroundColors.length) {
    background = 0;
  }
  document.body.style.background = backgroundColors[background];
  if (SetCookie)
    SetCookie("bgid",background);
}
function LoadBackground(labels) {
  backgroundTextLabels += ' '+labels;
  var id = GetCookie("bgid");
  if (id != null) {
    background = id - '0';
  }
  ChangeBackground(0);
}
