
function Gallery(displayId, linkClass, preloadClass)
{
		this.imgIndex = 0;
		this.display = displayId;
		this.links = $(linkClass).get();
		this.imgNumber = this.links.length;
		this.slideShow = null;
		
		if(preloadClass)
			$(preloadClass).css({display: "none"});
		
		this.showImg = function(_index, fade)
		{
			if(!_index)
				index = this.imgIndex;
			else
				index = _index;
			
			var link = this.links[index];
			
			if($("#displayImg"))
			{
					$("#displayImg").remove();
			}
			$("<img id='displayImg' class='fade' src='" + link.href + "'/>").appendTo(this.display);
			$("#displayImg").css(
				{
					position: "absolute",
					top: $(this.display).offset().top + 1,
					left: $(this.display).offset().left + 2,
					zIndex: "0"
				}
			);
			if(fade)
				$(".fade").css({display: "none"}).fadeIn(1000);
		}
		
		this.setIndex = function(index)
		{
			this.imgIndex = index;
		}
		
		this.showNext = function(fade)
		{
			this.imgIndex = ++this.imgIndex % this.imgNumber;
			this.showImg(null, fade);
		}
		
		this.showPrev = function(fade)
		{
			this.imgIndex = --this.imgIndex;
			if(this.imgIndex < 0) this.imgIndex = this.imgNumber - 1;
			this.showImg(null, fade);
		}
		
		this.load = function(path)
		{
			var fileName = this.links[this.imgIndex].href.split("/").pop();
			var top = $(this.display).offset().top + ($(this.display).height() / 2);
			var left = $(this.display).offset().left + ($(this.display).width() / 2);
			
			$("<img id='indicator' src='script/img/indicator_medium.gif' alt='ajax indicator'/>").css(
				{
					position: "absolute",
					top: top,
					left: left
				}
			).appendTo(this.display);
			return $("<div id='loadReturn'></div>").load(path + "fileData.php?filename=" + fileName, function()
				{
					$("#indicator").remove();
				}
			);
		}
		
		this.createStatusBar = function(content, height)
		{
			h = height
			if(!height) h = 20
			/* Creazione della statusBar */
			$("<div id='statusBar'></div>").appendTo(this.display)
			$("#statusBar").append(content);
			$("#statusBar").css(
				{
					position: "absolute",
					top: $(this.display).offset().top + 1,
					left: $(this.display).offset().left + 1,
					zIndex: "1",
					width: $(this.display).width() - 2,
					display: "none",
					height: h,
					border: "1px solid",
					background: "#000000",
					color: "#FFFFFF",
					fontSize: "10px",
					opacity: "0.50"
				}
			).slideDown(800);
		}
		
		this.destroyStatusBar = function()
		{
			$("#statusBar").slideUp(800, 
			function()
				{
					$("#statusBar").remove();
				}
			);
		}
		
		this.start = function(_obj)
		{
			obj = _obj;
			
			obj.destroyStatusBar();
			obj.showNext(true);
			setTimeout("obj.createStatusBar(obj.load('imgs/'))", 5000);
			this.slideShow = setTimeout("obj.start(obj)", 5000);
		}
		
		this.stop = function()
		{
			clearTimeout(this.slideShow);
		}
}
