// JavaScript Document

$(document).ready(function(){
	// Floating topOfPage link
	topOfPage();
	
	if($("#wrapMenu").length){
		if($("#wrapMenu ul li ul li").parents("li").hasClass("active") || $("#wrapMenu ul li ul li").hasClass("active")){
			$("#wrapMenu ul li ul").show();
		} else {
			$("#wrapMenu ul li ul").hide();
		}
	}
});


// Floating topOfPage link
function topOfPage() {
	// Show topOfPage link if content exceeds browser height and exceeds height of footer and right column (else there's no room for the link)
	if (($(document).height()>$(window).height()) && ($(document).height()>785)) {
		$(".topOfPage").css("display","block");
		$(window).scroll(function () { 
			offset = ($(document).scrollTop()+$(window).height()-(headerHeight + 20));
			// Not too high or low?
			if (offset<650) offset = 650;
			if ($(document).height()-offset<135) offset = $(document).height()-135;
			// Let's go...
			$(".topOfPage").animate({top:offset+"px"},{duration:500,queue:false});
		});
	}
}