$(function(){
	$('.sticky').each(function(){
		var elem = $(this);
		var parent = $(this).parent();
		var dTop = $(this).offset().top;
		var stickyTop = elem.position().top;
		parent.css('position','relative');
		elem.css('position','absolute');
		$(window).scroll(function(){
			if(scrollY()>stickyTop){
				elem.stop().animate({top:scrollY()-stickyTop+40},500)
			} else if(scrollY()<stickyTop){
				elem.stop().animate({top:stickyTop},500)
			} else{
				elem.stop().animate({top:stickyTop},500)
			}
		});
		
		if(scrollY()>stickyTop){
			elem.stop().animate({top:scrollY()-stickyTop+20},500)
		}
		
	});
});


/**
 * Return the position of the top
 **/
function scrollY(){
	srcOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ){
		// Netscape compliant
		srcOfY = window.pageYOffset;
	}else if( document.body && ( document.body.scrollTop ) ){
		// DOM compilant
		srcOfY = document.body.scrollTop;
	}else if( document.documentElement && ( document.documentElement.scrollTop ) ){
		// DOM compilant
		srcOfY = document.documentElement.scrollTop;
	}
	return srcOfY;
}
