/**
 * Popup that shows and caches external content, it's main purpose is show the text for quotes 
 * @param aOptions
 * @return void
 */
var QuotePopup =
{
		/**
		 * Cache for the externally loaded popup content
		 */
		oCache	: {},
		
		/**
		 * Open method
		 */
		open		:	function(aOptions)
		{
				aOptions.width = 400;
				
				aOptions.showConfirm = false;				
				
				// URL was loaded before and saved in oCache, don't load it again
				if(QuotePopup.oCache[aOptions.url])
				{					
					// Get the content based on the previously loaded URL
					aOptions.content = QuotePopup.oCache[aOptions.url];
					// Make sure the url won't be opened again if the content is empty
					aOptions.url = null;
					Popup.open(aOptions);
				}
				else
				{
					new Ajax.Request
					(
							aOptions.url,
							{
								onSuccess: function(oResponse, oJSON)
								{
																	
									if(oJSON.title)
									{
										aOptions.content = '<h2>' + oJSON.title + '</h2>' + oJSON.content;
									}
									else
									{
										aOptions.content = oJSON.content;
									}
									
									// Save the content based on the URL
									QuotePopup.oCache[aOptions.url] = aOptions.content ;
									// Make sure the url won't be opened again if the content is empty
									aOptions.url = null;		
									
									// Show content in the popup
									Popup.open(aOptions);
								},
								
								onFailure: function(oA, oResponse)
								{	
									aOptions.content = 'Ongeldige URL opgegeven';
								}
							}
					);	
				}
		}
};
