/* 
   Random Image
   Version 1.0
   September 13, 2010

   Will Bontrager
   http://www.willmaster.com/
   Copyright 2010 Bontrager Connection, LLC

   Bontrager Connection, LLC grants you 
   a royalty free license to use or modify 
   this software provided this notice appears 
   on all copies. This software is provided 
   "AS IS," without a warranty of any kind.
*/
// Leave next line as is.
var Images = new Array(); // Leave this line as is.


// CUSTOMIZATION 
//
// Two places to customize.
//
// Place 1:
//
// If repetition restriction is desired, specify a cookie 
//   name. Otherwise, leave the CookeieName value blank ("").

var CookieName = "RandomImagePlacement";


//
// Place 2:
//
// For each div (or other HTML container) that will contain 
//   a random image:
//
//   Copy the line below (without the leading "//") --
//
//        Images["A"] = "B";
//
//     and paste it into the JavaScript code below this 
//     comment block.
//
//   Then --
//
//     i. Replace A between the quotation marks with the id 
//        value of the div (or other container).
//
//    ii. Replace B between the quotation marks with a list 
//        of image file SRC= URLs separated with a space. 

Images["one"] = "images/hid.gif images/utc.png images/fire-lite.gif images/pelco.gif images/silent-knight.gif";
Images["two"] = "images/dedicated-micros.gif images/von-duprin.gif images/bosch.gif images/aiphone.gif images/aes.gif";
Images["three"] = "images/panasonic.gif images/honeywell.gif images/roam-alert.gif images/s2.gif images/axis.gif";

//
// No other customizations required.
////////////////////////////////////
function DisplayRandomImages() {
var Now = Array();
var Prior = Array();
CookieName = CookieName.replace(/\W/g,"");
if(CookieName.length) { Prior = GetCookiePriorInformation(); }
for(var container in Images) {
   var imgstring = Images[container].replace(/^ */,"");
   imgstring = imgstring.replace(/ *$/,"");
   imgstring = imgstring.replace(/  +/g," ");
   var list = imgstring.split(" ");
   var img = 0;
   if(list.length > 1) {
      var img = Math.ceil(Math.random()*list.length)-1;
      while(img == Prior[container]) {
         img = Math.ceil(Math.random()*list.length)-1;
         }
      }
   Now[container] = img;
   var content = '<img src="'+list[img]+'" />';
   document.getElementById(container).innerHTML = content;
   if(CookieName.length) { StoreCookiePriorInformation(Now); }
   }
}

function GetCookiePriorInformation() {
var ck = new String();
var retarray = new Array();
var cookiebegin = document.cookie.indexOf(CookieName + "=");
if(cookiebegin > -1) {
   cookiebegin += 1 + CookieName.length;
   cookieend = document.cookie.indexOf(";",cookiebegin);
   if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
   ck = document.cookie.substring(cookiebegin,cookieend);
   }
if( ck.length ) {
   var parts = ck.split("&");
   for(var i=0; i<parts.length; i++) {
      var tarray = parts[i].split("=");
      retarray[tarray[0]] = tarray[1];
      }
   }
return retarray;
}

function StoreCookiePriorInformation(now) {
var parts = new Array();
for(var indice in now) { parts.push(indice+"="+now[indice]); }
document.cookie = CookieName + "=" + parts.join("&");
}

DisplayRandomImages();
