// don't change the order of the days
var catalogueImagesList = new Array(
                                     // 08:00 ... 12:59
                                     // 13:00 ... 07:59
                                     // Sunday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Monday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Tuesday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Wednesday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Thursday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Friday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ],
                                     // Saturday
                                     [ new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!"),
                                       new CatalogueImage("main-image-jun.jpg", "appliances", "Brand-new kitchen appliances for every chore!") ]
                                   );

var solosImagesList = new Array(
                                new SolosImage("main_image_1b_june.jpg", "comet"),
                                new SolosImage("main_image_2b_june.jpg", "ambiance"),
								new SolosImage("main_image_3b_june.jpg", "30_litre_black_microwave")
                               );

// ---- !DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! ---- //

// -----------------
// object prototypes
// -----------------
function CatalogueImage(imagePath, pagePath, imageAltText)
{
  this.src  = "../images/home_page_rotator/" + imagePath;
  this.href = pagePath + ".aspx";
  this.alt  = imageAltText;
}

function SolosImage(imagePath, pageName)
{
  this.src  = "../images/home_page_rotator/" + imagePath;
  this.href = "buyers_choice/" + pageName + ".aspx";
  this.alt  = pageName.replace(/_/g, " ");
}

// ---------
// variables
// ---------
var rotateLinkLeft,
    rotateImageLeft,
    rotateLinkRight,
    rotateImageRight;

// ---------
// functions
// ---------
function initCatalogueImages()
{
  if (catalogueImagesList.length == 0)
  {
    alert("initCatalogueImages: no images defined!");

    return;
  }

  rotateLinkLeft   = document.getElementById("rotateLinkLeft");
  rotateImageLeft  = document.getElementById("rotateImageLeft");
  rotateLinkRight  = document.getElementById("rotateLinkRight");
  rotateImageRight = document.getElementById("rotateImageRight");

  // fire it every minute
  setInterval("selectCatalogueImage()", 1000 * 60);

  selectCatalogueImage();
}

function selectCatalogueImage()
{
  var currentDate = new Date(),
      imageIndex;

  // 08:00 ... 12:59
  if (currentDate.getHours() >= 8 &&
      currentDate.getHours() <  13)
  {
    imageIndex = 0;
  }
  // 13:00 ... 07:59
  else
  {
    imageIndex = 1;
  }

  rotateLinkLeft.href = catalogueImagesList[currentDate.getDay()][imageIndex].href;  
  rotateImageLeft.src = catalogueImagesList[currentDate.getDay()][imageIndex].src;
  rotateImageLeft.alt = catalogueImagesList[currentDate.getDay()][imageIndex].alt;
}

function initSolosImages()
{
  if (solosImagesList.length == 0)
  {
    alert("initSolosImages: no images defined!");

    return;
  }

  var solosMap = document.getElementById("solosMap"),
      areaTag,
      firstSolosImage = new Image();

  firstSolosImage.src = solosImagesList[0].src;

  for (var i = 0; i < solosImagesList.length; i ++)
  {
    areaTag = document.createElement("area");

    areaTag.setAttribute("shape" , "circle");
    // x-centre of circle, y-centre of circle, radius
    areaTag.setAttribute("coords", (26 + (i * 24)) + "," + (firstSolosImage.height - 25) + ",11");
    areaTag.setAttribute("href"  , "javascript:showSolosImage(" + i + ")");

    solosMap.appendChild(areaTag);
  }

  // this is a fix for IE, because it sucks
  if (typeof document.all != "undefined" &&
      (navigator.userAgent.indexOf("MSIE") != -1 ||
       navigator.userAgent.indexOf("Internet Explorer") != -1))
  {
    areaTag = document.createElement("area");

    areaTag.setAttribute("id"    , "ieLinkBugfix");
    areaTag.setAttribute("shape" , "rect");
    areaTag.setAttribute("coords", "0,0," + firstSolosImage.width + "," + (firstSolosImage.height - 37));

    solosMap.appendChild(areaTag);
  }

  setInterval("showSolosImage(null)", 4000);

  showSolosImage(0);
}

//var solosTimerId = null;
var currentImageIndex;

function showSolosImage(imageIndex)
{
  if (imageIndex == null)
  {
    currentImageIndex += 1;
  }
  else
  {
    currentImageIndex = imageIndex;
  }

  if (currentImageIndex >= solosImagesList.length)
  {
    currentImageIndex = 0;
  }

  rotateLinkRight.href = solosImagesList[currentImageIndex].href;
  rotateImageRight.src = solosImagesList[currentImageIndex].src;
  rotateImageRight.alt = solosImagesList[currentImageIndex].alt;

  if (typeof document.all != "undefined" &&
      (navigator.userAgent.indexOf("MSIE") != -1 ||
       navigator.userAgent.indexOf("Internet Explorer") != -1))
  {
    var areaTag = document.getElementById("ieLinkBugfix");

    areaTag.href = rotateLinkRight.href;
  }

/*
  if (solosTimerId != null)
  {
    clearTimeout(solosTimerId);
  }

  solosTimerId = setTimeout("showSolosImage(null)", 10000);
*/
}

