/**
 * class	CS_AjaxSelect
 * author	Paul Kruijt
 */
var CS_AjaxSelect = new Class({
	
	/**
	 * initialize
	 * @param	string	root_node_id
	 * @param	string	handler_id
	 * @param	string	listener_id
	 * @param	string	http_url
	 * @param	unknown	listener_value
	 * @param	unknown	handler_value
	 * @return	void
	 */
	initialize: function(root_node_id, handler_id, listener_id, http_url, listener_value, handler_value)
	{
		// nodes
		this.root_node		= $(root_node_id);
		this.handler_node	= $(handler_id);
		this.listener_node	= $(listener_id);
		
		// strings
		this.http_url		= http_url;
		this.listener_value	= listener_value;
		this.handler_value	= handler_value;
		
		// start ajax select
		this.start();
	},
	
	/**
	 * start
	 * @return	void
	 */
	start: function()
	{
		if (this.root_node && this.handler_node && this.listener_node)
		{
			// set events
			this.setEvents();
		}
		
		// get data when default value exists
		if (this.listener_value)
		{
			this.getData(this.listener_value, this.handler_value);
		}
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		// set vars
		var _this				= this;
		var handler_select_node	= this.handler_node.getElement('select');
		
		if (handler_select_node)
		{
			handler_select_node.removeEvents();
			handler_select_node.addEvents(
			{
				'change' : function()
				{
					// get data
					_this.getData(this.value);
					
					return false;
				}	
			});
		}
	},
	
	/**
	 * get data
	 * @param	unknown	listener_value
	 * @param	unknown	handler_value
	 * @return	void
	 */
	getData: function(listener_value, handler_value)
	{
		var _this = this;
		
		// make request
		var http_request = new Request.HTML({
			url			: this.http_url,
			update		: this.listener_node,
			onRequest	: function()
			{
				
			},
			onComplete	: function()
			{
				// set complete events
				_this.setCompleteEvents();
			}
		});
		
		http_request.get({'listener_value' : listener_value, 'handler_value' : handler_value});
	},
	
	/**
	 * set complete events
	 * @return	void
	 */
	setCompleteEvents: function()
	{
		// leave empty.
		// if you want a complete events call, please extend this class and create this method in the extended class.
	}
});
