// JavaScript Document
function slideshow(cfg) {

	function swap() {
		if (that.timer) window.clearTimeout(that.timer);
		that.img.src = that.images[that.index];
		// changeLinkHref("bannerLink", banners[index][1]);
		
		that.index = (++that.index > that.images.length-1) ? 0 : that.index;
		cue(that.images[that.index]);
	}

	function cue(url) {
		var cue = new Image();
		cue.src = url;
		that.timer = window.setTimeout(swap,that.delay);
	}
	
	this.id = cfg.id;
	this.delay = cfg.delay || 8000;
	this.images = cfg.images;
	this.img = document.getElementById(this.id);
	this.index = 1;
	var that = this;

	cue(this.images[this.index]);
	
	return this;
}


function findLinkByHref(href) {
  for (var i=0; i<document.links.length; i++) {
    if (document.links[i].href == href) return i;
  }
  return -1;
}

function changeLinkHref(id,newHref,oldHref) {
  if (document.links.length > 0) {
    if (document.getElementById) {
      document.getElementById(id).href = newHref;
    }
    else if (document.all) {
      document.all[id].href = newHref;
    }
    else {
      var index = findLinkByHref(oldHref);
      if (index > -1)
        document.links[index].href = newHref;
    }
  }
}