
var gradualFader={
	baseopacity: 0.6, //set base opacity when mouse isn't over element (decimal below 1)
	increment: 0.1, //amount of opacity to increase after each iteration (suggestion: 0.1 or 0.2)
	setopacity: function(obj, value){ //Sets the opacity of obj based on the passed in value setting (0 to 1 and in between)
		if (obj && obj.filters && obj.filters[0]){ //IE syntax
			if (typeof obj.filters[0].opacity=="number") //IE6
				obj.filters[0].opacity=value*100
			else //IE 5.5
				obj.style.filter="alpha(opacity="+value*100+")"
			}
		else if (obj && typeof obj.style.MozOpacity!="undefined") //Old Mozilla syntax
			obj.style.MozOpacity=value
		else if (obj && typeof obj.style.opacity!="undefined") //Standard opacity syntax
			obj.style.opacity=value
		obj.currentopacity=value
	},
	fadeupdown: function(obj, direction){
		var fadeamount = (direction=="fadeup")? this.increment : -this.increment
		if (obj && (direction=="fadeup" && obj.currentopacity<1 || direction=="fadedown" && obj.currentopacity>this.baseopacity)){
			this.setopacity(obj, obj.currentopacity+fadeamount)
			window["opacityfader"+obj._fadeorder]=setTimeout(function(){gradualFader.fadeupdown(obj, direction)}, 50)
		}
	},
	clearTimer: function(obj){
		if (typeof window["opacityfader"+obj._fadeorder]!="undefined")
			clearTimeout(window["opacityfader"+obj._fadeorder])
	},
	isContained: function(m, e){
		var e=window.event || e
		var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
		while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
		if (c==m)
			return true
		else
			return false
	},
	fadeinterface: function(obj, e, direction){
		if (!this.isContained(obj, e)){
			this.clearTimer(obj);
			this.fadeupdown(obj, direction);
		}
	},
	collectElementbyClass: function(classname){ //Returns an array containing DIVs with specified classname
		var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i"); //regular expression to screen for classname within element
		var pieces=[];
		var alltags=document.all? document.all : document.getElementsByTagName("*")
		for (var i=0; i<alltags.length; i++){
			if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
				pieces[pieces.length]=alltags[i];
		}
		return pieces;
	},
	init: function(){
		document.write('<style type="text/css">\n'); //write out CSS to enable opacity on "gradualfader" class
		document.write('.gradualfader{filter:progid:DXImageTransform.Microsoft.alpha(opacity='+this.baseopacity*100+'); -moz-opacity:'+this.baseopacity+'; opacity:'+this.baseopacity+';}\n');
		document.write('</style>');
		var objs = this.collectElementbyClass("gradualfader");
		for (var i=0; i < objs.length; i++){
			objs[i]._fadeorder = i;
			this.setopacity(objs[i], this.baseopacity);
			objs[i].onmouseover = function(e){gradualFader.fadeinterface(this, e, "fadeup");}
			objs[i].onmouseout = function(e){gradualFader.fadeinterface(this, e, "fadedown");}
		}
	}
}

