
// this code is for the header image fader and so must be included on every page
//var imgf = new image_fader();
//imgf.img_array = new Array('header_image_01.jpg', 'header_image_02.jpg', 'header_image_03.jpg', 'header_image_04.jpg', 'header_image_05.jpg', 'header_image_06.jpg');
//imgf.img1 = 'dh-topimg1';
//imgf.img2 = 'dh-topimg2';
//imgf.img_folder = 'user_resources/Image/image_faders/home/';
//imgf.obj = 'imgf';

function image_fader()
{

	this.thisimg = 0;	// the image counter
	this.img_array = new Array();
	this.href_array = null;
	this.href_tag;
	this.img1;	// img1 and img2 are used to fade in and fade out the images
	this.img2;
	this.img_folder;
	this.duration = 4.0;
	this.timeout = 9000;
	this.obj;
	this.t;

	// internal variables that track the function of img1 and img2 (either fading in or out)
	this.fadein;
	this.fadeout;

	this.init_fades = function(cat)
	{
		if(cat != undefined){
			this.thisimg = cat-1;
		}
		this.fadein = this.img1;
		this.fadeout = this.img2;
		this.obj = this.obj + '.dofades()';
		this.dofades();
	};
	
	this.dofades = function()
	{
		this.thisimg++;
		if(this.thisimg >= this.img_array.length)
			this.thisimg = 0;

		$(this.fadein).src = this.img_folder + this.img_array[this.thisimg];
		Effect.Appear(this.fadein, {duration:this.duration});
		Effect.Fade(this.fadeout, {duration:this.duration });
		if(this.href_array != null)
			$(this.href_tag).href = href_array[this.thisimg];
		var tmp = this.fadeout;
		this.fadeout = this.fadein;
		this.fadein = tmp;
		this.t = setTimeout(this.obj, 9000);
	};

	this.stopFade = function()
	{
		if(this.t)
			clearTimeout(this.t);
	};

}