var language = 0;

YUI().use("node", "event", "node-menunav", "overlay", "cookie", function(Y) {
	var main = {
		HEADER_MENU_HEIGHT: 302,//210,//181,
		
		init: function()
		{
			language = /\/e\//i.test(window.location) ? 0 : 1;
		
			// Initialize the menu.
			Y.on("contentready", function(e) {
				this.plug(Y.Plugin.NodeMenuNav, { submenuShowDelay: 0, submenuHideDelay: 100, mouseOutHideDelay: 400 });
			}, "#menu");
			Y.all("#menu .Dropdown").setStyle("visibility", "visible");
			
			// Render browser upgrade overlay.
			main.browserUpgradeOverlay = new Y.Overlay({
				srcNode: "#upgrade",
				centered: true,
				visible: false,
				width: "35em"
			});
			Y.one("#upgrade").setStyle("display", "block");
			main.browserUpgradeOverlay.render();
			
			// Fill content to window on window resize, and do initial resize.
			Y.on("contentready", function(e) {
				main.resize();
			}, "body");
			Y.on("windowresize", main.resize);
			
			main.ie6();
		},
		
		resize: function()
		{
			var minHeight = Y.DOM.winHeight() - main.HEADER_MENU_HEIGHT,
				currentHeight = Y.DOM.docHeight() - main.HEADER_MENU_HEIGHT,
				contentHeight = parseInt(Y.one("#contentHeightMonitor").getStyle("height"));
			if (contentHeight < minHeight)
			{
				Y.one("#bd").setStyle("height", minHeight);
			}
			else if (contentHeight < currentHeight)
			{
				Y.one("#bd").setStyle("height", "auto");
			}
		},
		
		ie6: function()
		{
			if (!(Y.UA.ie > 0 && Y.UA.ie < 7 || Y.UA.gecko > 0 && Y.UA.gecko < 1.9) || Y.Cookie.get("ignoreBrowserUpgrade"))
			{
				return;
			}
			
			Y.one("#overlay").setStyles({ height: Y.DOM.docHeight(), display: "block" });
			main.browserUpgradeOverlay.show();
			
			Y.one("#upgrade_close").on("click", function(e) {
				e.preventDefault();
				
				main.browserUpgradeOverlay.hide();
				Y.one("#overlay").setStyle("display", "none");
				
				var expiryDate = new Date();
				expiryDate = new Date(expiryDate.getTime() + 43200000);
				Y.Cookie.set("ignoreBrowserUpgrade", true, { expires: expiryDate });
			});
		}
	};
	Y.on("domready", main.init);
});
