/**
 * Fotolia select image form scripts
 *
 * @copyright (c) 2004-2008, SWsoft
 */
var FotoliaSelectImageFormLoader = Class.create();
FotoliaSelectImageFormLoader.prototype = {

	/**
	 * Object constructor
	 *
	 * @access public
	 * @return void
	 */
	initialize: function() {
		var loader = this;
		self.parent.fotoliaSelectImageFormObject.resetEventsListeners();
		self.parent.fotoliaSelectImageFormObject.observeOnAfterOpen(
			function() {
				loader.initFormContent();
			}
		);
		var selectedImageId = self.parent.fotoliaBannerManager.getSelectedImageId();
		if (self.parent.fotoliaSearchFormManager) {
			self.parent.fotoliaSearchFormManager.selectImage(selectedImageId);
		}
	},

	/**
	 * Loads form content if it is not loaded
	 *
	 * @access public
	 * @return void
	 */
	initFormContent: function() {
		var selectedImageId = self.parent.fotoliaBannerManager.getSelectedImageId();
		if (self.parent.fotoliaSearchFormManager) {
			self.parent.fotoliaSearchFormManager.selectImage(selectedImageId);
		} else {
			var requestUrl = self.parent.baseUrl + '/Wizard/Edit/Modules/Fotolia/SelectImage';
			if (selectedImageId) {
				var requestParams = new Object();
				requestParams.selectedImageId = selectedImageId;
				requestUrl += '?' + Object.toQueryString(requestParams);
			}
			self.parent.$('fotoliaSelectImageFormContent').src = requestUrl;
		}
	}
}