(function ($) {
	var cmn = mm.extend({
		
		init: function () {
			this.anchor();
		},
		
		anchor: function () {
			$('a[href*=#a_]').click(this.bind(function (a) {
				this.scroll($($(a).attr('href')));
				return false;
			}));
			$('a[href*=#frm-header]').click(this.bind(function (a) {
				this.scroll($($(a).attr('href')));
				return false;
			}));
			$('a[href*=#header]').click(this.bind(function (a) {
				this.scroll($($(a).attr('href')));
				return false;
			}));
		},
		
		scroll: (function () {
			var timer;
			var clear = function () {
				if (timer)
					clearInterval(timer);
				timer = null;
			};
			
			return function (el, fn) {
				clear();
				var content_top = $('body').position().top;
				var from = $(window).scrollTop();
				var to	 = $(el).position().top;
				if(from < to) to += content_top;
				if(el == 'a#pagetop') to = 0;
				
				timer = setInterval(function () {
					var move = Math.floor((from - to) / 3);
					if (!move && (from != to))
						move = (from > to) ? 1 : -1;
					from -= move;
					if (from == to) {
						if (fn)
							fn.call(this);
						clear();
					}
					else
						$(window).scrollTop(from);
				}, 50);
				
				var d = document;
				if (/Firefox/.test(navigator.userAgent))
					d.body.addEventListener('DOMMouseScroll', function () {
						clear();
						this.removeEventListener('DOMMouseScroll', arguments.callee, false);
					}, false);
				else
					$(d).one('mousewheel', clear);
				
				return false;
			};
		})()
		
	});
	
	$(cmn.bind(cmn.init));
})(jQuery);