/**
 * W_ShowPopup Class
 * @author Marco Troost
 */
var W_ShowPopup = new Class({
	
	/**
	 * initialize
	 * @param	string	overlay_node_id
	 * @param	string	popup_node_id
	 * @return	void
	 */
	initialize: function(root_node_id, overlay_node_id, popup_node_id)
	{
		// id's
		this.overlay_node_id	= overlay_node_id;
		this.popup_node_id		= popup_node_id;
		this.root_node_id		= root_node_id;		

		this.root_node			= $(this.root_node_id);	
		this.popup_node			= $(this.popup_node_id);	
		this.overlay_node		= $(this.overlay_node_id);
		this.close_button_node	= $('close_popup_button');
		
		// strings
		this.object_prefix		= 'object_';
		this.search_for_prefix	= 'search_for_';

	},
	
	/**
	 * start
	 * @return	void
	 */
	start: function()
	{        
		if (this.root_node_id)
		{            
			this.setEvents();
		}
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		// set var as object
		var _this	= this;
		
		// get anchors
		var anchor_nodes		= this.root_node.getElements('.show_details 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 object_id 	= this.get('class');
						var search_for 	= this.get('name');
						object_id		= object_id.replace(_this.object_prefix, '');
						search_for 		= search_for.replace(_this.search_for_prefix, '');
						_this.loadPopup(object_id, search_for);
						return false;
					}
				});
			});
		}
	},
	
	
	/**
	 * load popup
	 * @return	void
	 */
	loadPopup: function(object_id, search_for, save_stats)
	{
		// set vars
		var _this = this;
		var save_stats	= !save_stats ? 0 : save_stats;
		var content_url = '/http/popup_search_detail.php?search_for='+search_for+'&object_id='+object_id+'&s='+save_stats;
		
		// make request
		var http_request = new Request.HTML({
			url			: content_url,
			update		: this.popup_node,
			onComplete	: function() {
				_this.closePopup();
			}
		});
		http_request.get();

		this.overlay_node.setStyle('display', 'block');
		this.popup_node.setStyle('display', 'block');
		
		if (Browser.Engine.trident4) // IE6
		{
			$('text_container').getElements('select').setStyle('display', 'none');	
		}
		return false;
	},
	
	/**
	 * close popup
	 * @return	void
	 */
	closePopup: function()
	{
		// set vars
		var _this = this;

		$('close_popup_button').addEvent('click',function()
		{
			$('popup_content').innerHTML = '';
			$('overlay').setStyle('display', 'none');
			$('popup_content').setStyle('display', 'none');
			
			if (Browser.Engine.trident4) // IE6
			{
				$('text_container').getElements('select').setStyle('display', 'block');	
			}				
			return false;
		});
	}	

});
