var currentScroller = null;

function Scroller ()
{
        this.mousedown = false;
};

Scroller.prototype.mousedown ;
Scroller.prototype.intervalID ;

Scroller.prototype.continousScrollLeft = function(control)
{
        this.acquire();
        currentScroller = this;
        this.scrollLeft(control);
        this.intervalID = setInterval("currentScroller.scrollLeft('"+control+"')",100);
};

Scroller.prototype.continousScrollRight = function(control)
{
        this.acquire();
        currentScroller = this;
        this.scrollRight(control);
        this.intervalID = setInterval("currentScroller.scrollRight('"+control+"')",100);
};

Scroller.prototype.scrollLeft = function(control)
{
                document.getElementById(control).scrollLeft -= 20;
};
Scroller.prototype.scrollRight= function(control)
{
                document.getElementById(control).scrollLeft += 20;
};

Scroller.prototype.acquire= function()
{
        this.mousedown = true;
        clearInterval(this.intervalID);
};

Scroller.prototype.release= function()
{
        this.mousedown = false;
        clearInterval(this.intervalID);
};

function changeClass (control,class_name)
{
	document.getElementById(control).className = class_name;
};
	Disolver.prototype.opacity;
	Disolver.prototype.opacity_increment;
	Disolver.prototype.delay;
	Disolver.prototype.divname;
	Disolver.prototype.object_name;
	Disolver.prototype.htimeout_callback;
	Disolver.prototype.htimeout_fade;

	function Disolver (object_name,opacity,opacity_increment,delay,divname)
	{
		this.opacity = opacity;
		this.opacity_increment = opacity_increment;
		this.delay = delay;
		this.divname = divname;
		this.object_name = object_name;
	};

	Disolver.prototype.adjustFraction = function (x)
	{
		x = Math.round( x / 0.1 ) * 0.1;
		return x;
	};

	Disolver.prototype.fadeIn = function (call_back)
	{
		if ( this.opacity >= 1 )
		{
			this.opacity = 1;
			var ie_opacity = this.opacity*100;
			document.getElementById(this.divname).style.opacity = this.opacity;
			document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
			document.getElementById(this.divname).style.visibility="visible";
			this.htimeout_callback = setTimeout (call_back,1);
		}
		else
		{
			this.opacity = this.opacity + this.opacity_increment;
			this.opacity = this.adjustFraction(this.opacity);
			if ( this.opacity > 1 ) this.opacity = 1;
			document.getElementById(this.divname).style.visibility="visible";
			document.getElementById(this.divname).style.opacity = this.opacity;
			var ie_opacity = this.opacity*100;
			document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
			this.htimeout_fade = setTimeout(this.object_name+".fadeIn(\""+call_back+"\")",this.delay);
		}
	};

	Disolver.prototype.fadeOut = function (call_back)
	{
		if ( this.opacity <= 0 )
		{
			this.opacity = 0;
			document.getElementById(this.divname).style.opacity = this.opacity;
			var ie_opacity = this.opacity*100;
			document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
			this.htimeout_callback = setTimeout (call_back,1);
			if ( this.opacity ==0 )  document.getElementById(this.divname).style.visibility="hidden";
		}
		else
		{
			this.opacity = this.opacity - this.opacity_increment;
			this.opacity = this.adjustFraction(this.opacity);
			if ( this.opacity < 0 ) this.opacity = 0;
			document.getElementById(this.divname).style.opacity = this.opacity;
			var ie_opacity = this.opacity*100;
			document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
			if ( this.opacity ==0 )  document.getElementById(this.divname).style.visibility="hidden";
			this.htimeout_fade = setTimeout(this.object_name+".fadeOut(\""+call_back+"\")",this.delay);
		}
	};

	Disolver.prototype.fadeOutImmediate = function ()
	{
		clearTimeout (this.htimeout_callback);
		clearTimeout (this.htimeout_fade);
		this.opacity = 0;
		document.getElementById(this.divname).style.opacity = this.opacity;
		var ie_opacity = this.opacity*100;
		document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
	};
	Disolver.prototype.fadeInImmediate = function ()
	{
		clearTimeout (this.htimeout_callback);
		clearTimeout (this.htimeout_fade);
		this.opacity = 1;
		document.getElementById(this.divname).style.opacity = this.opacity;
		var ie_opacity = this.opacity*100;
		document.getElementById(this.divname).style.filter = "alpha(opacity="+ie_opacity+")";
		
	};


	RotatingGallery.prototype.gallery_images;
	RotatingGallery.prototype.captions;
	RotatingGallery.prototype.gallery_image_id;
	RotatingGallery.prototype.caption_id;
	RotatingGallery.prototype.current_index;
	RotatingGallery.prototype.object_name;
	RotatingGallery.prototype.delay;
	RotatingGallery.prototype.started;


	function RotatingGallery (image_id,caption_id)
	{
		this.gallery_images = new Array ();
		this.captions = new Array ();	
		this.gallery_image_id = image_id;
		this.caption_id = caption_id;
		this.current_index = 0;
		this.started = false;
		this.object_name = "";
		this.delay = 0;
	};
	RotatingGallery.prototype.addItem = function (image,caption,image_src)
	{
		this.gallery_images.push(image);
		this.captions.push(caption);
		myImage = new Image();
		myImage.src = image;
	};
	RotatingGallery.prototype.rotateInternal = function (call_run)
	{
		if ( (!this.started && this.gallery_images.length > 0) ||  this.gallery_images.length > 1 )
		{
			document.getElementById(this.gallery_image_id).innerHTML = this.gallery_images[this.current_index];
			document.getElementById(this.caption_id).innerHTML = this.captions[this.current_index];
		}
		
		this.started = true;
		if ( this.gallery_images.length > 1 )
		{
			if ( this.current_index < this.gallery_images.length - 1 )
				this.current_index ++;
			else this.current_index = 0;
		}
		
		if ( call_run ) 
			disolver.fadeIn (this.object_name+".runInternal()");
		else disolver.fadeIn ('');
	};
	RotatingGallery.prototype.rotate = function (call_run)
	{
		if (call_run )
			disolver.fadeOut (this.object_name+".rotateInternal('"+call_run+"')");
		else this.rotateInternal(call_run);
	};
	RotatingGallery.prototype.runInternal = function ()
	{
		setTimeout(this.object_name+'.rotate(true);',this.delay);
	};

	RotatingGallery.prototype.run = function (object_name,delay)
	{
		this.object_name = object_name;
		this.delay = delay ;
		setTimeout(this.object_name+'.rotate(true);',this.delay);
	};

