var My;
if ( !My ) My = {};

My.Garpunkt_Gallery = Class.create();

//My.Garpunkt_Gallery.galleryCounter = 0;

My.Garpunkt_Gallery.prototype =
{
	initialize: function( id, opts ) 
	{
		this.options = 
		{
			actResourceId:		null
		}
		
		Object.extend(this.options, opts || {});
		
		this.element = $(id);
		this.lastResourceId = 0;
		this.oldContent = new Element( 'div', { id: 'galleryContent_' + this.lastResourceId, style: 'position: absolute;' } ).setOpacity( 0 );
		this.element.update( this.oldContent );
		
		if ( this.options.actResourceId != null )
		{
			this.showReosurce( this.options.actResourceId );
		}
	},
	
	showReosurce: function ( resourceId )
	{
		if ( this.lastResourceId != resourceId )
		{
			if ( this.runningEffect != null && !Object.isUndefined( this.runningEffect ) )
			{
				this.runningEffect.cancel();
				this.oldContent.remove();
				this.oldContent = this.newContent;
				this.runningEffect = null;
			}
			
			this.lastResourceId = resourceId;
			
			this.newContent = new Element( 'div', { id: 'galleryContent_' + resourceId, style: 'position: absolute;' } ).setOpacity( 0 ).update( $('galleryItemBigCode' + resourceId).innerHTML );
			this.element.insert( { 'top': this.newContent } );
			

			this.runningEffect = new Effect.Parallel( [
						new Effect.Fade( this.oldContent, { 
							from: 1.0,
							to: 0.0,
							sync: true
						} ),
						new Effect.Appear( this.newContent, { 
							from: 0.0,
							to: 1.0,
							sync: true
						} )
					], { 
						duration: 0.5,
						afterFinish: function ()
							{
								this.oldContent.remove();
								this.oldContent = this.newContent;
								this.runningEffect = null;
							}.bind(this)
				} );
		}
	}
};