$(document).ready(function(){	

$("ul li:last-child").addClass('last');
$(".colgroup .col:last-child").addClass('last');
$(".box:last-child").addClass('last');
$(".reports figure:last-child").addClass('last');
$(".content .colgroup:last-child").addClass('last');
	
// Call those functions
scrolltop();
checksidebarheight();
checkfold();
swapLogo();
closeLeader();

$("#squery").focus();
$("#form_password").focus();
}); 


// Scroll to top
function scrolltop() {
	$('a.self').click(
	function(){
		$.scrollTo( $('#page'), 500 );
		return false;
	}
	);
}
// check the height of th sidebar and positions the buttons on the white background
// use margin to keep element in the flow
function checksidebarheight() {
	var box = $("div.under");
	var link = $("div.under a");
	var position = box.position();
	// alert( "left: " + position.left + ", top: " + position.top );
	if (position.top < 511) {
		// box.css("position", "relative");
		// box.css("top", "520px");
		// box.css("left", "40");
		box.css("margin-top", (540 - position.top) + "px");
		link.css("color", "#666");
	}
	return true;
}
// check if the document if longer than the browser window (background gradient issue)
// needs to be optimised for border cases
//		* browser window not fullscreen, but big enough for all content
//		* user resizes browser (bigger)
//		* background appears
function checkfold() {
	var bh = $(window).height();   // returns height of browser viewport
	var dh = $(document).height(); // returns height of HTML document
	var html = $("html");
	var hh = html.outerHeight(true); // returns height of HTML element w/ margins and paddings incl.
	// alert("Browser height: "+ bh + "\nDocument height: " + dh + "\nHTML height: " + hh);
	if (hh < dh) { html.css("height", "100%"); }
	return true;
}
function swapLogo() {
	$('.branding .inner h1').hover(
		function () {
			$(this).css("background-image","url(/assets/img/logo_ufof_bleu.png)");
		  },
		function () {
		    $(this).css("background-image","url(/assets/img/logo_ufof_gris.png)");
		  }
	);
}
function closeLeader() {
	$('body.ufof div#leader a.close').click(
		function (event) {1
	     	event.preventDefault();
			$('body.ufof div#leader').toggle('slow');
		}
	)
}
