jQuery(document).ready(function() { 

	var windowHeight = $(window).height();
	var documentHeight = $(document).height();
	var padding = 0;
	var topOffset = 169;
	var footerHeight = 522;
	
	if(documentHeight-topOffset-footerHeight > windowHeight) {
		var stickyHeight = windowHeight;
	} else {
		var stickyHeight = documentHeight-topOffset-footerHeight;
	}

	function scrollSticky(){
	    if($(window).height() >= stickyHeight) {
	        var aOffset = $('#socialbar').offset();
	
	        if($(document).height() - footerHeight - padding < $(window).scrollTop() + stickyHeight) {
	            var top = $(document).height() - stickyHeight - footerHeight - padding;
	            $('#socialbar').attr('style', 'position:absolute; top:'+top+'px; margin-left:720px; height:'+stickyHeight+'px;');
	
	        } else if($(window).scrollTop() + padding > topOffset) {
	            $('#socialbar').attr('style', 'position:fixed; top:'+padding+'px; margin-left:720px; height:'+stickyHeight+'px;');
	
	        } else {
	            $('#socialbar').attr('style', 'position:relative; height:'+stickyHeight+'px;');
	        }
	    }
	}

	$(window).scroll(function(){
	    scrollSticky()
	});
	
});
