//****************************
//** FROM: somewhere. Seen these functions elsewhere too many times to properly credit
//***************************
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function addEvent(obj,evType,fn){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,false);
	}
	else if(obj.attachEvent){
		var r=obj.attachEvent("on"+evType,fn);
	}
	else{
		if ( typeof( obj['on'+evType] ) == 'function' ) {
			var last = obj['on'+evType] ;
			obj['on'+evType] = null;
			obj['on'+evType] = function() { last(); fn(); };
		}
		else obj['on'+evType] = fn;
	}
}


function getObj(name) {
  if (document.getElementById) {
  	this.obj = document.getElementById(name);
		if(this.obj) 
			this.style = document.getElementById(name).style;
  }
  else if (document.all) {
		this.obj = document.all[name];
		if(this.obj)
			this.style = document.all[name].style;
  }
  else if (document.layers) {
   	this.obj = document.layers[name];
		if(this.obj)
	   	this.style = document.layers[name];
  }
	return this.obj; //secondary functionality returns reference to obj
}

function ImgRotator (objId,speed)
{
	this.objId = objId; // VARIABLE SHOULD BE NAMED THIS AS WELL
	this.obj = getObj(objId);
	this.speed = speed;
	this.ImgSrc = new Object();
	this.ImgAlt = new Object();
	this.ImgLnk = new Object();
	this.Cache = new Object();
	this.curIndex =  0;
	this.count = 0;
	this.started = false;
	this.paused = false;
	this.preloaded = false;
	if (this.obj) {
		var a = this.obj.parentNode;
		if (a.tagName == 'A') { this.addImage(this.obj.src,this.obj.alt,a.href); this.curIndex++; a.style.display = 'block'; }
		this.obj.onmouseover = function() { eval(this.id).paused = true; }
		this.obj.onmouseout = function() { eval(this.id).paused = false; }
	}
}

var IR = ImgRotator.prototype;

IR.addImage = function(source,alt,lnk) { this.ImgSrc[this.count] = source; this.ImgLnk[this.count] = lnk; this.ImgAlt[this.count++] = alt; }
IR.preloadImages = function() { for(i=0;i < this.count;i++) { this.Cache[i] = new Image(); this.Cache[i].src = this.ImgSrc[i]; } this.preloaded = true; }
IR.beginSlideShow = function() { if (!this.obj || this.count <=1) return; if(!this.preloaded) this.preloadImages(); this.obj.onload = function() { this.started = true; setTimeout("eval("+this.id+").showImage()",eval(this.id).speed); } }
IR.showImage = function () { 
	if ( this.paused ) { setTimeout("eval("+this.objId+").showImage()",this.speed); return; }
	if (this.obj.parentNode){
		var a = this.obj.parentNode;
		a.style.background = 'url('+this.obj.src+') no-repeat top';
		if ( a.tagName == 'A') a.href=this.ImgLnk[this.curIndex];
	}
	this.obj.title = this.ImgAlt[this.curIndex];
	this.obj.alt = this.ImgAlt[this.curIndex];
	this.obj.src = this.Cache[this.curIndex].src;
	this.curIndex++; this.curIndex %= this.count;
	
	fadeIn(this.objId,0);
	if (!this.preloaded) { // fetch the next image when preloading has
		imgy = new Image();
		imgy.src = this.ImgSrc[this.curIndex];
	}
}