// JavaScript Document
/* 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: "#333", angles: false, shadows: true, shadowColor: "#000", 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 10px 5px 5px", backgroundColor:  options.bgColor }).children("a").css({ outline: 0, fontFamily: options.fontFace, fontStyle: "normal", color: options.fontColor, textDecoration: "none", fontWeight: "bold", fontSize: "10px", background: options.bgImage, padding: options.padding });

		// Rounded Angles
		if(options.angles == false){ $("#up-anchor").css("-moz-border-radius","5px 0 0 5px"); }

		// 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: "Trebuchet MS,Arial,Helvetica,sans-serif",
		fontColor: "#fff",
		bgColor: "#125077",
		angles: false,
		shadows: false,
		shadowColor: "#000",
		text: "HAUT",
		altText: "Retourner en haut de page",
		bgImage:"url(http://www.golfe-saint-tropez-information.com/templates/Inf/images/suite-contour-haut-blanc.png) center left no-repeat",
		padding: "0px 0px 0px 12px"
	});
});