jQuery(function() {
	jQuery('#shop, #about, #loc, #disc').each(function() { jQuery(this).attr('_overCount', 0); })
	.mouseover(function(evt) {
		jQuery(this).attr('_show', setTimeout('overNav("#' + this.id + '")', 150));
	}).mouseout(function(evt) {
		offNav('#' + this.id);
	});
	jQuery('#shopNav, #aboutNav, #discNav').hover(function() {
		overNav('#' + this.id.replace('Nav', ''), true);
	}, function() {
		offNav('#' + this.id.replace('Nav', ''), true);
	});

	jQuery('#bottomNav > div:not(.selectedGroup)').hide();
	jQuery('#bottomNav div.menu').mouseover(function(evt) {
		jQuery(this).attr('_overCount', parseInt(jQuery(this).attr('_overCount')) + 1);
		clearTimeout(jQuery(this).attr('_hider'));
		if (!jQuery(this).hasClass('dropped')) {
			navDropdown(this.id);
		}
	}).mouseout(function(evt) {
		jQuery(this).attr('_overCount', parseInt(jQuery(this).attr('_overCount')) - 1);
		clearTimeout(jQuery(this).attr('_hider'));
		if (jQuery(this).attr('_overCount') <= 0 && jQuery(this).hasClass('dropped')) {
			jQuery(this).attr({'_overCount': 0,
				'_hider': setTimeout('navDropdown()', 1000)
			});
		}
	}).attr('_overCount', 0)
	.children('div.navDroplist').css('display', 'block').hide();

	jQuery('#bottomNav a.fltrOpt').click(function(evt) {
		evt.preventDefault();
		evt.stopPropagation();
		navDropdown();
	});
})

function overNav(id, counterOnly) {
	jQuery(id).attr('_overCount', jQuery(id).attr('_overCount') + 1);
	clearTimeout(jQuery(id).attr('_hider'));
	jQuery(id).removeAttr('_hider');
	if (!jQuery(id).hasClass('_hilited') && !counterOnly) {
		// just ensure the current dropdowns are hidden before changes happen
		navDropdown('switchNav');
		jQuery('#topNav a._hilited').each(function() {
			jQuery(this).removeClass('_hilited');
			if (jQuery(this).hasClass('selected')) {
				jQuery(this).animate({'opacity': '0.5'}, 400).css('z-index', 0);
			} else {
				jQuery(this).animate({'opacity': '0'}, 400).css('z-index', 0);
			}
			if (jQuery.browser.msie) {
				jQuery('#' + this.id + 'Nav').hide();
			} else {
				jQuery('#' + this.id + 'Nav').animate({'opacity': '0'}, 400, function() {
					jQuery(this).css('display', 'none');
				});
			}
			clearTimeout(jQuery(this).attr('_hider'));
		});
		jQuery(id).addClass('_hilited').animate({'opacity': 1}, 400).css('z-index', 1);
		if (jQuery.browser.msie) {
			jQuery(id + 'Nav').show();
		} else {
			jQuery(id + 'Nav').css({'z-index': 1, 'display': 'block'}).animate({'opacity': 1}, 400)
				.addClass('_hilited');
		}
	}
}
function offNav(id) {
	clearTimeout(jQuery(id).attr('_show'));
	jQuery(id).attr('_overCount', jQuery(id).attr('_overCount') - 1);
	clearTimeout(jQuery(id).attr('_hider'));
	if (jQuery(id).attr('_overCount') <= 0) {
		jQuery(id).attr({'_overCount': 0, '_hider': setTimeout('revertNav()', 3000)});
	}
}
function revertNav() {
	navDropdown();
	jQuery('#topNav a').each(function() {
		if (jQuery(this).hasClass('_hilited') && !jQuery(this).hasClass('selected')) {
			jQuery(this).animate({'opacity': 0}, 400).css('z-index', 0).removeClass('_hilited');
			if (jQuery.browser.msie) {
				jQuery('#' + this.id + 'Nav').hide();
			} else {
				jQuery('#' + this.id + 'Nav').animate({'opacity': 0}, 400, function() {
					jQuery(this).css('display', 'none').removeClass('_hilited');
				}).css('z-index', 0);
			}
		} else if (jQuery(this).hasClass('selected') && !jQuery(this).hasClass('_hilited')) {
			jQuery(this).css('z-index', 1).animate({'opacity': 1}, 400).addClass('_hilited');
			if (jQuery.browser.msie) {
				jQuery('#' + this.id + 'Nav').show();
			} else {
				jQuery('#' + this.id + 'Nav').css({'z-index': 1, 'display': 'block'})
					.animate({'opacity': 1}, 400).addClass('_hilited');
			}
		}
	});
}
/**
 * Shows the dropdown passed in by id and hides all other dropdowns.  If no id
 * is passed in, then all dropdowns are hidden
 */
function navDropdown(id) {
	jQuery('#bottomNav div._hilited div.menu').each(function() {
		clearTimeout(jQuery(this).attr('_hider'));
		if (this.id == id) {
			jQuery(this).addClass('dropped').children('div.navDroplist').slideDown(300).css('z-index', 5);
		} else {
			if (jQuery(this).hasClass('dropped')) {
				if (id == 'switchNav') {
					jQuery(this).removeClass('dropped').children('div.navDroplist').hide().css('z-index', 0);
				} else {
				jQuery(this).removeClass('dropped').children('div.navDroplist').slideUp(300, function() {
					jQuery(this).css('z-index', 0);
				});
				}
			}
			if (jQuery(this).hasClass('selected')) {
				if (id != null) {
					jQuery(this).children('a.titleLink').animate({borderBottomColor: 'rgb(252, 220, 213)'}, 300);
				} else {
					jQuery(this).children('a.titleLink').animate({borderBottomColor: 'rgb(243, 113, 83)'}, 300);
				}
			}
		}
	});
}
