/*-------------------------------------------------------------------
imageRotator by Jordan Windebank (jordan@windebank.net.au)
http://sandbox.windebank.com.au/imageRotator
***************
     Usage
***************
For each new image required, add another 'oImg' object with
the following syntax: 
  image:'images/1.jpg',     // Relative reference to image
  img: '',                  // Must remain blank
  link:'#',                 // URL link
  alt: 'Sunset - tearoom',  // Alt attribute for image
  target: '_self'           // Target - either '_self' or '_blank'
Modify the myTimer variable to contain the rate of rotation in 
Milliseconds.
Include the following two elements in your HTML file referring to 
the image and link elements to be used by imageRotate. An anchor 
element with an ID of 'irLink' and an image element with the ID of
'irImg'.
The images used in this example are randomly used from flickr 
(www.flickr.com) and all rights are reserved by their appropriate 
creators.
---------------------------------------------------------------------*/
var oImg = [
  {
    image:'images/LazyOwl-revised.jpg',
    img: '',
    link:'/images/LazyOwl-revised.jpg',
    target: '_self'
  },
  {
    image:'images/Pub-Trivia-New1.jpg',
    img: '',
    link:'/images/Pub-Trivia-New2.jpg',
    target: '_self'
  },
   {
    image:'images/cupboards.jpg',
    img: '',
    link:'http://ursu.uregina.ca/images/cupboards2.jpg',
    target: '_self'
  },
  {
    image:'images/foodboxursusmall.jpg',
    img: '',
    link: '/images/foodboxursusmall.jpg',
    target: '_self'
  }
  
];
var loaded = false;
var myTimer = 9000;
var step = 0;
function preLoad()
{
  for (var i = 0; i < oImg.length; i++)
  {
    oImg[i].img = new Image();
	  oImg[i].img.src = oImg[i].image;
  }
  loaded = true;
}
function imageRotate()
{
  var link = document.getElementById('irLink');
  var image = document.getElementById('irImg');
  if (!loaded)
  {
    preLoad();
  }
  
  if (step >= oImg.length)
  {
    step = 0;
  }
  link.href = oImg[step].link;
  link.target = oImg[step].target;
  image.src = oImg[step].img.src;
  image.alt = oImg[step].alt;
  step++;
  setTimeout('imageRotate()', myTimer);
}
window.onload = imageRotate;

