// fade-image.js

var book_fader = new ImageFader('book_fader', 'images/book_cover.gif', 320, 340, 300);

// --------------------------------------------------------------------
// ImageFader constructor
// --------------------------------------------------------------------
function ImageFader(name, image_src, width, height, delay)
{
	// add members
	this.name = name;
	this.image = "img_" + name;
	this.delay = delay;
	this.ie4 = document.all && navigator.userAgent.indexOf("Opera") == -1;
	this.dom = document.getElementById && navigator.userAgent.indexOf("Opera") == -1;
	this.timer = "";
	this.opacity = 0;
	
	// add methods
	this.FadeIn = f_IF_FadeIn;
	this.Stop = f_IF_Stop;
	this.Restart = f_IF_Restart;

	// draw it
	if (this.ie4 || this.dom)
	{
		document.write('<img id="' + this.image + '" name="' + this.image 
			+ '" + src="' + image_src + '" + width=' + width + ' height=' + height 
			+ ' style="filter:alpha(opacity=0);-moz-opacity:0.0">');
	}
	else
	{
		document.write('<img name="imgImageFader" src="' + image_src + '">');
	}
	
	// kick it off
	if (this.dom || this.ie4)
		this.timer = setInterval(this.name + '.FadeIn()', this.delay);
}

function f_IF_Stop()
{
	if (this.timer != "")
	{
		clearInterval(this.timer);
		this.timer = "";
	}
}

function f_IF_Restart()
{
	if (this.dom || this.ie4)
	{
		this.Stop();
		this.opacity = -10;
		this.FadeIn();
		this.timer = setInterval(this.name + '.FadeIn()', this.delay);
	}
}

function f_IF_FadeIn()
{
	if (this.opacity < 100)
	{
		var img = this.dom ? document.getElementById(this.image) : eval("document.all." + this.image);

		this.opacity += 10;
		if (img.filters)
			img.filters.alpha.opacity = this.opacity;
		else if (img.style.MozOpacity)
			img.style.MozOpacity = this.opacity / 100;
	}
	else if (this.timer != "")
		this.Stop();
}
