(function ($) {
var self = mm.common = mm.extend({
	
/* ===============================	 */
	
	init: function () {
		self.hover('active');
		self.anchor();
	},
	
/* ===============================	 */
	
	hover: function (className) {
		$('.hover a').mouseover(this.bind(function (a) {
			$(a).parent().css({backgroundPosition: '0px -' + $(a).parent().height() + 'px'});
		})).mouseout(this.bind(function (a) {
			$(a).parent().css({backgroundPosition: '0px 0px'});
		}));
		
		if (className) {
			var hover  = $('.' + className);
			var images = [];
			this.each(hover, function (_hover) {
				_hover = $(_hover);
				var imgObj = new Image();
				switch (_hover.get(0).nodeName) {
					case 'A':
					imgObj.src = _hover.find('img').attr('src').replace(/(\.gif|\.jpg)$/, '_on$1');
					break;
					case 'IMG':
					imgObj.src = _hover.attr('src').replace(/(\.gif|\.jpg)$/, '_on$1');
					break;
				}
				images.push(imgObj);
			});
			
			hover.mouseover(this.bind(function (_hover) {
				_hover = $(_hover);
				
				switch (_hover.get(0).nodeName) {
					case 'A':
					_hover.find('img').attr('src', _hover.find('img').attr('src').replace(/(\.gif|\.jpg)$/, '_on$1'));
					break;
					case 'IMG':
					_hover.attr('src', _hover.attr('src').replace(/(\.gif|\.jpg)$/, '_on$1'));
					break;
				}
			})).mouseout(this.bind(function (_hover) {
				_hover = $(_hover);
				
				switch (_hover.get(0).nodeName) {
					case 'A':
					_hover.find('img').attr('src', _hover.find('img').attr('src').replace(/_on(\.gif|\.jpg)$/, '$1'));
					break;
					case 'IMG':
					_hover.attr('src', _hover.attr('src').replace(/_on(\.gif|\.jpg)$/, '$1'));
					break;
				}
			}));
		}
	},
	
/* ===============================	 */
	
	anchor: function () {
		$('a[href*=#a_]').click(this.bind(function (a) {
			self.scroll('a' + $(a).attr('href'));
			return false;
		}));
		$('a[href*=#pagetop]').click(this.bind(function (a) {
			self.scroll('a' + $(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 = $('#frm-contents').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;
		};
	})()
});

/* ===============================	 */

$(function () {
	mm.common.init();
});
})(jQuery);

/* ===============================	 */