function divFader(id) {
	
	this.id = id;
	
	window["slider"+id] = this;
	
	//if (divFader.slideshow && divFader.numDivs > 1) {
	//	divFader.init();
	//}
}


divFader.prototype.slideshow = true;
divFader.prototype.slideshowTimeout = 5000; // milliseconds
divFader.prototype.slideshowInitDelay = false;
divFader.prototype.divPrefix = "slideshowdiv";
divFader.prototype.buttonPrefix = "slideshowbutton";
divFader.prototype.currentDivId = "1";
divFader.prototype.parentButtonDiv = "slideshownavi";
divFader.prototype.numDivs = 0;
divFader.prototype.buttonOnClass = "on";
divFader.prototype.buttonLinkVar = "ssid";

divFader.prototype.previousDivId = "";
divFader.prototype.lastTimeoutId = "";
divFader.prototype.slideshowTimeoutId = "";
divFader.prototype.slideshowFirstTimeout = false;

divFader.prototype.youtubeVideo = "";

divFader.prototype.preFunc = "";


divFader.prototype.onClickHandlers = function() {

	 var naviDiv = document.getElementById(this.parentButtonDiv); 
	 var buttonLinkVar = this.buttonLinkVar;
	 var tmpobj = this;

	 if (naviDiv) {

		 for (var i = 0;i < naviDiv.childNodes.length; i++) {

			if (naviDiv.childNodes[i].tagName == 'a' || naviDiv.childNodes[i].tagName == 'A') {
				
				naviDiv.childNodes[i].onclick = function () {
					var naviMatch = buttonLinkVar + "=([0-9]{1,})";
					// alert(naviMatch);
					var naviRE = new RegExp(naviMatch);
					var result = this.href.match(naviRE);
					if (result != null) {
						return tmpobj.fadeButton(result[1]);
					}
					else {
						return true;
					}
				}
			}
		}
	}
}

divFader.prototype.vidOnClickHandlers = function() {

	 var vib = document.getElementById(this.buttonPrefix + "0");

	 if (vib) {
	 
	 	var tmpobj = this;

		vib.onclick = function () {
		
			//document.getElementById("docimage0").innerHTML = 'hello';
			
			success = tmpobj.fadeButton(0);
			
			if (!success) {
				document.getElementById(tmpobj.divPrefix + "vid").style.display = "block";
				document.getElementById(tmpobj.divPrefix + "vid").innerHTML = '<object width="320" height="240"><param name="movie" value="' + tmpobj.youtubeVid + '&autoplay=true"></param><embed src="' + tmpobj.youtubeVid + '&autoplay=true" type="application/x-shockwave-flash" width="320" height="240"></embed></object>';
			}
			
			return success;
		}
	}
}

divFader.prototype.init = function() {

	if (this.buttonLinkVar && this.buttonLinkVar.length > 0) {

		this.onClickHandlers();
		
		if (this.youtubeVid && this.youtubeVid != "") {
			
			if (this.preFunc == "") {
				this.preFunc = "clearVid";
			}
			
			this.vidOnClickHandlers();
		}
	}
	
	if (this.slideshow == true) {

		if (this.slideshowFirstTimeout) {
			initTimeout = this.slideshowFirstTimeout;
		}
		else if (this.slideshowInitDelay) {
			initTimeout = this.slideshowTimeout + this.slideshowInitDelay;
		}
		else {
			initTimeout = this.slideshowTimeout;
		}
		this.slideshowTimeoutId = window.setTimeout("window.slider"+this.id+".doSlideshow()", initTimeout);
	}
}

divFader.prototype.doSlideshow = function() {
	
	var nextDivId = Number(this.currentDivId) + 1;
	// alert(this.currentDivId);
	if (nextDivId > this.numDivs) {
		nextDivId = 1;
	}
	
	//alert(divFade_divPrefix + nextDivId);
	if (this.currentDivId != nextDivId) {
		this.fade(String(nextDivId));
	}
	
	this.slideshowTimeoutId = window.setTimeout("window.slider"+this.id+".doSlideshow()", this.slideshowTimeout);
}

