/**
 * class	TopMenu
 * author	Marco Troost
 */
var TopMenu = new Class({

	/**
	 * initialize
	 * @return	void
	 */
	initialize: function(root_node_id)
	{
		// nodes
		this.root_node				= $(root_node_id);
		this.text_container			= $('header_text');

		// classes
		this.hide_class				= 'hide';

		// strings
		this.item_prefix			= 'item_';
		this.text_prefix			= 'text_item_';
	},

	/**
	 * start
	 * @return void
	 */
	start: function()
	{
		if (this.root_node)
		{
			// set events
			this.setEvents();
		}
	},

	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		// set vars
		var _this = this;

		// get anchors
		var anchor_nodes		= this.root_node.getElements('a');
		var total_anchor_nodes	= anchor_nodes.length;
		if (total_anchor_nodes)
		{
			anchor_nodes.each(function(anchor_node, index)
			{
				anchor_node.removeEvents();
				anchor_node.addEvents(
				{
					'click' : function()
					{
						var item_id 	= this.get('id');
						_this.setInActive();
				
						this.set('class', 'active');

						_this.showText(item_id);
						return false;
					}
				});
			});
		}
	},



	/**
	 * Show text
	 * @return	void
	 */
	showText: function(item_id)
	{
		var _this 		= this;
		if (item_id)
		{
			// first hide all text blocks
			_this.hideText();

			// show selected text block
			var text_item = $('text_'+item_id);
			if (text_item)
			{
				text_item.toggleClass('hide');

				_this.closeButton(item_id);
			}
		}
	},

	/**
	 * Set inactive item
	 * @return	void
	 */
	setInActive: function()
	{
		var _this 		= this;

		// first hide all text blocks
		// get anchors
		var anchor_nodes		= this.root_node.getElements('a');
		var total_anchor_nodes	= anchor_nodes.length;
		if (total_anchor_nodes)
		{
			anchor_nodes.each(function(anchor_node, index)
			{
				class_name = anchor_node.get('class');
				if (class_name == 'active')
				{
					anchor_node.toggleClass('active');
				}
			});
		}
	},

	/**
	 * Set inactive item
	 * @return	void
	 */
	closeButton: function(item_id)
	{
		var _this 		= this;

		var close_btn_node	= $('close_'+item_id);

		if (close_btn_node)
		{
			close_btn_node.addEvent('click',function()
			{
				_this.hideText();
				_this.setInActive();
			});
		}
	},


	/**
	 * Hide Text
	 * @return	void
	 */
	hideText: function()
	{
		var _this 		= this;

		// hide all text blocks
		var text_items			= this.text_container.getElements('div');
		var total_text_items	= text_items.length;
		if (total_text_items)
		{
			text_items.each(function(text_item, index)
			{
				item_class = text_item.get('class');
				if (item_class == '')
				{
					text_item.toggleClass('hide');
				}
			});
		}
	}

});


