/**
 * Fotolia banner manager scripts
 *
 * @copyright (c) 2004-2008, SWsoft
 */
function InitFotoliaBannerManager(selectedImageId) {
	self.parent.fotoliaBannerManager = new FotoliaBannerManager(selectedImageId);
}
var FotoliaBannerManager = Class.create();
FotoliaBannerManager.prototype = {

	/**
	 * Selected image id
	 *
	 * @var string
	 * @access private
	 */
	_selectedImageId: null,

	/**
	 * Object constructor
	 *
	 * @access public
	 * @param string
	 * @return void
	 */
	initialize: function(selectedImageId) {
		if (selectedImageId) {
			this._selectedImageId = selectedImageId;
		}
		if ('on' != self.getCookie('fotoliaHidePromotionLink')) {
			$('fotoliaPromotionContainer').show();
		}
		var containerRow = $('sbImageProvidersBannersContainerRow');
		var updateDialogSize = function() {
			self.parent.sbImageFormObject.changeSize(750, 460 + containerRow.getHeight());
		}
		updateDialogSize();

		var manager = this;

		var hidePromotionLink = $('fotoliaHidePromotionLink');
		if (hidePromotionLink) {
			Event.observe(
				hidePromotionLink,
				'click',
				function() {
					manager.hidePromotion();
					updateDialogSize();
				}
			);
		}

		var searchFormLink = $('fotoliaSearchLink');
		if (searchFormLink) {
			Event.observe(searchFormLink, 'click', function() { manager.openSearchDialog(); } );
		}

		var browseGalleryButton = $('fotoliaBrowseGalleryButton');
		if (browseGalleryButton) {
			browseGalleryButton.onclick = function() { manager.openSearchDialog(); return false; };
			self.enableButton(browseGalleryButton);
		}

		var purchaseFormLink = $('fotoliaPurchaseLink');
		if (purchaseFormLink) {
			Event.observe(purchaseFormLink, 'click', function() { manager.openPurchaseDialog(); } );
		}
	},

	/**
	 * Returns current selected image id
	 *
	 * @access public
	 * @return string
	 */
	getSelectedImageId: function() {
		return this._selectedImageId;
	},

	/**
	 * Hides promotion
	 *
	 * @access public
	 * @return void
	 */
	hidePromotion: function() {
		self.setCookie('fotoliaHidePromotionLink', 'on', 'Sat, 01-Jan-39 00:00:01 GMT', '/');
		$('fotoliaPromotionContainer').hide();
	},

	/**
	 * Opens search dialog
	 *
	 * @access public
	 * @return void
	 */
	openSearchDialog: function() {
		var maxDimensions = self.parent.sbImageFormObject.getMaxDimensions();
		self.parent.SbProduceModalForm(
			'fotoliaSelectImageForm',
			self.parent.baseUrl + '/Ajax/Wizard/Edit/Modules/Fotolia/SelectImageForm?' +
				Object.toQueryString(maxDimensions)
		);
		self.fotoliaSelectImageFormLoader = new FotoliaSelectImageFormLoader();
		self.parent.fotoliaSelectImageFormObject.open();
	},

	/**
	 * Opens search dialog
	 *
	 * @access public
	 * @return void
	 */
	openPurchaseDialog: function() {
		self.parent.SbProduceModalForm(
			'fotoliaPurchaseImageForm',
			self.parent.baseUrl + '/Ajax/Wizard/Edit/Modules/Fotolia/PurchaseImageForm'
		);
		self.parent.fotoliaPurchaseImageFormManager = new FotoliaPurchaseImageFormManager(this._selectedImageId);
	}
}