//<script language="JavaScript">
//	KLIXO GALLERY JAVASCRIPT - by Daniel Wonacott
//	(c)2008 Klixo Ltd 2008. Some rights reserved:
//	Free for use by Klixo customers. All other use restricted, 
//	contact support@klixo.co.nz for details

// Purpose:
//		To fade an image in when it loads
// Instructions:	
//		Create a global variable on the onload for the gallery object passing the ID of
//		the image and the period for each transition in milliseconds e.g.
//
//		var gallery;
//		function BodyOnload() {
//		  gallery = new kxGallery("GalleryImageID", 25); }
//
//		Add onclick events as required calling the show function of the object passing
//		the URL of the image to show in the gallery e.g.
//
//		<p onclick="gallery.Show("pics/closeup.jpg");">Show close up</p>
//
//		That's it.

function kxGallery(img, period)
{
	this.GalleryImg = document.getElementById(img);
	this.Opacity = 0;
	this.Period = period;
	this.OpacityTimer = null;
	var me = this;
	
	this.Stop = function()
	{
		if (me.GalleryImg != null)
		{
			me.GalleryImg.onload = null;
			if (me.OpacityTimer != null) 
				clearInterval(me.OpacityTimer);
		}
	}
	
	this.SetOpacity = function()
	{
		var i = me.GalleryImg;
		if (i.filters && i.filters[0]) 
		{
			if (typeof i.filters[0].opacity == "number")
				i.filters[0].opacity = me.Opacity * 100;
			else
				i.style.filter = "alpha(opacity=" + (me.Opacity * 100) + ")";
		}
		else if (typeof i.style.MozOpacity != "undefined")
		{
			i.style.MozOpacity = me.Opacity;
		}
		else if (typeof i.style.opacity != "undefined")
		{
			i.style.opacity = me.Opacity;
		}
		else
		{
			me.Stop();
		}
	}	
	
	this.Timer = function()
	{
		me.Opacity += 0.1;
		me.SetOpacity();
		if (me.Opacity >= 1)
			me.Stop();
	}

	// Load the image, start fading in
	this.Show = function(img)
	{
		me.Stop();
		me.GalleryImg.style.visibility = "hidden";//display = "none";
		me.GalleryImg.onload = function() {
			me.Opacity = 0.1;
			me.SetOpacity();
			me.GalleryImg.style.visibility = "visible";//display = "block";
			me.OpacityTimer = setInterval(me.Timer, me.Period);
		}
		me.GalleryImg.src = img;
	}
}

