/**
 * Scripts to set up the galleries for a room
 */
var RoomPageURL = {
	PRAIRIE : '/rooms_galleries/prairie',
	TERRACE : '/rooms_galleries/terrace',
	PATIO : '/rooms_galleries/patio',
	GRAVENEY : '/rooms_galleries/graveney',
	ASHBY : '/rooms_galleries/ashby',
	ROOFTOP : '/rooms_galleries/rooftop'
};

/**
 * The object that takes care of the ui
 * @param Object
 * - trigger : jQuery instance of the element(s) responsible for triggering the callout
 * - url : String for where the content is to be found
 */
function RoomCallout (o) {
	/* Save the configuration */
	var _this = this;
	this.config = o;
	
	/* See if we have legitemate params */
	if (!this.config.trigger || !this.config.url) {
		return;
	}
	
	/* Link up the trigger */
	this.config.trigger.click(function (event) {
		_this.onTriggerClick(event);
	});
	this.config.trigger.css({
		'cursor' : 'hand',
		'cursor' : 'pointer'
	});
};
/**
 * Runs when the trigger gets clicked
 * @param Event
 */
RoomCallout.prototype.onTriggerClick = function (event) {
	/* Load in the data */
	jQuery('div.room-overlay').remove();
	var _this = this;
	jQuery.get(this.config.url, {}, function (data) {
		_this.onDataLoad(data);
	}, 'text');
};
/**
 * Runs when the html from the server finishes loading
 * @param Object
 */
RoomCallout.prototype.onDataLoad = function (data) {
	/* Save the dom element and set it up! */
	this.dom = jQuery(data);
	var elm;
	jQuery.each(this.dom, function (idx, elem) {
		if (jQuery(elem).hasClass('room-overlay')) {
			elm = jQuery(elem);
			return;
		}
	});
	this.dom = elm;
	this.setup();
};
/**
 * When the close button is clicked on
 * @param Event
 */
RoomCallout.prototype.onCloseClick = function () {
	/* Fade out the element */
	jQuery('div.room-overlay').remove();
};
/**
 * Sets up the callout window
 */
RoomCallout.prototype.setup = function () {
	/* Create a dom element */
	var _this = this;
	jQuery('body').append(this.dom);
	jQuery('div.room-overlay').find('a.button-close').click(function () {
		_this.onCloseClick();
		return false;
	});
	new HeaderGallery({
		container : this.dom.find('div.gallery-table-container'),
		speed : 4000,
		frequency : 5000
	});
};
