/******************************************
 * The Content Modal Class
 *
 * Opens a content modal on the page.
 ******************************************/
if (typeof crumbs == "undefined" || !crumbs) {
    var crumbs = {};
}

crumbs.Modal.Content = Class.create(crumbs.Modal, {
	/**
	 * Constructor
	 *
	 * Add the option {useOverlay: true} to disable the screen when the modal is open.
	 */
	initialize: function (customOptions) {
		this.containerId = "content-modal";
		var options = {
			className: "content-modal",
			zIndex: 1000,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			useOverlay: true,
			onClose: this.hideWindow.bindAsEventListener(this),
			recenterAuto: false
		};

		// set Object options
		var myOptions = Object.clone(this.options);
		var myLoadOptions = Object.clone(this.loadOptions);
		for (var i in options) {
			myOptions[i] = options[i];
		}

		// set Constructor options
		if (customOptions) {
			for (var j in customOptions) {
				myOptions[j] = customOptions[j];
				myLoadOptions[j] = customOptions[j];
			}
		}
		if (myOptions["useOverlay"] && myOptions["useOverlay"] === true) 
			this.useOverlay = true;
		myLoadOptions['destroyOnClose'] = myOptions['destroyOnClose'];

		this.window = new Window(this.containerId, myOptions);
		this.loadWindow = new Window(this.containerId + "-load", myLoadOptions);
	},

	/**
	 * Load content via an asynchronous request.
	 *
	 * @param Event e
	 * @param string url
	 */
	load: function($super, e, url) {
		if (Object.isString(url))
			this.setUrl(url);

		this.eventCreate = this.loadCreate.bindAsEventListener(this);
		this.eventSuccess = this.loadSuccess.bindAsEventListener(this);
		this.eventFailure = this.loadFailure.bindAsEventListener(this);

		var options = {
			method: 'get',
			onCreate: this.eventCreate,
			onSuccess: this.eventSuccess,
			onFailure: this.eventFailure
		};
		
		$super(options);
	}
});