var mbx_fontsizechanger = new Class(
/**
 *	@class
 *	@requires Mootools 1.2
 *	@description provides functionality to change em-based fontsize of a certain dom-element
 *	@lends mbx_fontsizechanger
 *	@property options {object} implements Mootools.Options
 *	@property m_currentSize {float} represents the current fontsize
 */
{
	
	Implements: [Options, Events],

	options: {
		'minSizeLimit' : null,
		'maxSizeLimit' : null,
		'stepping' : null,
		'saveUrl' : null,
		'buttonMinusSelector' : null,
		'buttonPlusSelector' : null,
		'containerSelector' : null,
		'onSave' : $empty
	},
	'm_currentSize' : null,
	
	/**
	 *	@constructs
	 *	@param {object} p_options
	 *	@param {function} p_hook
	 */
	initialize : function(p_options, p_hook)
	{
		this.setOptions(p_options);
		this.setCurrentSize($(this.options['containerSelector']).getStyle('font-size').toFloat());
		this.onChange = p_hook;
		
		//add the events
		this.addButtonEvents();
	}, 
	
	/**
	 *	getter for member m_currentSize
	 *	@return {float} m_currentSize
	 */
	getCurrentSize : function()
	{
		return this.m_currentSize;
	},
	
	/**
	 *	setter for member m_currentSize
	 *	@param {float} p_currentSize
	 */
	setCurrentSize : function(p_currentSize)
	{
		this.m_currentSize = p_currentSize;
	},
	
	/**
	 *	adds all neccessary events to the respective dom-elements
	 */
	addButtonEvents : function()
	{
		$(this.options['buttonMinusSelector']).addEvent('click', function(p_ev) {
			this.stopHtmlEvent(p_ev);
			this.onMinus_click();
		}.bind(this));
		
		$(this.options['buttonPlusSelector']).addEvent('click', function(p_ev) {
			this.stopHtmlEvent(p_ev);
			this.onPlus_click();
		}.bind(this));
	},
	
	/**
	 *	helper to stop basic events
	 *	@param {native.event} pev
	 *	@event
	 */
	stopHtmlEvent : function(p_ev)
	{
		new Event(p_ev).stop();
	},
	
	/**
	 *	eventhandler for click-event on "minus"-button
	 *	@event
	 */
	onMinus_click : function()
	{
		currentSize = this.getCurrentSize();
		
		if(currentSize - this.options['stepping'] >= this.options['minSizeLimit'])
		{
			currentSize -= this.options['stepping'];
			this.setCurrentSize(currentSize);
			$(this.options['containerSelector']).setStyle('font-size', currentSize + 'em');
		}
		
		this.save()
	},

	/**
	 *	eventhandler for click-event on "plus"-button
	 *	@event
	 */
	onPlus_click : function()
	{
		currentSize = this.getCurrentSize();
		
		if(currentSize + this.options['stepping'] <= this.options['maxSizeLimit'])
		{
			currentSize += this.options['stepping'];
			this.setCurrentSize(currentSize);
			$(this.options['containerSelector']).setStyle('font-size', currentSize + 'em');
		}
		
		this.save()
	},
	
	/**
	 *	saves the current fontsiize via xml-request so it is still available after reload
	 */
	save : function()
	{
		//hook: fire custom event
		this.fireEvent('onSave');
		
		new Request({
			'url' : this.options['saveUrl'],
			'method' : 'get'
		}).send('fontsize=' + this.getCurrentSize().round(2));
	}
});
