/**
* 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: "UP!", 
            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: "10px 20px 10px 20px", 
            backgroundColor: options.bgColor
        }).children("a").css({
            outline: 0, 
            fontFamily: options.fontFace, 
            fontStyle: "italic", 
            color: options.fontColor, 
            textDecoration: "none", 
            fontWeight: "bold", 
            fontSize: "18px"
        });

        // Rounded Angles
        if(options.angles == false){
            $("#up-anchor").css("border-radius","10px 0 0 10px");
        }
        if(options.angles == false){
            $("#up-anchor").css("-moz-border-radius","10px 0 0 10px");
        }
        if(options.angles == false){
            $("#up-anchor").css("-webkit-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) * 30 )/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: "Helvetica, Arial, sans-serif",
        fontColor: "#fff",
        bgColor: "#333",
        angles: false,
        shadows: true,
        shadowColor: "#000",
        text: "Remonter",
        altText: "Retourner en haut de la page"
    });
});
