var Gallery = 
{
	
	slideTime : 5000
	,
	transitionTime  : 1000
	,
	imgWidth  : 0
	,
	imgHeight : 0
	,
	         // src, href, SKU, width, height, copyright
	slides : [ ]
	,
	photographer : ""
	,
	currentSlide : 0
	,
	screenID : "Gallery"
	,
	format : "generic"
	,
	nextText : "Next"
	,
	faderHandle : setTimeout("void(0);", 1)
	,
	galleryHandle : setTimeout("void(0);", 1)
	,
	opacity : 100
	,
	aryNumbers : [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]
	,
	start : function ()
	{
		this.preload();
	}
	,
	start2 : function ()
	{
		this.run();
	}
	,
	run : function ()
	{
		clearTimeout(this.faderHandle);
		clearTimeout(this.galleryHandle);
		this.galleryHandle = setTimeout(this.screenID + '.running();', this.slideTime + this.transitionTime);
	}
	,
	running : function()
	{
		this.fadeNext();
		this.galleryHandle = setTimeout(this.screenID + '.running();', this.slideTime + this.transitionTime);
	}
	,
	preload : function ()
	{
		var imgPreloads = new Array();
		var i;
		for (i = 0; i < this.slides.length; i++) {
			imgPreloads[i] = new Image();
			imgPreloads[i].src = this.slides[i][0];
		}
		if (i > 0) imgPreloads[(i - 1)].onLoad = this.start2();
	}
	,

	getNext : function ()
	{
		this.currentSlide++;
		if (this.currentSlide >= this.slides.length) this.currentSlide = 0;
	}
	,
	getPrev : function ()
	{
		this.currentSlide--;
		if (this.currentSlide < 0) this.currentSlide = this.slides.length;
	}
	,

	loadSlide : function()
	{
		var imgObj = document.getElementById(this.screenID + "_img");
		var linkObj = document.getElementById(this.screenID + "_link");
		imgObj.src = this.slides[this.currentSlide][0];

		linkObj.href = this.slides[this.currentSlide][1];	

	} 

	,
	fadeNext : function()
	{
		clearTimeout(this.faderHandle);
		this.faderHandle = setTimeout(this.screenID + '.fadeNext_out();', 50);
	}
	,
		fadeNext_out : function()
		{
			var imgObj = document.getElementById(this.screenID + "_img");
			if (this.opacity > 0) {
				this.setOpacity(imgObj, this.opacity - 5);
				this.faderHandle = setTimeout(this.screenID + '.fadeNext_out();', (this.transitionTime/50) );
			} else {
				this.setOpacity(imgObj, 0);
				this.fadeNext_switch();
			}
		}
	,
		fadeNext_switch : function()
		{
			this.getNext();
			this.loadSlide();
			
			this.faderHandle = setTimeout(this.screenID + '.fadeNext_in();', (this.transitionTime/50) );
		}
	,
		fadeNext_in : function()
		{
			var imgObj = document.getElementById(this.screenID + "_img");
			if (this.opacity < 99) {
				this.setOpacity(imgObj, this.opacity + 5);
				this.faderHandle = setTimeout(this.screenID + '.fadeNext_in();', (this.transitionTime/50) );
			} else {
				this.setOpacity(imgObj, 100);
			}
		}
	,
	setOpacity : function(myObj, myOpacity)
	{ // set opacity of the element
		// Fix for math error in some browsers
		myOpacity = (myOpacity >= 100)? 99.999: myOpacity;
		myOpacity = (myOpacity < 0)? 0: myOpacity;
		// IE/Windows
		myObj.style.filter = "alpha(opacity: " + myOpacity + ")";
		// Safari < 1.2, Konqueror
		myObj.style.KHTMLOpacity = myOpacity/100;	
		// Older Mozilla and Firefox
		myObj.style.MozOpacity = myOpacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		myObj.style.opacity = myOpacity/100;
		
		this.opacity = myOpacity;
	}
	
}