divFader.prototype.fadeOnClick = function(switchDiv) {
	
	if (this.slideshow) {
		this.slideshow == false;
		if (this.slideshowTimeoutId != "") { window.clearTimeout(this.slideshowTimeoutId); }
	}
	
	return this.fade(switchDiv);
}

divFader.prototype.fadeButton = function(switchDiv) {

	if (this.preFunc && this.preFunc.length) {
		eval('this.' + this.preFunc + '()');
	}
	
	if (this.slideshow == true) {
		this.slideshow == false;
		if (this.slideshowTimeoutId != "") { window.clearTimeout(this.slideshowTimeoutId); }
	}
	
	return this.fade(switchDiv);
}

divFader.prototype.fade = function(switchDiv) {
	
	// make sure any current fade is completed
	if (this.lastTimeoutId != "") { window.clearTimeout(this.lastTimeoutId); }
	divFader.setOpacity(document.getElementById(this.divPrefix + this.currentDivId), 100);
	if (this.previousDivId != "") { divFader.setZIndex(document.getElementById(this.divPrefix + this.previousDivId), 1); }
	
	// set prev div
	this.previousDivId = this.currentDivId;
	
	
	// set incoming div as current
	if (this.currentDivId != switchDiv) {
		this.currentDivId = switchDiv;
		divFader.setOpacity(document.getElementById(this.divPrefix + this.currentDivId), 0);
	
	// set z-index
		divFader.setZIndex(document.getElementById(this.divPrefix + this.currentDivId), 50);
		divFader.setZIndex(document.getElementById(this.divPrefix + this.previousDivId), 2);
		
		this.crossFade(this.divPrefix + this.currentDivId,0);
		this.switchButtonState();
	}
	
	return false;
}

divFader.setOpacity = function(obj, opacity) {

	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity="+opacity+")";
	
	//alert(obj.style.filter);
	
	// 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;
}

divFader.setZIndex = function(obj, idx) {
	
	obj.style.zIndex = idx;
}

divFader.prototype.crossFade = function(inObjId,inOpacity) {
	if (document.getElementById) {
		obj = document.getElementById(inObjId);
		if (inOpacity <= 100) {
			divFader.setOpacity(obj, inOpacity);
			inOpacity += 10;
			this.lastTimeoutId = window.setTimeout("window.slider"+this.id+".crossFade('"+inObjId+"',"+inOpacity+")", 100);
		}
	}
}

divFader.prototype.switchButtonState = function() {

	var naviDiv = document.getElementById(this.parentButtonDiv);
	
	if (naviDiv) {
		for (var i = 0;i < naviDiv.childNodes.length; i++) {
		
			if (naviDiv.childNodes[i].tagName == 'a' || naviDiv.childNodes[i].tagName == 'A') {
				naviDiv.childNodes[i].className = '';
			}
			else if (naviDiv.childNodes[i].childNodes.length) {
				
				for (var j = 0;j < naviDiv.childNodes[i].childNodes.length; j++) {
					if (naviDiv.childNodes[i].childNodes[j].tagName == 'a' || naviDiv.childNodes[i].childNodes[j].tagName == 'A') {
						naviDiv.childNodes[i].childNodes[j].className = '';
					}
					else if (naviDiv.childNodes[i].childNodes[j].childNodes.length) {
						
						for (var k = 0;k < naviDiv.childNodes[i].childNodes[j].childNodes.length; k++) {
							if (naviDiv.childNodes[i].childNodes[j].childNodes[k].tagName == 'a' || naviDiv.childNodes[i].childNodes[j].childNodes[k].tagName == 'A') {
								naviDiv.childNodes[i].childNodes[j].childNodes[k].className = '';
							}
						}
					}
				}
			}
		}
	
		document.getElementById(this.buttonPrefix + this.currentDivId).className = this.buttonOnClass;
	}
}

divFader.prototype.clearVid = function() {
	document.getElementById(this.divPrefix + "vid").style.display = "none";
	document.getElementById(this.divPrefix + "vid").innerHTML = '&nbsp;';
					
}


// divFader.onClickHandlers();

//if (divFade_slideshow && divFade_numDivs > 1) {
//if (divFader.slideshow && divFader.numDivs > 1) {
//	alert('loo');
//	divFader.init();
//	alert('car');
//}