/**
 * class	CS_Tabs
 * author	Paul Kruijt
 */
var CS_Tabs = new Class({
	
	/**
	 * initialize
	 * @param	string	root_node_id
	 * @param	string	content_wrapper_id
	 * @param	boolean	use_http_request
	 * @return	void
	 */
	initialize: function(root_node_id, content_wrapper_id, use_http_request)
	{
		// nodes
		this.root_node				= $(root_node_id);
		this.content_wrapper_node	= $(content_wrapper_id);
		this.active_item_node		= null;
		
		// classes
		this.class_active	= 'active';
		
		// settings
		this.use_http_request	= !use_http_request ? 0 : 1;
	},
	
	/**
	 * start
	 * @return void
	 */
	start: function()
	{
		// set vars
		var _this	= this;
		
		if (this.root_node && this.content_wrapper_node)
		{
			// loop through all items and set event
			var item_nodes			= this.root_node.getElements('li');
			var total_item_nodes	= item_nodes.length;
			
			if (total_item_nodes > 0)
			{
				item_nodes.each(function(item_node, index)
				{
					var item_handler_node	= item_node.getElement('a');
					
					if (item_handler_node)
					{
						// set active item
						var item_class	= item_handler_node.get('class');
						
						if (item_class == _this.class_active && !_this.active_item_node)
						{
							_this.active_item_node = item_handler_node;
							
							// use http request to show content
							if (_this.use_http_request == 1)
							{
								var url_location = item_handler_node.get('href');
								_this.loadContent(url_location);
							}
							
							// toggle content with styles
							else
							{
								_this.toggleContent();
							}
						}
						
						// set event
						_this.setHandlerEvent(item_handler_node);
					}
				});
			}
		}
	},
		
	/**
	 * set handler event
	 * @param	object	handler_node
	 * @return	void
	 */
	setHandlerEvent: function(handler_node)
	{
		// set vars
		var _this	= this;
		
		if (handler_node)
		{
			// add events
			handler_node.removeEvents();
			handler_node.addEvents(
			{
				'click' : function()
				{
					// disable current active item
					if (_this.active_item_node) _this.active_item_node.set('class', '');
					
					// set active tab
					this.set('class' , _this.class_active);
					
					_this.active_item_node = this;
					
					// use http request to show content
					if (_this.use_http_request == 1)
					{
						var url_location = this.get('href');
						_this.loadContent(url_location);
					}
					
					// toggle content with styles
					else
					{
						_this.toggleContent();
					}
					
					return false;
				}
			});
		}
	},
	
	/**
	 * load content with http request
	 * @param	string	url_location
	 * @return	void
	 */
	loadContent: function(url_location)
	{
		if (url_location)
		{
			// make request
			var http_request = new Request.HTML(
			{
				url		: url_location,
				update	: this.content_wrapper_node
			});
			
			http_request.get();
		}
	},
	
	/**
	 * toggle content by setting styles
	 * @return	void
	 */
	toggleContent: function()
	{
		// THIS NEEDES TO BE BUILD!!!
	}
	
});