$(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() {
	//$('a.dialogLink').click(function(evt) {
	$('#smallRightBlurb a').click(function(evt) {
		if( !(this.href.toLowerCase().indexOf(".aspx") > 0) && !(this.href.toLowerCase().indexOf(".pdf") > 0) )
		{
		evt.preventDefault();
        	evt.stopPropagation();
		if(this.href.toLowerCase().indexOf(".swf") > 0)
		{
			//$('#dialog').load("#", null, loadComplete);

			$("#dialog").html("<div id=\"popupVideo\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"640\" height=\"400\" id=\"vid-overview\" align=\"middle\">		<param name=\"allowScriptAccess\" value=\"sameDomain\" \/>		<param name=\"allowFullScreen\" value=\"false\" \/>		<param name=\"movie\" value=\"" + this.href +"\" \/><param name=\"loop\" value=\"false\" \/><param name=\"menu\" value=\"false\" \/><param name=\"quality\" value=\"best\" \/><param name=\"scale\" value=\"exactfit\" \/><param name=\"wmode\" value=\"transparent\" \/><param name=\"bgcolor\" value=\"#ffffff\" \/>			<embed src=\"" + this.href +"\" loop=\"false\" menu=\"false\" quality=\"best\" scale=\"exactfit\" wmode=\"transparent\" bgcolor=\"#ffffff\" width=\"640\" height=\"400\" name=\"vid-overview\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"\/>		</object><p id=\"dialogClose\"><a href=\"#\" class=\"dialogClose\">Close &raquo;</a></p><script>$(\"#dialogClose\").click(function() {	if ($.support.opacity) {		$(\"#dialog, #screen\").hide(function() { $(\"#dialog\").html(\"\"); });	} else {		$(\"#dialog, #screen\").fadeOut(300, function() { $(\"#dialog\").html(\"\"); });	}	return false;});	</script></div>	");

			loadComplete();
		}
		else if ($(this).parent(3).attr("id") == "smallRightBlurb")
		{
			if(!this.href.toLowerCase().indexOf(".aspx") > 0 && !this.href.toLowerCase().indexOf(".pdf") > 0)
			{
				//$('#dialog').load("#", null, loadComplete);

				$("#dialog").html("<div id=\"popupImage\"><a href=\"#\" class=\"dialogClose\" title=\"Close\"><img id=\"dialogClose\" src=\"" + this.href + "\" width=\"450\" height=\"300\" alt=\"Overflow Stickers\" border=\"0\" /></a><script>	$(\"#dialogClose\").click(function(evt) {	evt.preventDefault();	if ($.browser.msie) {	$(\"#dialog, #screen\").hide();} else {	$(\"#dialog, #screen\").fadeOut(300);	}});</script></div>");

				loadComplete();
			}
			else
			{
				//if(this.href.toLowerCase().indexOf(".pdf") > 0)
				//{
					//newwindow=window.open(url,'name','height=200,width=150');
					//if (window.focus) {newwindow.focus()}
				//}
				//else
				//{
					window.location.href = this.href;
				//}
			}
		}
		else 
		{
			$('#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);
			}
		}
	});
}
