jQuery(document).ready(function(){
 
	jQuery('#scrolltop').stop().animate({top:0},1000,'swing');

	var selectorA = "#scrolltop";
	
	var parentX = jQuery(selectorA).parent().position().top;
	
	if(jQuery(window).scrollTop() < parentX) {
		jQuery(selectorA).stop().animate({top:0},750,'swing');
	} else {
  		jQuery(selectorA).stop().animate({top:jQuery(window).scrollTop()-parentX},750,'swing');
	}
	
	jQuery(window).scroll(function(){
		if(jQuery(window).scrollTop() < parentX) {
			jQuery(selectorA).stop().animate({top:0},750,'swing');
		} else {
			jQuery(selectorA).stop().animate({top:jQuery(window).scrollTop()-parentX + 0},750,'swing');
		}
	});

});

function scroll(obj,offset){
	if(location.pathname.replace(/^\//,'')==obj.pathname.replace(/^\//,'') && location.hostname==obj.hostname){
		var jQuerytarget=jQuery(obj.hash);
		jQuerytarget=jQuerytarget.length&&jQuerytarget||jQuery('[name='+obj.hash.slice(1)+']');
		if(jQuerytarget.length){
			var targetOffset=jQuerytarget.offset().top+offset;
			jQuery('html,body').stop().animate({scrollTop:targetOffset},600,'swing');
			return false;
		}
	}
}
