(function($) {
	$.fn.sliderMenu = function(options) {
	
		var defaults = {
			speed: 500,
			easing: 'swing'
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var obj = $(this);
			obj.css({
				display: 'block'
			});
			
			var menuItems = $("li.slider_menu_list").size();
			var menuItemWidth = $("li.slider_menu_list").width();
			var menuItemHeight = $("li.slider_menu_list").height();
			var menuWidth = menuItems * menuItemWidth;
			var menuHeight = menuItems * menuItemHeight;
			var inactiveMargin, bodyHeight, browserWidth, browserHeight, cursorX, cursorY, move, offset;
			
			obj.css({
				display: 'none'
			});	
				
			$('#menu').hover(function() {
				browserHeight = $(window).height();

				obj.find("ul").css({
					height: menuHeight+"px",
					width: menuItemWidth+"px"
				}).end()
				.css({
					top: 0,
					right: 0,
					height: browserHeight+"px"
				});

				if(obj.is(':hidden')) { obj.animate({width: 'show'}, options.speed, options.easing, 
					function() {
						$(document).mousemove(function(e){
							bodyHeight = $(document).height();
							browserWidth = $(window).width();
								
							cursorX =  e.pageX;
							cursorY =  e.pageY;
		
							offset = obj.offset();
							inactiveMargin = 100;
							move = (cursorY - offset.top) * ((menuHeight + 2 * inactiveMargin) - browserHeight) / browserHeight - inactiveMargin ;
							obj.scrollTop(move);					
						});
					}); 
				}
			});

			obj.mouseleave(function() {
				obj.animate({width: 'hide'}, options.speed, options.easing);
			});
		});
	};
})(jQuery)
