var HOMEPG_ADS = "/files/2860350/ads/homepage/";

var HPA_IMG_DLY = 1000;
var HPA_GRP_DLY = 2500;

var hpaGrpIdx;
var hpaImgIdx;
var hpaDelay;

var hpaGrp = new Array();

function createHomePageAds(){
   hpaGrp[0] = new Object();
   
   hpaGrp[0].title = "Click here to shop for Lullaby Music";
   hpaGrp[0].link = "/lullaby-cds";

   hpaGrp[0].imgSet = new Array();
   hpaGrp[0].imgSet[0] = new Image();
   hpaGrp[0].imgSet[0].src = HOMEPG_ADS + "LullabyMusic_fr1.gif";
   hpaGrp[0].imgSet[1] = new Image();
   hpaGrp[0].imgSet[1].src = HOMEPG_ADS + "LullabyMusic_fr2.gif";

   hpaGrp[1] = new Object();

   hpaGrp[1].title = "Click here to shop for Children's Books";
   hpaGrp[1].link = "/books";

   hpaGrp[1].imgSet = new Array();
   hpaGrp[1].imgSet[0] = new Image();
   hpaGrp[1].imgSet[0].src = HOMEPG_ADS + "BoardBooks_fr1.gif";
   hpaGrp[1].imgSet[1] = new Image();
   hpaGrp[1].imgSet[1].src = HOMEPG_ADS + "BoardBooks_fr2.gif";
   hpaGrp[1].imgSet[2] = new Image();
   hpaGrp[1].imgSet[2].src = HOMEPG_ADS + "BoardBooks_fr3.gif";

   hpaGrp[2] = new Object();

   hpaGrp[2].title = "Click here to shop for Fleece Blankets";
   hpaGrp[2].link = "/blankets";

   hpaGrp[2].imgSet = new Array();
   hpaGrp[2].imgSet[0] = new Image();
   hpaGrp[2].imgSet[0].src = HOMEPG_ADS + "Blankets_fr1.gif";
   hpaGrp[2].imgSet[1] = new Image();
   hpaGrp[2].imgSet[1].src = HOMEPG_ADS + "Blankets_fr2.gif";
   hpaGrp[2].imgSet[2] = new Image();
   hpaGrp[2].imgSet[2].src = HOMEPG_ADS + "Blankets_fr3.gif";

   hpaGrpIdx = 0;
   hpaImgIdx = 0;
   hpaDelay = HPA_IMG_DLY;
}

function hpaDelayTimer() {
   setTimeout('showNextHPAImage()', hpaDelay);
}

function getHPAImgSet() {
   return hpaGrp[hpaGrpIdx].imgSet;
}

function showNextHPAImage() {
   var anchor = document.getElementById('AdLink');
   var viewer = document.getElementById('ImgViewer');
   var imgSet = getHPAImgSet();

   hpaImgIdx = ++hpaImgIdx % imgSet.length;

   hpaDelay = HPA_IMG_DLY;

   if( hpaImgIdx == 0 ) {
      // Switch to next group ...
      hpaGrpIdx = ++hpaGrpIdx % hpaGrp.length;

      anchor.href = hpaGrp[hpaGrpIdx].link;
      viewer.title = hpaGrp[hpaGrpIdx].title;

      imgSet = getHPAImgSet();
 
      if( imgSet.length == 1 ) {
         // New group only has a single image ...
         hpaDelay = HPA_GRP_DLY;
      }
      //alert("Crossfade: Grp: "+hpaGrpIdx+"  Img: "+hpaImgIdx+"  Delay: "+hpaDelay);

      IWD_crossfade(viewer, imgSet[hpaImgIdx].src, '1', '', 'hpaDelayTimer');
   }
   else {
      if( hpaImgIdx == (imgSet.length - 1) ) {
         // Last image of group ...
         hpaDelay = HPA_GRP_DLY;
      }
      //alert("Overlay:  Grp: "+hpaGrpIdx+"  Img: "+hpaImgIdx+"  Delay: "+hpaDelay);

      IWD_overlay(viewer, imgSet[hpaImgIdx].src, '1', '', 'hpaDelayTimer');
   }
}

function initHomePageAds() {
   createHomePageAds();
   hpaDelayTimer();
}

if (window.addEventListener) {
	window.addEventListener("load",initHomePageAds,false);
} else if (window.attachEvent) {
	window.attachEvent("onload",initHomePageAds);
} else {
	window.onload = function() {initHomePageAds();}
}
