/**
 * An info window 
 */
var CoalitionInfoWindow = new Class({
	Extends: InfoWindow,

	/**
	 * Create a new info window for the coalition map. The options hash should
	 * contain the following to properly fill out the content:
	 *
	 * options.values.name
	 * options.values.url
	 * options.values.coordinator_name
	 * options.values.coordinator_email
	 * options.values.phone
	 * options.values.designation_date
	 * options.values.boundaries
	 */
	initialize: function(options) {
		this.parent(options);

		// If an existing content div is supplied, try to find the boundaries
		// container, since we'll need a reference to this later on.
		if(this.content) {
			this.boundaries_container = this.content.getElement(".info_window_boundaries");

			// We were actually hiding the name from the screen readers since
			// its redundant within the original context. So we need to make
			// that visible now.
			var name = this.content.getElement(".info_window_name");
			name.setStyle("display", "");
			name.setStyle("visibility", "");
		}

		this.addEvent("openStart", this.handleOpenStart.bind(this));
		this.addEvent("open", this.handleOpen.bind(this));
		this.addEvent("closeStart", this.handleCloseStart.bind(this));

		this.coordinator_rows = [];
		this.coordinator_name_containers = [];
		this.coordinator_phone_containers = [];
	},

	/**
	 * Triggered after the info window has just begun to open.
	 */
	handleOpenStart: function(event) {
		// Our content is originally grabbed from elsewhere on the page where
		// its hidden view, but visible to screen readers. So now that we
		// actually want to display this content, we need to remove our special
		// hiding class so it can become visible to viewing users.
		this.content.removeClass("hide");
	},

	/**
	 * Triggered after the info window has been completely openend.
	 */
	handleOpen: function(event) {
		// The boundaries div needs to be expanded to fill the rest of the
		// height of the info window, so it can scroll if needs be.
		var boundaries_container_position = this.boundaries_container.getPosition(this.inner_window);
		var boundaries_container_height = this.content_height - boundaries_container_position.y;

		this.boundaries_container.setStyle("height", boundaries_container_height + "px");

		// Firefox has a fun little bug with overflow auto elements that move
		// on the page. Even when they should be hidden, they do fun things
		// like move the document content where they should be displayed. So
		// all sorts of bizarre things can happen with seemingly random
		// fragments of the page moving across the screen. So we can only set
		// the div to autoflow once the window has finished opening and is no
		// longer moving.
		this.boundaries_container.setStyle("overflow", "auto");
	},

	/**
	 * Triggered when the info window has just begun its close action.
	 */
	handleCloseStart: function(event) {
		// Fix a Firefox bug with overflow auto elements messing things up
		// while an element is being moved on the page. See handleOpen for a
		// bit more detail.
		this.boundaries_container.setStyle("overflow", "visible");
	}
});
