;(function( $ ){
   $.fn.extend({
	   scrollIntoView:function(){
		    //boxmargin = 5;
			s = $(document).scrollTop();
			wh = $(window).height();
			o = this.offset().top;
			h = this.height();
			//o = o - boxmargin
			//h = h + (boxmargin*2);
			t = o-s;
			b = t+h;
			newscrolltop=-1;
			if(t<0){
				//alert('s t ');
				newscrolltop = o;
			}else{
				if(b>wh){
					d = b-wh;
					//alert('d');
					if(d<t){
						//alert('sd'+d);
						newscrolltop = s+d;
					}else{
						//alert('st');
						newscrolltop = o;
					}
				}
			}	
			if(newscrolltop>-1){
				$.scrollTo(newscrolltop,{duration:500,easing:'swing'});
			}

}
   });
})( jQuery );