$(document).ready(function() {

$("ul#navigation li div").animate({
	opacity : 0
}, 0);

	$("a#sgm").click(function () {
		if($("#sgm-list").hasClass("dropped")){
			$("#sgm-list").removeClass("dropped");
		} else {
			setTimeout(function() {$("#sgm-list").addClass("dropped")}, 500);	
		};
		$("#sgm-list").toggle();
	});
	
	$("a#new-here").click(function () {
		if($("#new-here-list").hasClass("dropped")){
			$("#new-here-list").removeClass("dropped");
		} else {
			setTimeout(function() {$("#new-here-list").addClass("dropped")}, 500);	
		};
		$("#new-here-list").slideToggle();
	});	
	
	$("body").click(function () {
		if($("#sgm-list").hasClass("dropped")){
			$("#sgm-list").slideToggle();
			$("#sgm-list").removeClass("dropped");
		};
		if($("#new-here-list").hasClass("dropped")){
			$("#new-here-list").slideToggle();
			$("#new-here-list").removeClass("dropped");
		};
		if($("#login-box").hasClass("dropped")){
			$("#login-box").fadeOut();
			$("#login-box").removeClass("dropped");
		}
		$(".dropdown").each(function() {
			if($(this).hasClass("dropped")){
				$(this).animate({ 
					marginTop : "20px",
					opacity : 0
				}, 300, function() {
					$(this).removeClass("dropped").hide();
				});
			};
		});
		$(".expand").each(function() { 
			if($(this).hasClass("expnd-selected")) {
				$(this).removeClass("expnd-selected");
				$(this).addClass("expnd");
			}
		});
	});
	$("a.primary-login").click(function () {
		if($("#login-box").hasClass("dropped")){
			$("#login-box").fadeOut();
			$("#login-box").removeClass("dropped");
			hasFocus = false;
		} else {
			$("#login-box").fadeIn();
			$("#username").focus();
			$("#login-box input").focus(function () {
				$("#login-box").removeClass("dropped");			
			});	
			$("#password").blur(function () {
				$("#login-box").addClass("dropped");			
			});	
			$("#username").blur(function () {
				$("#login-box").addClass("dropped");			
			});	
		};
	});

$('#header-search').keyup(function(e) {
	if(e.keyCode == 13) {
    var keywords = $("#header-search").val();
    keywords = keywords.replace(/'/g, "%27");
    keywords = keywords.replace(/"/g, "QOT");
    window.location= 'http://covlife.org//search/' + keywords;	
	};

});

$("a.expand").click(function() {
	$("a.expand").removeClass("expnd-selected");
	var dropItem = $(this).attr('id');
	dropItem = dropItem.replace(/expand/,'dropdown');
	$("a.expand").addClass("expnd");
	$(this).addClass("expnd-selected");
	$(this).removeClass("expnd");
	$('.' + dropItem).show().animate({
		marginTop : "30px",
		opacity : 1.0
	}, 300);
	setTimeout(function() {$('.' + dropItem).addClass("dropped")}, 500);	
});



});

function includejs(file) {
document.write('<script src="' + file +
'"type="text/javascript"><\/script>');
}
