
var gradualFader={}

gradualFader.baseopacity=1 //set base opacity when mouse isn't over element (decimal below 1)
gradualFader.increment=0.1 //amount of opacity to increase after each iteration (suggestion: 0.1 or 0.2)

document.write('<style type="text/css">\n') //write out CSS to enable opacity on "gradualfader" class
document.write('.fader{filter:progid:DXImageTransform.Microsoft.alpha(opacity='+gradualFader.baseopacity*100+'); -moz-opacity:'+gradualFader.baseopacity+'; opacity:'+gradualFader.baseopacity+';}\n')
document.write('</style>')

gradualFader.setopacity = function(obj, value) { //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
  var targetobject = obj
  if (targetobject && targetobject.filters && targetobject.filters[0]) { //IE syntax
    if (typeof targetobject.filters[0].opacity == "number") //IE6
      targetobject.filters[0].opacity = value * 100
    else //IE 5.5
      targetobject.style.filter = "alpha(opacity=" + value * 100 + ")"
  }
  else if (targetobject && typeof targetobject.style.MozOpacity != "undefined") //Old Mozilla syntax
    targetobject.style.MozOpacity = value
  else if (targetobject && typeof targetobject.style.opacity != "undefined") //Standard opacity syntax
    targetobject.style.opacity = value;
  targetobject.currentopacity = value;
}

gradualFader.fadeupdown=function(obj, direction){
	var targetobject=obj
	var fadeamount=(direction=="fadeup")? this.increment : -this.increment
	if (targetobject && (direction=="fadeup" && targetobject.currentopacity<1 || direction=="fadedown" && targetobject.currentopacity<=this.baseopacity && targetobject.currentopacity > 0)){
		this.setopacity(obj, targetobject.currentopacity+fadeamount)
		
		window.setTimeout(function(){gradualFader.fadeupdown(obj, direction)}, 20)
	}
}

gradualFader.fadeinterface=function(obj, direction){
		gradualFader.fadeupdown(obj, direction)
}

gradualFader.init=function(idname){
  // this.setopacity(document.getElementById('GalleryMainImage'), this.baseopacity)
  this.setopacity(document.getElementById(idname), this.baseopacity)
}
