function DropMenu(options) {
	// Set our default options
	this.options = Object.extend({
		buttonList: [],
		dropList: [],
		timeout: 500
	}, options || {});

	// Setup our properties
	this.timer = null;
	this.current = null;

	// Setup our methods
	this.menuOpen = function(id) {
		// Close the current menu
		this.menuClose();

		// Show the new menu
		if ($(id)) {
			$(id).show();
			this.current = id;

			// Clear the timer, if necessary
			this.menuClear();
		}
	}

	this.menuClose = function() {
		if (this.current)
			$(this.current).hide();

		this.current = null;
	}

	this.menuTimeout = function() {
		this.timer = window.setTimeout(this.menuClose.bind(this), this.options.timeout);
	}

	this.menuClear = function() {
		if (this.timer) {
			window.clearTimeout(this.timer);
			this.timer = null;
		}
	}

	// Set an overall event to close the menu upon a click
	Event.observe(document, 'click', this.menuClose.bind(this));

	// Add our handlers to any menu items
	if (this.options.buttonList.length == this.options.dropList.length) {
		for (var i = 0; i < this.options.buttonList.length; i++) {
			var b = $(this.options.buttonList[i]);
			var d = $(this.options.dropList[i]);

			if ($(b) && $(d)) {
				var t = b.id.substr(3);

				Event.observe($(b), 'mouseover', this.menuOpen.bind(this, d));
				Event.observe($(b), 'mouseout', this.menuTimeout.bind(this));
				Event.observe($(d), 'mouseover', this.menuClear.bind(this));
				Event.observe($(d), 'mouseout', this.menuTimeout.bind(this));

				// Set the hovers for the children of the menu
				var c = d.childElements();
				c.each(function(e) {
					var de = e.firstDescendant();

					e.observe('mouseover', quickHov.bind(e, true, t));
					e.observe('mouseout', quickHov.bind(e, false, t));
					e.observe('click', quickLink.bindAsEventListener(de, de.href));
				});
			}
		}
	}
}

function quickLink(e, url) {
	if (url == null || url < 0)
		return;

	if (this.hasClassName("jsChat")) {
		openChat(e);
	} else {
		window.location.href = url;
	}
}

function quickHov(a, t) {
	if (a) {
		this.addClassName(t + 'Hov');
	} else {
		this.removeClassName(t + 'Hov');
	}
}

function buddyToggle() {
	try {
		var id = this.id.substr(11);
		Effect.toggle('buddyShow_' + id, 'blind', {duration: .3});
	} catch(err) { }
}

function xt(e) {
	// Attempt to grab a page/entry ID
	var idp = 0;
	var ide = 0;

	if (this.id && this.id.substr(0, 3) == 'xt_') {
		var xt = this.id.split("_");
		idp = xt.length > 1 ? xt[1] : 0;
		ide = xt.length > 2 ? xt[2] : 0;
	}

	var sr = "/xt/?idp=" + idp + "&ide=" + ide + "&sp=" + escape(window.location.pathname) + "&ss=" + escape(window.location.search) + "&sh=" + escape(window.location.hash) + "&ud=" + escape(this.href) + "&st=" + escape(document.title);
	(new Image()).src = sr;

    return true;
}

function openChat(e) {
	Event.stop(e);
	window.open('/chat/', 'pokercuriouschat', 'width=900,height=600,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no');
}

document.observe("dom:loaded",
	function() {
		try {
			new DropMenu({
				buttonList: ['navMostPopular', 'navEntertainment', 'navMedia', 'navPurchasableResources', 'navInformationalResources', 'navCommunity', 'navPokerCuriousContent', 'navHelpAbout'],
				dropList: ['menuMostPopular', 'menuEntertainment', 'menuMedia', 'menuPurchasableResources', 'menuInformationalResources', 'menuCommunity', 'menuPokerCuriousContent', 'menuHelpAbout'],
				timeout: 500});

			swfobject.embedSWF('/flash/top-banner.swf', 'flashBanner', '194', '113', '9.0.0', false, false, false, {styleclass: 'emb'});

			// Setup any button stuff
			var en = $$('div.xbBase');
			en.each(function(e) {
				// Look for an anchor tag
				var an = $(e).select('a');
				if (an.length >= 1) {
					e.observe('click', quickLink.bind(this, an[0].href));
				}
			});

			// Setup any buddylist stuff
			var en = $$('div.jsBuddyClick');
			en.each(function(e) {
				e.observe('click', buddyToggle.bind(e));
			});

			// Setup all link stuff
			var en = $$('a');
			en.each(function(e) {
				e.observe('click', xt.bindAsEventListener(e));
			});

			// Setup chat links
			var en = $$('a.jsChat');
			en.each(function(e) {
				e.observe('click', openChat.bindAsEventListener(e));
			});
		} catch(err) { }
	}
);