/******************************************
 * The Location Modal Class
 *
 * Opens a content modal on the page.
 ******************************************/
if (typeof crumbs == "undefined" || !crumbs) {
    var crumbs = {};
}

crumbs.Modal.Content.Location = Class.create(crumbs.Modal.Content, {
	/**
	 * Constructor
	 */
	initialize: function () {
		this.containerId = "location-modal";
		var options = {
			className: "location-modal",
			zIndex: 1000,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			destroyOnClose: false,
			onClose: this.closeStore.bindAsEventListener(this),
			useOverlay: true,
			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];
		}
		myLoadOptions['destroyOnClose'] = myOptions['destroyOnClose'];

		if (myOptions["useOverlay"] && myOptions["useOverlay"] === true) 
			this.useOverlay = true;		
		this.window = new Window(this.containerId, myOptions);
		this.loadWindow = new Window(this.containerId + "-load", myLoadOptions);
	},

	/**
	 * loadSuccess, to add locations to the url.
	 */
	loadSuccess: function(transport) {
		var storeId = this.url.substr(this.url.lastIndexOf("/")+1);
		storeId = parseInt(storeId);
		screenManager.getLocation().addStore(storeId);

		this.loadWindow.hide();
		this.window.getContent().innerHTML = transport.responseText;
		this.evalHtml(this.window.getContent());
		this.showWindow();

		// track the page view
		screenManager.trackPageview(this.url);
	},

	/**
	 * Clears the store from the url and hides the window.
	 */
	closeStore: function() {
		screenManager.getLocation().clearStore();
		this.hideWindow();
	}
});