$(function() {
	setTimeout(function() {
		var navWidth = $('#navItems').width();
		$('#navItems a').each(function() {
			var subId = '#' + this.id + 'Sub';
			if ($(subId).size() > 0) {
				// has a sub nav menu, set it up
				var left = $(this).parent().position()['left'] - navWidth;
				if (left > -180) left = -180;
				$(subId).css('left', left);
				$(this).mouseover(function() {
					$(this).attr('_count', parseInt($(this).attr('_count'))+1)
					if ( ! $(this).hasClass('selected')) {
						hideMenus(this.id);
						$(subId).slideDown(200);
						$(this).addClass('selected');
					}
				}).mouseout(function() {
					$(this).attr('_count', parseInt($(this).attr('_count'))-1);
					if ($(this).hasClass('selected')) {
						clearTimeout($(this).attr('_timer'));
						if (parseInt($(this).attr('_count')) <= 0) {
							// set the timer
							$(this).attr({'_timer': setTimeout('hideMenu("#' + this.id + '")', 1000),
								'_count': 0});
						}
					}
				}).attr('_count', 0);
				$(subId).mouseover(function() {
					$('#' + this.id.replace('Sub', '')).trigger('mouseover');
				}).mouseout(function() {
					$('#' + this.id.replace('Sub', '')).trigger('mouseout');
				});
			}
		})
	}, 500);
	$('input.replaceText').each(function() {
		$(this).attr('_value', $(this).val());
	}).focus(function() {
		if ($(this).val() == $(this).attr('_value')) {
			$(this).val('');
		}
	}).blur(function() {
		if ($.trim($(this).val()) == '') {
			$(this).val($(this).attr('_value'));
		}
	});
	$('#searchSubmit').click(function() {
		$('#searchForm').submit();
		return false;
	});
	$('#searchForm').submit(function() {
		var text = $.trim($('#searchText').val());
		if (text == '' || text == $('#searchText').attr('_value')) {
			alert('You must enter something to search for first.');
			$('#searchText').focus();
			return false;
		}
	})
})
$(function() {
	$('a.dialogLink').click(function(evt) {
		evt.preventDefault();
        evt.stopPropagation();
		$('#dialog').load(this.href, null, loadComplete)
		$('#screen').css({'width': $(document).width(), 'height': $(document).height()})
		if ($.browser.msie) {
			$('#screen').show();
		} else {
			$('#screen').fadeIn(300);
		}
	});
})
function loadComplete() {
	var dlg = $('#dialog');
	var width = dlg.width() / 2;
	var height = dlg.height() /2;
	dlg.css({marginLeft: -width, marginTop: $(window).scrollTop() - height});
	if ($.browser.msie) {
		$('#dialog').show();
	} else {
		$('#dialog').fadeIn(600);
	}
}
function hideMenu(id) {
	if ($(id).hasClass('selected') && parseInt($(id).attr('_count')) == 0) {
		$(id + 'Sub').slideUp(200);
		$(id).removeClass('selected');
	}
}
function hideMenus(id) {
	$('#navItems a').each(function() {
		if (this.id != id) {
			if ($(this).hasClass('selected')) {
				$(this).attr('_count', 0);
				hideMenu('#' + this.id);
			}
		}
	});
}