/* 
   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 = "MGCCTRandom1";


//
// 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["left"] = "http://www.mgtoronto.com/images/1929-1.jpg http://www.mgtoronto.com/images/1931-1.jpg http://www.mgtoronto.com/images/1932-1.jpg http://www.mgtoronto.com/images/1932.jpg http://www.mgtoronto.com/images/1933.jpg http://www.mgtoronto.com/images/1934.jpg http://www.mgtoronto.com/images/1935.jpg http://www.mgtoronto.com/images/1938.jpg http://www.mgtoronto.com/images/1939.jpg http://www.mgtoronto.com/images/tcgrille.jpg http://www.mgtoronto.com/images/1925.jpg http://www.mgtoronto.com/images/1925-1.jpg  http://www.mgtoronto.com/images/racing.jpg";

Images["left1"] = "http://www.mgtoronto.com/images/1946.jpg http://www.mgtoronto.com/images/1949.jpg http://www.mgtoronto.com/images/1947.jpg http://www.mgtoronto.com/images/1951.jpg http://www.mgtoronto.com/images/1953.jpg http://www.mgtoronto.com/images/1954-1.jpg http://www.mgtoronto.com/images/1955.jpg http://www.mgtoronto.com/images/bluetc.jpg http://www.mgtoronto.com/images/redtc.jpg  http://www.mgtoronto.com/images/1948.jpg http://www.mgtoronto.com/images/td-grille.jpg";

Images["right1"] = "http://www.mgtoronto.com/images/1957.jpg http://www.mgtoronto.com/images/1960.jpg http://www.mgtoronto.com/images/1962.jpg http://www.mgtoronto.com/images/1966-1.jpg http://www.mgtoronto.com/images/1965.jpg http://www.mgtoronto.com/images/1967.jpg http://www.mgtoronto.com/images/1973.jpg http://www.mgtoronto.com/images/1974-5.jpg http://www.mgtoronto.com/images/1961a.jpg http://www.mgtoronto.com/images/59mag.jpg http://www.mgtoronto.com/images/1961.jpg http://www.mgtoronto.com/images/midget1.jpg";

Images["right"] = "http://www.mgtoronto.com/images/rv8.jpg http://www.mgtoronto.com/images/metro.jpg http://www.mgtoronto.com/images/1995.jpg http://www.mgtoronto.com/images/tf135.jpg http://www.mgtoronto.com/images/wires.jpg http://www.mgtoronto.com/images/xpwr.jpg http://www.mgtoronto.com/images/mgtf135.jpg http://www.mgtoronto.com/images/mg3.jpg http://www.mgtoronto.com/images/mg6.jpg http://www.mgtoronto.com/images/1969c.jpg";

//
// 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();

