Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
	//alert('Searching for '+ value +' in ' + this);
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).

        if (this[i] == value) {
            return true;
        }
    }
    return false;
};

dw_Banner.restartDelay = 500; // delay onmouseout to restart rotation

dw_Banners = {}; // globally accessible reference to object 
function dw_Banner(id, delay, bMouse) {
    this.id = id; this.delay = delay; this.items = []; this.ctr = 0;this.oldctr = '-1'; 
	this.timer = null;
    dw_Banners[this.id] = this; this.animString = "dw_Banners." + this.id;
    if (bMouse) dw_Banner.setMouseEvents(this.id); // set up pause/resume onmouseover/out
};

dw_Banner.prototype.addItem = function(sHtml) {
 	this.items[this.items.length] = sHtml;
};

dw_Banner.prototype.rotate = function() {
    clearTimeout(this.timer); this.timer = null;
    var el = document.getElementById(this.id);
	//alert('Items:' + this.items.length);
    if ( el && typeof el.innerHTML != "undefined" ) {
		if(this.oldctr == '-1' || this.oldctr == 'undefined') {
			this.oldctr = this.ctr;
			var a_all_ctrs = new Array(1);
			a_all_ctrs[0] = this.oldctr;
		} else {
			this.oldctr = this.oldctr + "," + this.ctr
			var a_all_ctrs = this.oldctr.split( ',' );
		}
		//alert('this.items.length: ' + this.items.length);
		//alert('a_all_ctrs.length: ' + a_all_ctrs.length);
		if(this.items.length == a_all_ctrs.length) {
			this.oldctr = '-1';
			this.ctr = Math.floor(this.items.length*Math.random())
		} else {
			//alert('Old: ' + this.oldctr)

			do {
				this.ctr = Math.floor(this.items.length*Math.random())
				//alert('Generated: ' + this.ctr);
				//alert('Already: ' + a_all_ctrs.inArray(this.ctr));
			} while( a_all_ctrs.inArray(this.ctr) )
		}
		
		//alert('New: ' + this.ctr);
		//alert('array: ' + a_all_ctrs)
        el.innerHTML = this.items[this.ctr];
        //if (this.ctr < this.items.length-1) this.ctr++;
        //else this.ctr = 0;
        this.timer = setTimeout(this.animString + ".rotate()", this.delay);
    }
};

dw_Banner.setMouseEvents = function(id) {
    var el = document.getElementById(id);
    if (el) {
        el.onmouseover = dw_Banner.pause;
        el.onmouseout = dw_Banner.resume;
    }
};

// these 2 functions called onmouseover/out of banner el
dw_Banner.pause = function() { 
    var curObj = dw_Banners[this.id];
    if (curObj) { clearTimeout(curObj.timer); curObj.timer = null; }
};
 
dw_Banner.resume = function(e) {
    e = e? e: window.event;
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( this != toEl && !dw_contained(toEl, this) ) {
        var curObj = dw_Banners[this.id];
        if (curObj)
            curObj.timer = setTimeout(curObj.animString + ".rotate()", dw_Banner.restartDelay);
    }
};

// returns true of oNode is contained by oCont (container)
function dw_contained(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
    return false;
};

var imageHandler = { 
    path:"", imgs:[], preload:function() { for(var i=0;arguments[i];i++) {
    var img=new Image(); img.src=this.path+arguments[i]; this.imgs[this.imgs.length]=img;}}
};