$.fn.tagName = function () {
	return this.get(0).tagName.toLowerCase();
};

$(document).ready(function () {
	$('.header-top-left').locDropdown([
		{ 'text': 'Las Vegas, NV', 'href': './lasvegas-location.php' },
		{ 'text': 'Salt Lake City, UT', 'href': './saltlakecity-location.php' },
		{ 'text': 'St. George, UT', 'href': './stgeorge-location.php' }
	]);
});

/** Manual navigation dropdowns for IE6 */
(function () {

	if (!($.browser.msie && -1 != $.browser.version.indexOf('6.'))) {
		return false;
	}

	var get_nav_level = function () {

		var scope = this,
		level = 0,
		parent = $(scope).parent();

		while ('div' != parent.get(0).tagName.toLowerCase()) {
			parent = parent.parent();
			level++;
		}

		return level;

	},
	get_base_link = function () {
		var parent = $(this).parent();
		while (1) {
			parent = parent.parent();
			if ('li' == parent.get(0).tagName.toLowerCase() && '' != $.trim(parent.attr('class'))) {
				break;
			}
		}
		return parent;
	},
	timeout = 0;

	$('.topnav a').mouseenter(function (evt) {
		clearTimeout(timeout);
		switch (get_nav_level.apply(this)) {
			case 2: /** Hovering over a main button */
				/** Remove all other hovering */
				$('.topnav li').removeClass('hover');
				$('.topnav ul.grandchild').parent().removeClass('hover');
				/** Add hovering to parent */
				$(this).parent().addClass('hover');
				$(this).parent().find('ul.child').width($(this).width());
			break;
			case 4: /** Hovering over a subnav */
				get_base_link.apply(this).addClass('hover');
				$(this).parent().addClass('hover');
			break;
			case 6:
			break;
		}
	}).mouseleave(function (evt) {
		var scope = this;
		switch (get_nav_level.apply(this)) {
			case 2: /** Leaving from a main button */
				timeout = window.setTimeout(function () {
					$(scope).parent().removeClass('hover');
				}, 50);
			break;
			case 4:
			case 6:
				timeout = window.setTimeout(function () {
					$('.topnav li').removeClass('hover');
				}, 100);
			break;
		}
		evt.stopPropagation();
	});
	$('.topnav ul').add('.topnav ul li').mouseenter(function () {
		clearTimeout(timeout);
	});

})();
