
	function cImagesDialog( baseURL )
	{
		this.baseURL	= baseURL;
		this.currentID	= null;
		this.currentIDs	= null;
		
		$(document).keypress(function(e){ if(e.keyCode==27) imagesDialog.hideImage(); });
	}
	
	cImagesDialog.prototype.displayPrevious = function()
	{
		if ( ( this.currentIDs == null ) || ( this.currentID == null ) )
			return false;
		
		var prevID = this.getPrevious();
		if ( prevID == null )
			return false;
	
		return this.displayImageID ( prevID );
	}
	
	cImagesDialog.prototype.displayNext = function()
	{
		if ( ( this.currentIDs == null ) || ( this.currentID == null ) )
			return false;

		var nextID = this.getNext();
		if ( nextID == null )
			return false;
	
		return this.displayImageID ( nextID );
	}
	
	cImagesDialog.prototype.displayImageID = function ( id )
	{
		this.currentID = id;
		
		$("#popupContent img").attr('src',this.baseURL + id);
		$("#popupContent .previous a").toggle(this.getPrevious() != null);
		$("#popupContent .next a").toggle(this.getNext() != null);
	}
	
	cImagesDialog.prototype.getPrevious = function()
	{
		if ( this.currentIDs != null )
		{
			var prev = null;
			var i;

			for ( i = 0; i < this.currentIDs.length; i++ )
			{
				if ( this.currentIDs[i] == this.currentID )
					return prev;
			
				prev = this.currentIDs[i];
			}
		}
		
		return null;
	}
	
	cImagesDialog.prototype.getNext = function()
	{
		if ( this.currentIDs != null )
		{
			var i;
			
			for ( i = 0; i < this.currentIDs.length; i++ )
				if ( this.currentIDs[i] == this.currentID )
				{
					if ( i >= this.currentIDs.length - 1 )
						return null;
				
					return this.currentIDs[i+1];
				}
		}
		
		return null;
	}
	
	cImagesDialog.prototype.displayImage = function ( id, IDs )
	{
		if ( ( this.currentID == null ) && ( id != undefined ) && ( id != null ) )
		{
			this.currentID	= id;
			this.currentIDs = ( IDs == undefined ) ? null : IDs;
			
			var content = ''
				+ '<span class="previous"><a href="#" onclick="imagesDialog.displayPrevious(); return false;"></a></span>'
				+ ' <span class="image"><a href="#" onclick="imagesDialog.hideImage(); return false;"><img src="' + this.baseURL + id + '" alt="" title="" /></a></span>'
				+ ' <span class="next"><a href="#" onclick="imagesDialog.displayNext(); return false;"></a></span>';
			
			$("#popup").fadeIn("fast");
			$("#popupContent").html(content);
			
			this.displayImageID( id );
		}
	}
	
	cImagesDialog.prototype.hideImage = function()
	{  
		if ( this.currentID != null )
		{
			this.currentID	= null;
			this.currentIDs	= null;
			
			$("#popupContent").html('');
			$("#popup").hide();
		}
	}
	