var mbx_autogallery = new Class(
/**
 *	@class
 *	@requires Mootools 1.2
 *	@description provides a gallery that slides its elements periodical
 *	@lends mbx_autogallery
 *	@property options {object} implements Mootools.Options
 *	@property {array} m_data holds gallerydata
 *	@property {int} m_currentIndex represents current index in m_data
 *	@property {int} m_itemCount holds count of m_data
 */
{
								
	Implements : Options,

	options: {
		'tyTopic' : null,
		'delay' : null,
		'dataUrl' : null,
		'galleryImgSelector' : null
	},
	'm_data' : null,
	'm_currentIndex' : null,
	'm_itemCount' : null,

	/**
	 *	@constructs
	 *	@param {object} p_options 
	 */
	initialize : function(p_options)
	{
		if(p_options['tyTopic'])
		{
			this.setOptions(p_options);
			this.start();	//and run()
			this.setCurrentIndex(0);
		}
	},

	/**
	 *	getter for member m_currentIndex
	 *	@return {int} m_currentIndex
	 */
	getCurrentIndex : function()
	{
		return this.m_currentIndex;
	},
	
	/**
	 *	setter for member m_currentIndex
	 *	@param {int} p_index
	 */
	setCurrentIndex : function(p_index)
	{
		this.m_currentIndex = p_index;
	},

	/**
	 *	getter for member m_data
	 *	@return {array} m_data
	 */
	getData : function()
	{
		return this.m_data;
	},

	/**
	 *	setter for member m_data
	 *	@param {array} m_data
	 */
	setData : function(p_data)
	{
		this.m_data = p_data;
	},
	
	/**
	 *	getter for member m_itemCount
	 *	@return {int} m_itemCount
	 */
	getItemCount : function()
	{
		return this.m_itemCount;
	},
	
	/**
	 *	setter for member m_itemCount
	 *	@param {int} m_itemCount
	 */
	setItemCount : function(p_ItemCount)
	{
		this.m_itemCount = p_ItemCount;
	},
	
	/**
	 *	loads the gallerydata via xml-request, sets up required member-variables, prepares the data and starts the periodical execution
	 */
	start : function()
	{
		//load data
		request = new Request({
			'url' : this.options['dataUrl'],
			'method' : 'get'
		});
		
		request.addEvent('success', function(p_data) {
			//get the data and prepare it
			var tmpData = p_data.split(',');
			var data = [];
			
			tmpData.each(function(ai)
			{
				var tmpDataDetails = ai.split('###');
				
				data.extend([{
					'imageId' : tmpDataDetails[0],
					'detailLink' : tmpDataDetails[1],
					'caption' : tmpDataDetails[2]
				}]);
			});
			
			this.setData(data);
			this.setItemCount(data.length);
			if(this.prepareData())
			{
				//run
				this.run.periodical(this.options['delay'], this);
			}
		}.bind(this));
		
		request.send('tyTopic=' + this.options['tyTopic'] + '&mode=autogallery');
	},
	
	/**
	 *	prepares the data - not implemented here
	 *	@return {bool}
	 */
	prepareData : function()
	{
		//not implemented here
	},
	
	/**
	 *	runs periodical and sets the new current index
	 */
	run : function()
	{
		var currentIndex = this.getCurrentIndex();

		if((this.getCurrentIndex() + 1) < this.getItemCount())
		{
			this.setCurrentIndex(currentIndex + 1);
		}
		else
		{
			this.setCurrentIndex(0);
		}

		this.updateImage(currentIndex);
	},
	
	/**
	 *	updates the gallery-specific dom-elements - not implemented here
	 *	@param {int} p_oldIndex
	 */
	updateImage : function(p_oldIndex)
	{
		//not implemented here
	}
});