/*
 * @author		Claudio Bizzotto
 * @requires	DomHelp.js
 */

Hacks =
{
	body: null,
	windowHeight: null,
	bodyHeight: 750,

	/**
	 *
	 *
	 */
	init: function ()
	{
		//document.getElementById("nocloack").style.display = "none";
		//Hacks.body = document.getElementById("body");
		//Hacks.alignVertically();
	},
	
	/**
	 *
	 *
	 */
	getWindowHeight: function()
	{
		if (Hacks.windowHeight > 0) return Hacks.windowHeight;
		
		var windowHeight = 0;

		if (typeof(window.innerHeight) == "number")
		{
			windowHeight = window.innerHeight;
		}
		else
		{
			if (document.documentElement && document.documentElement.clientHeight)
			{
				windowHeight = document.documentElement.clientHeight;
			}
			else if (document.body && document.body.clientHeight)
			{
				windowHeight = document.body.clientHeight;
			}
		}
		
		Hacks.windowHeight = windowHeight;
		return (windowHeight);
	},
	
	/**
	 *
	 *
	 */
	alignVertically: function ()
	{
		//if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) return;

		if (document.getElementById)
		{
			var windowHeight = Hacks.getWindowHeight();
			
			if (windowHeight > 0)
			{
				var contentElement = Hacks.body;
				var contentHeight = Hacks.bodyHeight; // contentElement.offsetHeight;
				
				if (windowHeight - contentHeight > 0)
				{
					contentElement.style.position = "relative";
					contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + "px";
				}
				else
				{
					contentElement.style.position = "static";
				}
			}
		}
	},

	/**
	 *
	 *
	 */
	changeBackground: function ()
	{
		var central_column, from, url, image, page;

		central_column  = document.getElementById("central_column");
		url = document.URL;
		from = url.search(/\/[a-zA-Z]{2}\//i);
		page = url.substring(from + 4); // Remove language piece (eg: "/en/")
		page = page.substring(0, page.length-1); // Remove trailing slash

		switch (page)
		{
			case "services":
			case "services":
				central_column.style.backgroundImage = "url(../../media/images/layout/services_bg.jpg)";
				break;
			case "theclub":
			case "leclub":
				central_column.style.backgroundImage = "url(../../media/images/layout/theclub_bg.jpg)";
				break;
			case "neighbourhood":
			case "lequartier":
				central_column.style.backgroundImage = "url(../../media/images/layout/neighbourhood_bg.jpg)";
				break;
			case "contact":
			case "contact":
				central_column.style.backgroundImage = "url(../../media/images/layout/contact_bg.jpg)";
				break;
			case "accueil":
			default:
				central_column.style.backgroundImage = "url(../../media/images/layout/home_bg.jpg)";
				break;
		}
	}
};

DomHelp.addEvent(window, "load", Hacks.init, false);
DomHelp.addEvent(window, "resize", Hacks.alignVertically, false);
