/**
 * class	SparkleAlert
 * author	Jeffrey van der Veen
 */
var SparkleAlert = new Class({
	
	/**
	 * initialize
	 * @return	void
	 */
	initialize: function()
	{
		// nodes
		this.document_node	= document.getElement('body');
		this.overlay_node	= $('overlay');
		this.alert_node		= $('alert');
		this.content_node	= $('alert_content');
		
		// settings
		this.hide_time_out	= 5000;
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		var _this	= this;
		
		this.overlay_node.removeEvents();
		this.overlay_node.addEvents(
		{
			'click' : function()
			{
				_this.hide();
				
				return false;
			}	
		});
	},
	
	/**
	 * dimensions
	 * @return	void
	 */
	dimensions: function()
	{
		this.width	= this.content_node.getWidth() + 16;
		this.height	= this.content_node.getHeight() + 28;
		
		this.alert_node.setStyle('width', this.width + 'px');
		this.alert_node.setStyle('height', this.height + 'px');
			
		// set position
		this.position();
	},
	
	/**
	 * position
	 * @return	void
	 */
	position: function()
	{
		var margin_left	= Math.floor(this.width / 2).toInt();
		var margin_top	= Math.floor(this.height / 2).toInt();
		
		this.alert_node.setStyle('margin-left', '-'+margin_left+'px');
		this.alert_node.setStyle('margin-top', '-'+margin_top+'px');
	},
	
	/**
	 * set content
	 * @return	void
	 */
	setContent: function()
	{
		this.content_node.set({html: this.content});
	},
	
	/**
	 * show
	 * @param	string	content
	 * @param	integer	alert_time_out
	 * @return	void
	 */
	show: function(content, alert_time_out, redirect)
	{
		// set vars
		var _this		= this;		
		this.content	= content;
		
		if (this.overlay_node && this.alert_node)
		{
			// set events
			this.setEvents();
			
			// load content
			this.setContent();
			
			// show
			this.overlay_node.setStyle('display', 'block');
			this.alert_node.setStyle('display', 'block');
			
			// set dimensions
			this.dimensions();
			
			var hide_time_out = alert_time_out ? alert_time_out : _this.hide_time_out;
			
			var hide_timer = setTimeout(
			function ()
			{
				_this.hide();
				
				if (redirect)
				{
					document.location = redirect;
				}
			}
			, hide_time_out
			);
		}
	},
	
	/**
	 * hide
	 * @return	void
	 */
	hide: function()
	{
		if (this.overlay_node && this.alert_node)
		{
			// hide
			this.overlay_node.setStyle('display', 'none');
			this.alert_node.setStyle('display', 'none');
		}
	}
});
