﻿/*global PIEDMONT */
PIEDMONT = {
	interactiveMenus: [ 'NAV000222' ],

	onDOMReady: function() {
		this.initMenus();
	},

	initMenus: function() {
		var x, y, menu;
		var links = [];
		var menus = [];

		var x = this.interactiveMenus.length; while(x--) {
			menu = $('I' + this.interactiveMenus[x]);
			if (!menu) { continue; }
			menus[menus.length] = menu;
			for (y = 0; y < menu.childNodes.length; y++) {
				if (menu.childNodes[y].nodeName.toLowerCase() === 'a') {
					links[links.length] = menu.childNodes[y];
					break;
				}
			}
		}

		Event.addListener(links, 'click', Event.preventDefault, Event, true);
		Event.addListener(menus, 'click', this.showInteractiveMenu, this, true);
	},

	showInteractiveMenu: function(e) {
		var li     = Event.getTarget(e);
		if (li.nodeName.toLowerCase() !== 'li') { li = Dom.getAncestorByTagName(li, 'li'); }
		var tierRE = /\bT(\d+)\b/;
		var tier   = tierRE.exec(li.className);
		var x, ul = null;

		Dom.addClass(li, 'Active');
		Dom.addClass(li, tier[0] + 'Active');

		x = li.childNodes.length; while (x--) {
			if (li.childNodes[x].nodeName.toLowerCase() === 'ul') {
				ul = li.childNodes[x];
				break;
			}
		}

		if (ul === null) { return; }
		Dom.addClass(ul, 'Active');
		Dom.addClass(ul, 'T' + (parseInt(tier[1], 10) + 1).toString() + 'Active');
	},


	emailPage: {
		mailWindow: null,
		RootPath: '/Content/MailPage/',

		emailPage: function() {
			var sURL =
			this.RootPath +
			'Window-MailPage.asp' +
			'?URL=' + encodeURIComponent(document.location.href) +
			'&Title=' + encodeURIComponent(document.title);

			this.mailWindow = window.open(sURL, 'MailPage', 'height=700,width=500,toolbar=no,scrollbars=yes,resizable=yes');

			if (this.mailWindow !== null) {
				this.mailWindow.Scope = this;
			} else {
				alert('Your popup blocker has prevented us from opening a new window.\nPlease disable your popup blocker and try again.');
			}
		},

		closeEmail: function() {
			if (this.mailWindow !== null) { this.mailWindow.close(); }
		}

	}


};
Event.onDOMReady(PIEDMONT.onDOMReady, PIEDMONT, true);


