/*
Author: Marco Chiodetti
Email: devilmark84 at hotmail dot it

Require jQuery and the scrollTo plugin!

/////////////////////////////////INSTRUCTIONS//////////////////////////////////////////////
    Create a div at the top of the body:
    <div id="top"></div>
    
    Add this code to the bottom of the body:
    <div id="back_to_top">
        <a href="#top"><img src="images/back_to_top.gif" alt="Torna in cima" title="Torna in cima" /></a>
    </div>
    
    Add this rule to the css file:
    #back_to_top { width: 50px; height: 50px; position: absolute; top: 0px; left: 85%; display: none; }
/////////////////////////////////INSTRUCTIONS//////////////////////////////////////////////

Enjoy!

*/


jQuery(document).ready(function() {
    //CONFIGURATION AREA
    $scroll_speed = 1000;        //time in milliseconds to reach the anchor
    //END OF CONFIGURATION AREA
    /////////////////////////DO NOT EDIT BELOW THIS LINE!!!////////////////////////////////
    
	jQuery("body").attr("id","top").append("<div id='back_to_top' style='width: 50px; height: 50px; position: absolute; top: 0px; right: 50px; display: none;'><a href='#top'><img src='http://www.vivi-pisa.it/images/common/back_to_top.gif' alt='Torna in cima' title='Torna in cima' /></a></div>");
    
    jQuery("a[href*='#']:not(a[href='#'])").click(function() {
        ancora = jQuery(this).attr("href");
        separato = ancora.split("#");
        jQuery.scrollTo("#"+separato[1],$scroll_speed);
        return false;
    });
    
    jQuery(window).scroll(function() {
        val = parseInt(jQuery(document).scrollTop()) + parseInt(jQuery(window).height()) - 60;
        jQuery("#back_to_top").css({ "top": val }).show();
        if (jQuery(document).scrollTop() == 0) jQuery("#back_to_top").hide();
        //else jQuery("#back_to_top").show();
    });
    
});