
/*
 * Give a more interresting look to the progress meter
 */
$.fn.progressMeter = function() {
	$(".progress").each(function() {
		var progress = $.trim($(this).text());
		progress = 100 - progress.substring(0, progress.length-1);
		$(this).wrap('<div class="progress-meter"></div>');
		$(this).css("width", (200 - 2 * progress)+"px");
	});
};

/*
 * Force external links to open in a new window
 */
$.fn.targetBlank = function() {
	$("a[@rel=external]").attr("target", "_blank");
};

/*
 * Cross browser hoverable elements
 */
$.fn.hoverable = function(what, c) {
	$(what).each(function() {
		$(this).hover(function(){
			$(this).addClass(c);
		},
  	function(){
			$(this).removeClass(c);
		});
	});
};

/*
 * Footer positionning
 */
function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight= document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
$.fn.setFooter = function() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = $("#container").height();
			var footerHeight  = $("#footer").height();
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				$("#footer").css({"position": "absolute", "top": (windowHeight - footerHeight - 1) + "px"});
			} else {
				$("#footer").css({"position": "static"});
			}
		}
	}
}

$(document).ready(function() {
	$(window).setFooter();
	$(window).resize($.fn.setFooter);
	$("body").progressMeter();
	$("body").targetBlank();
	$("form").each(function() {$(this).find("input").get(0).focus();});
	if (jQuery.browser.msie) {
		$("form").hoverable(".button", "hover-button");
		$("form").hoverable(".field", "hover-field");
	}
});