function RegisterEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
  return true;
};

// This owns all category image objects
function TCategoryImages() {
  this.CategoryImages = new Array();
}

TCategoryImages.prototype.Init = function(il) {
  var img = new TCategoryImage();
  img.il = il;
  img.el = document.getElementById('CardImages');
  img.Init();
  this.CategoryImages[this.CategoryImages.length] =  img;
} 
 
// This is a category image object, this is the object that displays an image
function TCategoryImage() {
  this.il = false;
  this.el = false;
  this.delay = 3000;
  this.timer = false;
  this.visible = false;
}

TCategoryImage.prototype.Init = function() {
  var self = this;

  this.el.innerHTML = this.il.getImage();  
  
  this.StartTimer();
}

TCategoryImage.prototype.StartTimer = function() {
  var self = this;

  this.timer = window.setTimeout(function() { self.Cycle() }, this.delay);
}

TCategoryImage.prototype.Cycle = function() {
  this.el.innerHTML = this.il.getImage();  
  this.StartTimer();
}


// This is a list of available images for a category image object
function TCategoryImageList() {
  this.imageArray = new Array();
  this.urlArray = new Array();
  this.captionArray = new Array();
  this.current = 0;
  this.mode = 0;
}

// Adds an image
TCategoryImageList.prototype.addImage = function(imgPath, url, caption) {
  this.imageArray[this.imageArray.length] = imgPath;
  this.urlArray[this.urlArray.length] = url;
  this.captionArray[this.captionArray.length] = caption;
}

// returns an image.  mode 0 is cyclical and mode 1 is random
TCategoryImageList.prototype.getImage = function() {
  var s = '<a href="' + this.urlArray[this.current] + '"><img src="' + this.imageArray[this.current] + '" alt="' + this.captionArray[this.current] + '" title="' + this.captionArray[this.current] + '" /></a>';

  this.current++;
  if (this.current >= this.imageArray.length) {
    this.current = 0;
  }
  return s;
}

var allCats = new TCategoryImages();
var allCatImages = new TCategoryImageList();

allCatImages.addImage('/images/cards/WDC133.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-M-8554-EA3X-KN.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-M-8637-H67R-KG.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-A-7011-W03B-DC-KS.jpg', '/', '');
allCatImages.addImage('/images/cards/XFFI71116-145.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-M-8389-C64R-LG-KG.jpg', '/', '');
allCatImages.addImage('/images/cards/DCP116.jpg', '/', '');
allCatImages.addImage('/images/cards/XBNX75331-13.jpg', '/', '');
allCatImages.addImage('/images/cards/XPNX73848-12.jpg', '/', '');
allCatImages.addImage('/images/cards/WDC130.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-N-7934-W13W-KG.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-X-5099-N50R-KG.jpg', '/', '');
allCatImages.addImage('/images/cards/B2-F-3118-W25R-KG.jpg', '/', '');

function onBodyInit() {  
  allCats.Init(allCatImages);  
}

RegisterEvent(window, 'load', onBodyInit, true);       

