// JavaScript Document
$(document).ready(function(){
	$('.opts > .pointsbox').each(function(e){
		var thi = $(this);
		thi.mousedown(function(){
			thi[0].sc = 1;
			$(document).mousemove(function(e){
				if (thi[0].sc == 1) {
					var toY = e.pageY-thi.parent().offset().top-5;
					if (toY > thi.parent().find('.libox').height()) { toY = thi.parent().find('.libox').height() } else if (toY < thi.height()) { toY = thi.height() }
					thi.css({top:toY-thi.height()+'px'});
					var roll = (thi.parent().find('.libox ul').height()-thi.parent().find('.libox').height())/(thi.parent().find('.libox').height()-(thi.height()));
					thi.parent().find('.libox').scrollTop((toY-thi.height())*roll);
				}
			});
			return false;
		});
		
		$(document).mousedown(function(){
			thi[0].sc = 0;
		});
		
		$(document).mouseup(function(){
			thi[0].sc = 0;
		});
		
		thi.parents('.opts').hover(function(){
			if (window.addEventListener) { window.addEventListener('DOMMouseScroll', wheel, false); }
			window.onmousewheel = wheel;
			document.onmousewheel = wheel;
		}, function(){if (window.removeEventListener) { window.removeEventListener('DOMMouseScroll', wheel, false); } window.onmousewheel = ''; document.onmousewheel = ''});
		function wheel(event) {
			if(!event) {event = window.event}
			if (event.wheelDelta) {	wheelDelta = -event.wheelDelta/120; } 
			else if (event.detail) { wheelDelta = event.detail/3; }
			var top = parseInt(thi.css('top'));
			if(isNaN(top)) { top = 0; }
			var toY = top+thi.height()+(wheelDelta*3);
			if (toY > thi.parent().find('.libox').height()) { toY = thi.parent().find('.libox').height() } else if (toY < thi.height()) { toY = thi.height() }
			thi.css({top:toY-thi.height()+'px'});
			var roll = (thi.parent().find('.libox ul').height()-thi.parent().find('.libox').height())/(thi.parent().find('.libox').height()-(thi.height()));
			thi.parent().find('.libox').scrollTop((toY-thi.height())*roll);
			if (event.preventDefault)
			{
				event.preventDefault();
			}
			event.returnValue = false;
		}
		
	});
	
	
});
