/**
 * class	QAIC_PopupDownloads
 * author	Paul Kruijt
 */
var QAIC_PopupDownloads = new Class(
{
	// extend core popup class
	Extends: QAIC_Popup,
	
 	/**
	 * constructor
	 * @return void
	 */
	initialize: function()
	{
		// call parents constructor
		this.parent();
		
		// id's
		this.filter_id	= 'qaic_filter_alt';
		this.popup_id	= 'qaic_popup_alt';
		this.content_id	= 'qaic_popup_content_alt';
		this.loader_id	= 'qaic_popup_loader_alt';
		this.confirm_id	= 'qaic_popup_filter_selection_confirm';
		
		// classes
		this.class_item		= 'qaic_popup_filter_selection_item';
		this.class_disabled	= 'qaic_disabled';
		this.class_close	= 'close';
		this.class_show		= 'show';
		this.class_hide		= 'hide';
		this.class_active	= 'active';
		
		// settings
		this.active_item_node	= null;
		
		// paths
		this.loader_img_path	= '../img/qaic_loader.gif';
	},
	
	/**
	 * set content events
	 * @return void
	 */
	setContentEvents: function()
	{
		// set item events
		this.setItemEvents();
		
		// set confirm event
		this.setConfirmEvent();
		
		// create scrollbar
		getScrollbar('qaic_popup_downloads');
	},
	
	/**
	 * set item events
	 * @return void
	 */
	setItemEvents: function()
	{
		// set vars
		var _this = this;
		
		if (this.content_node)
		{
			var item_nodes			= this.content_node.getElements('.'+this.class_item);
			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)
					{
						item_handler_node.removeEvents();
						item_handler_node.addEvents(
						{
							'click'	: function()
							{
								if (this != _this.active_item_node)
								{
									// de-activate node
									if (_this.active_item_node) _this.active_item_node.set('class', '');
									
									// set active node
									this.set('class', _this.class_active);
									_this.active_item_node = this;
									
									var confirm_node = $(_this.confirm_id);
									
									if (confirm_node)
									{
										var button_confirm_node = confirm_node.getElement('a');
										
										if (button_confirm_node)
										{
											var button_confirm_class = button_confirm_node.get('class');
											
											if (button_confirm_class == _this.class_disabled) button_confirm_node.set('class', '');
										}
									}
								}
								
								return false;
							}
						});
					}
				});
			}
		}
	},
	
	/**
	 * set confirm event
	 * @return void
	 */
	setConfirmEvent: function()
	{
		// set vars
		var _this = this;
		
		if (this.content_node)
		{
			var confirm_node = $(this.confirm_id);
			
			if (confirm_node)
			{
				var button_confirm_node = confirm_node.getElement('a');
				
				if (button_confirm_node)
				{
					button_confirm_node.removeEvents();
					button_confirm_node.addEvents(
					{
						'click'	: function()
						{
							var button_confirm_class = this.get('class');
							
							if (button_confirm_class != _this.class_disabled)
							{
								// call download zip script
								window.open(this.href);
								
								_this.remove();
							}
							
							return false;
						}
					});
				}
			}
		}
	}
});
