var mbx_autogallery_tmgs = new Class(
/**
 *	@class
 *  @augments mbx_autogallery
 *	@requires Mootools 1.2
 *	@description extends mbx_autogallery
 *	@lends mbx_autogallery_tmgs
 *	@property {object} options implements Mootools.Options
 */
{
	Extends: mbx_autogallery,

	options: {
		'tyTopic' : null,
		'delay' : null,
		'dataUrl' : null,
		'galleryImgSelector' : null,
		'effectFadeDuration' : null
	},
	
	/**
	 *	@constructs
	 *	@param {object} p_options 
	 *  @augments mbx_autogallery
	 */
	initialize : function(p_options)
	{
		this.parent(p_options);
	},

	/**
	 *	prepares the data and sets up the respective dom-element
	 *  @augments mbx_autogallery
	 *	@return {bool}
	 */
	prepareData : function()
	{
		//get all the data into the html
		var galleryItems = this.getData();

		if(galleryItems[0] == 'true')
		{
			return false;
		}
		
		var container = $(this.options['galleryImgSelector']).getParent('div');
		container.empty();
		
		var tmpOpacity = 0;
		var galleryItem = '';
		var galleryLink = '';
		var galleryCaption = '';
		for(i in galleryItems)
		{
			galleryItem = galleryItems[i].imageId;
			galleryLink = galleryItems[i].detailLink;
			galleryCaption = galleryItems[i].caption;
			
			if($type(galleryItem) == 'string')
			{
				tmpOpacity = 0;
				if(i == 0)
				{
					tmpOpacity = 1;
				}

				var galleryItem = galleryItem;
				
				var aEl = new Element('a', {
					'id' : this.options['galleryImgSelector'] + '_' + i,
					'href' : galleryLink,
					'class' : 'pagegallery_link'
				}).setStyles({'opacity' : tmpOpacity, 'position' : 'absolute', 'z-index' : 0});
				
				container.adopt(
					aEl.adopt(
						new Element('span', {
							'class' : 'pagegallery_caption',
							'html': galleryCaption
						})
					)
				);
				container.adopt(
					aEl.adopt(
						new Element('img', {
							'src' : '/tycon/pic.php?imgid=' + galleryItem + '&width=675&height=325&resizemode=fill',
							'title' : galleryCaption,
							'alt' : galleryCaption
						})
					)
				);
			}	
		}
		
		return true;
	},
	
	/**
	 *	updates the gallery-specific dom-elements
	 *  @augments mbx_autogallery
	 *	@param {int} p_oldIndex
	 */
	updateImage : function(p_oldIndex)
	{
		var newIndex = this.getCurrentIndex();
		var data = this.getData();
		
		//fade out old image
		new Fx.Tween($(this.options['galleryImgSelector'] + '_' + p_oldIndex), {'duration' : this.options['effectFadeDuration']}).start('opacity', 1, 0);
		
		//fade in current image
		new Fx.Tween($(this.options['galleryImgSelector'] + '_' + newIndex), {'duration' : this.options['effectFadeDuration']}).start('opacity', 0, 1);
	}
});