var timer = 3;

var photos = [
    ['secufone',  'Secufone',             'products_secufone.jsp'],
    ['batrak',    'BATrak',               'products_batrak.jsp'],
    ['twig',      'TWIG Discovery',       'products_twig.jsp'],
    ['portman',   'PORTMAN<br>GT-2000',   'products_portman.jsp'],
    ['hp6915',    'HP 6915',              'products_hp6915.jsp'],
    ['ocellus',   'QinetiQ Ocellus S100', 'products_ocellus.jsp'],
    ['tripleton', 'Tripleton GT100G',     'products_tripleton.jsp'],
    ['identicom', 'Identicom',            'products_identicom.jsp'],
    ['bb8800',    'Blackberry 8800',      'products_bb8800.jsp']
];

var img, count = 1, imgWidth = 105, imgHeight = 105;

function startSlideshow()
{
  img = document.getElementById('photo');
  
  count = Math.round(Math.random() * (photos.length-1));
  
  cueNextSlide();
}

function cueNextSlide()
{
  var next = new Image;

  next.onerror = function()
  {
    //alert('Failed to load next image');
  };

  next.onload = function()
  {
    img.src = next.src;
    img.alt = photos[count][1];
	
    var productlink = document.getElementById('productlink');
    productlink.href = "dev/" + photos[count][2];

    var productnamediv = document.getElementById('productname');
    productnamediv.innerHTML = photos[count][1];

    img.width = imgWidth;
    img.height = imgHeight;

    if (++count == photos.length) { count = 0; }

    window.setTimeout('cueNextSlide()', timer * 1000);
  };

  next.src = 'images/productshow/' + photos[count][0] + '.png';
}

addLoadListener(startSlideshow);

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
