/* ---------------------------------------------------------------------------------------------------------------------- */
/* Alerts --------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
$().ready(function() {
	if($(".thealert").length) {
		$(".thealert").hide();
		$(".alert-inside").css({"opacity":"0"});
		$(".thealert").delay(250).slideDown("slow",function() {
			$(".alert-inside").fadeTo("fast",1);
		});

		if($(".thealert").hasClass("good-alert")) {
			setTimeout("closeAlert()",4000);
		}
	}

	$(".close-it").click(function() {
		closeAlert();	
		return false;
	});
});

function closeAlert() {
	$(".alert-inside").fadeTo("fast",0,function() {
		$(".thealert").slideUp("slow");
	});
}



/* ---------------------------------------------------------------------------------------------------------------------- */
/* Tooltips ------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
$().ready(function() {
	$(".showtip").tipsy({
		live: true,
		gravity: 's'
	});
});



/* ---------------------------------------------------------------------------------------------------------------------- */
/* Helpful Tools Scroll Follow ------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------- */
$(window).scroll(function() {
	moveHelpfulTools();
});

$().ready(function() {
	originaloffset = $("#helpful-tools").position().top;
	originalmaxheight = $(".middle-container").offset().top+$(".middle-container").height();

	moveHelpfulTools();
});

var theoffset = 0;
var stop = 0;
function moveHelpfulTools() {
	theoffset = $("#helpful-tools").offset().top;
	
	moveVal = theoffset+($(window).scrollTop()-theoffset);
	if($(window).scrollTop()<originaloffset) {
		moveVal = originaloffset;
	} else {
		if((moveVal+$("#helpful-tools").height())>=originalmaxheight-60) {
			moveVal = originalmaxheight-$("#helpful-tools").height()-60;
		}
	}
	
	if(!stop) $("#helpful-tools").stop(true,true).animate({"top":moveVal+"px"},"50");
}
