// GENERATE A RANDOM BANNER IMAGE

if (eval(unescape(window.location).match(/tsunami/i))) {
  // test if URL contains "tsunami"
  var n = 1; // default image
  var r = 4; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org.ae/banner/ae_" + n + ".jpg";
  credit = "";
} 
else if ( eval(unescape(window.location).match(/jobs\.undp\.org/i)) || eval(unescape(window.location).match(/jobs-beta\.undp\.org/i)) )  {
  // test if URL contains "jobs.undp.org"
  var n = 1; // default image
  var r = 8; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org.ae/banner/ae_" + n + ".jpg";
  credit = "";
  
} 
else if ( eval(unescape(window.location).match(/bulletin\.undp\.org/i)))  {
  // test if URL contains "bulletin.undp.org"
  var n = 1; // default image
  var r = 5; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org.ae/banner/ae_" + n + ".jpg";
  credit = "";
}
else {
  // no match, choose from one of the default sets
  var n = 1; // default image
  
  // pick a number between 1 and 10
  var chance = Math.round(Math.random()*9) + 1;

  // use each set 40/60% of the time
  if (chance > 6) {
    // UNCDF
    var r = 8; // # of images in set
    n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
    i = "http://www.undp.org.ae/banner/ae_" + n + ".jpg";
    credit = "";
  } else {
    // Aerial Images
    var r = 8; // # of images in set
    n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
    i = "http://www.undp.org.ae/banner/ae_" + n + ".jpg";
    credit = "";
  }

}

// write image CSS
document.write('<style type="text/css">.banner {background-image: url(' + i + ');}</style>');


