/**
 * class	CS_Login
 * author	Paul Kruijt
 * date		16-05-2009
 */
var CS_Login = new Class({
	
 	/**
	 * initialize
	 * @return void
	 */
	initialize: function(root_node_id)
	{
		if (root_node_id)
		{
			// nodes
			this.root_node		= $(root_node_id);
			this.blocker_node	= $('page_blocker');
			
			// classes
			this.show_class				= 'show';
			this.hide_class				= 'hide';
			this.focus_class			= 'focus';
			this.input_wrapper_class	= 'cs_form_input';
			
			// settings
			this.start_effect_duration	= 500;
			this.end_effect_duration	= 500;
			this.start_position			= this.root_node.getStyle('top').toInt();
			this.end_position			= 40;
			this.login_focussed			= 0;
			
			// start rendering
			if (this.root_node)
			{
				this.start();
			}
		}
	},
	
	/**
	 * start
	 * @return	void
	 */
	start: function()
	{
		// set events
		this.setEvents();
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		// set vars
		var _this = this;
		var start_effect;
		var end_effect;
		
		// slider
		this.root_node.addEvents(
		{
			'mouseenter' : function()
			{
				if (_this.login_focussed == 0)
				{
					// pause end effect
					if (end_effect) end_effect.pause();
					
					// get top position
					var current_position = this.getStyle('top').toInt();
					
					// start effect
					start_effect = new Fx.Morph(_this.root_node, {duration: _this.start_effect_duration, transition: Fx.Transitions.Quad.easeOut});
					
			 		start_effect.start({'top' : [current_position, _this.end_position]});
				}
			},
			
			'mouseleave' : function()
			{
				if (_this.login_focussed == 0)
				{
					// pause start effect
					if (start_effect) start_effect.pause();
					
					// get top position
					var current_position = this.getStyle('top').toInt();
					
					// start effect
					end_effect = new Fx.Morph(_this.root_node, {duration: _this.end_effect_duration, transition: Fx.Transitions.Quad.easeOut});
					
			 		end_effect.start({'top' : [current_position, _this.start_position]});
				}
			}
		});
		
		// input events
		var input_wrappers			= this.root_node.getElements('.'+this.input_wrapper_class);
		var total_input_wrappers	= input_wrappers.length;
		
		if (total_input_wrappers > 0)
		{
			input_wrappers.each(function(input_wrapper)
			{
				var input_field	= input_wrapper.getElement('input');
				
				if (input_field)
				{
					input_field.addEvents(
					{
						'focus' : function()
						{
							this.set('class', _this.focus_class);
							this.value = '';
							
							_this.login_focussed = 1;
						},
						
						'blur' : function()
						{
							this.set('class', '');
							
							_this.login_focussed = 0;
						}
					});
				}
			});
		}
	}
	
});

	