/**
 * Sb crop form loader scripts
 *
 * @copyright (c) 2004-2008, SWsoft
 */
var SbCropFormLoader = Class.create();
SbCropFormLoader.prototype = {

	/**
	 * Initialises the class
	 *
	 * @access public
	 * @return void
	 */
	initialize: function() {
		var loader = this;
		self.sbCropFormObject.observeOnBeforeOpen(
			function() {
				loader.initFormContent();
			}
		);
		self.sbCropFormObject.observeOnAfterClose(
			function() {
				loader.clearFormContent();
			}
		);
		self.sbCropFormObject.observeOnAfterClose(
			function() {
				loader.restoreSelection();
			}
		);
	},

	/**
	 * Cleares form content
	 *
	 * @access public
	 * @return void
	 */
	clearFormContent: function() {
		$('sbCropFormContent').src = '/blank.html';
	},

	/**
	 * Restores WYSIWYG selection
	 *
	 * @access public
	 * @return void
	 */
	restoreSelection: function() {
		var helper = self.parent.getSbImageHelperInstance();
		var fckObject = helper.getFckObject();

		helper.restoreSelection();
		fckObject.FCK.Focus();
	},

	/**
	 * Loads form content
	 *
	 * @access public
	 * @return void
	 */
	initFormContent: function() {
		var src = self.baseUrl + '/Wizard/Edit/Wysiwyg/SbCrop';
		var requestParams = new Object();

		var helper = self.parent.getSbImageHelperInstance();
		var imageInfo = helper.getSelectedImageInfo();
		if (imageInfo && imageInfo.src) {
			requestParams.src = imageInfo.src;
			requestParams.width = imageInfo.width;
			requestParams.height = imageInfo.height;
		}
		var requestParamsString = Object.toQueryString(requestParams);
		if (requestParamsString.length > 0) {
			src += '?' + requestParamsString;
		}

		$('sbCropFormContent').src = src;
	}
}