if (typeof PLSControl == "undefined") {
	PLSControl = {};
}

PLSControl.Modal = Class.create(Control.Modal, {
	initialize: function($super,container,options){
		options = options || {};

		var ai = options.afterInitialize;
		options.afterInitialize = function(e) {
			this._original_html = this.getContentContainer().innerHTML;
			this.bindLinks();
			ai && ai(e);
		}.bind(this);

		$super(container, options);
	},

	bindLinks: function() {
		this.container.select('a.close').invoke('observe','click', function(e) {
			e.stop();
			this.close();
			this.updateAndBind(this._original_html);
		}.bindAsEventListener(this));

		this.container.down('form a.submit').observe('click', function(e) {
			e.stop();
			e.findElement('form').request({
				onSuccess: function(response) {
					this.updateAndBind(response.responseText);
				}.bind(this)
			});
		}.bindAsEventListener(this));
	},

	getContentContainer: function()
	{
		return this.container.down('.holder');
	},

	updateAndBind: function(content)
	{
		this.getContentContainer().update(content);
		this.bindLinks();
	}
});

