/**
* jQuery Plugin Up
* @requires	jQuery v1.2+
* @author	Mathieu Artu
* @licenses	Creative Commons license, 2009
*/

(function($){
	$.fn.up = function(options){
		// Definition Options
		var defaults	= { fontFace: "Arial, sans-serif", fontColor: "#fff", bgColor: "#ccc", angles: false, shadows: true, shadowColor: "#333", text: "Haut", altText: "Retourner en haut de page" };
		var options	= $.extend(defaults, options);

		// Html Structure
		$("body").append("<div id='up-anchor'><a href='#' title='" + options.altText + "'><span>" + options.text + "</span></a></div>");

		// CSS Appearance
		$("#up-anchor").css({ display: "none", opacity: "0.9", position: "fixed", right: "0", bottom: "50px", zIndex: 1000, overflow: "hidden", padding: "5px 20px 5px 10px", backgroundColor:  options.bgColor }).children("a").css({ outline: 0, fontFamily: options.fontFace, color: options.fontColor, textDecoration: "none", fontWeight: "bold", fontSize: "15px" });

		// Rounded Angles
		if(options.angles == false){ $("#up-anchor").css("-moz-border-radius","10px 0 0 10px"); }

		// Shadows
		if(options.shadows == true){ $("#up-anchor a").css("text-shadow","1px 1px "+options.shadowColor+""); }

		// Check Scrolltop And Display
		if(typeof(window.innerWidth) == "number"){
			windowHeight	= window.innerHeight;
		}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
			windowHeight	= document.documentElement.clientHeight;
		}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
			windowHeight	= document.body.clientHeight;
		}
		var bodyHeight	= $("body").outerHeight();
		var maxScroll		= ((bodyHeight - windowHeight) * 50 )/100;
		$(window).scroll(function(){
			if($(window).scrollTop() > maxScroll){ $("#up-anchor").fadeIn(); }else{ $("#up-anchor").fadeOut(); }
		});

		// Up Anchor Click
		$("#up-anchor a").click(function(e){
			e.preventDefault();
			$("html, body").animate({scrollTop:0}, "fast");
		});
	};
})(jQuery);


//Launch me UP !
jQuery(function(){
	jQuery(document).up({
		fontFace: "Arial, sans-serif",
		fontColor: "#004c99",
		bgColor: "#ccc",
		angles: false,
		shadows: false,
		text: "Haut de page",
		altText: "Retourner en haut de page",
		fontSize: "15px"
	});
});
