function Property()
{
	this.mode = null;

	if (location.href.match(/gallery/))
		this.mode = Property.Mode.Gallery;
	else if (location.href.match(/prices/))
		this.mode = Property.Mode.Prices;
	else
		this.mode = Property.Mode.Default;
}
Property.prototype = new DomDependentDispatcher(Property);
Property.current = null;

Property.Mode = {};
Property.Mode.Default = 1;
Property.Mode.Gallery = 2;
Property.Mode.Prices = 3;

Property.setup = function ()
{
	Property.current = new Property;
	Property.current.initialize();
}

Property.cleanup = function ()
{
	if (Property.current != null)
		Property.current.cleanup();
}

Property.prototype.initialize = function ()
{
	this.initializeElements();

	if (this.mode == Property.Mode.Gallery)
		return;
	else
		this.initializeDefault();
}

Property.prototype.initializePrices = function ()
{
}

Property.prototype.initializeDefault = function ()
{
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
	{
		if (links[i].id.match(/propertyPricesLink/))
		{
			evt.addHandler(links[i], "onclick", Property.showPrices);
		}

		else if (links[i].href.match(/#rooms/))
			evt.addHandler(links[i], "onclick", Property.scrollToRooms);

		else if (links[i].href.match(/#gallery/))
			evt.addHandler(links[i], "onclick", Property.showGallery);

		else if (links[i].href.match(/#r\d+_more/))
			evt.addHandler(links[i], "onclick", Property.showSingleRoom);

		else if (links[i].href.match(/#toggleAll/))
			evt.addHandler(links[i], "onclick", Property.toggleRoomDetails);
	}
}

Property.showPrices = function ()
{
	try
	{
		if (document.getElementById("priceHeader"))
		{
			Property.scrollToPrices();
		}
		else
		{
			Property.showRoomDetails();
			Property.scrollToRooms();
		}
	}
	catch(e)
	{
		log.error(e.message);
	}

	return false;
}

Property.toggleRoomDetails = function ()
{
	var allvisible = Property.areAllRoomsVisible();
	if (allvisible)
		Property.hideRoomDetails();
	else
		Property.showRoomDetails();

	return false;
}

Property.areAllRoomsVisible = function ()
{
	var allvisible = true;

	var prices = document.getElementById("propertyPrices");
	var details = dom.getElementsByClassName(prices, "detail");
	for (var i = 0; i < details.length; i++)
	{
		if (details[i].offsetHeight == 0)
		{
			allvisible = false;
			break;
		}
	}

	return allvisible;
}

Property.showRoomDetails = function ()
{
	var prices = document.getElementById("propertyPrices");
	var details = dom.getElementsByClassName(prices, "detail");

	for (var i = 0; i < details.length; i++)
		if (details[i].offsetHeight == 0)
			css.display(details[i]);
}

Property.hideRoomDetails = function ()
{
	var prices = document.getElementById("propertyPrices");
	var details = dom.getElementsByClassName(prices, "detail");

	for (var i = 0; i < details.length; i++)
		css.undisplay(details[i]);
}

Property.showSingleRoom = function ()
{
	if (this.href.match(/#r(\d+)/))
	{
		var roomNum = RegExp.$1;
		var roomElem = document.getElementById("room" + roomNum);
		if (roomElem)
		{
			var detailElem = dom.getElementsByClassName(roomElem, "detail")[0];

			if (detailElem && detailElem.offsetHeight)
				css.undisplay(detailElem);

			else if (detailElem)
				css.display(detailElem);
		}
	}
	return false;
}

Property.scrollToRooms = function ()
{
	var roomHeader = document.getElementById("roomHeader");
	if (roomHeader != null)
	{
		Property.scrollToElement(roomHeader);
		return false;
	}
}

Property.scrollToPrices = function ()
{
	var priceHeader = document.getElementById("priceHeader");
	if (priceHeader != null)
	{
		Property.scrollToElement(priceHeader);
		return false;
	}
}

Property.scrollToElement = function (elemObj, length)
{
	if (isNaN(length))
		length = 700;

	var html = document.getElementsByTagName("html")[0];
	var targetTop = dom.getTop(elemObj) - 10;
	var scroll = new anim.Scroll(html, targetTop, 0, length, Math.easeOutExpo);
	scroll.run();

	return false;
}

Property.showGallery = function ()
{
	alert("showGallery");
	return false;
}

Property.showPriceOverview = function ()
{
	ui.showDialog(this.href, 820, 600);
	return false;
}

evt.addHandler(window, "onready", Property.setup);
evt.addHandler(window, "onunload", Property.cleanup);

