/**
 * This object handles retrieval of an all images associated with a particular entity.
 * The images are retrieved asynchronously and inserted into the DOM
 * as a child of: updateParentElement
 */
var MultipleImageDownLoader = {
	/**
	 * Class construtor
	 */
	load: function(urlString, updateParentElement) {
		this.attachLoadingImage(updateParentElement);
		new Ajax.Request(
			urlString, 
			{
  				onSuccess:function(transport) {
					MultipleImageDownLoader.detachLoadingImage();
					MultipleImageDownLoader.processResult(updateParentElement, transport.responseText);
				}
			}
		);
	},
	// insert the image into the DOM
	processResult: function(updateElement, jsonResult) {

		var jsonObj = jsonResult.evalJSON();
		var srcString = '/includes/skin/default/front_images/no-offer.jpg';
		if (jsonObj.got_image == true) {
			$A(jsonObj.image_list).each(function( elem ){
				srcString = '/client/uploads/images/'+elem.file_name;
				var thumbnail = new Element('img', {
					'src': srcString,
					'alt': elem.alt_text,
					'id': elem.file_name
				});
				$(updateElement).appendChild(thumbnail);
			});
		}
	},
	// insert the loading image into the DOM
	attachLoadingImage: function(parentElement) {
		
		var ajaxLoader = new Element('img', {
			'src': '/includes/skin/default/front_images/ajax-front-loader.gif',
			'alt': 'Loading...',
			'id': 'ajax_loader'
			
		});
		
		$( parentElement ).appendChild( ajaxLoader );
	},
	// remove the loading image from the DOM
	detachLoadingImage: function() {
		$('ajax_loader').remove();
	}
}
