// JavaScript Document
var mover;
var speed=10;
$(document).ready(function(){
	$("#mover",".scrollBox").mousedown(function(e){
		mover=$(this);
		var y=e.pageY;
		mover.attr("cY", Math.round(y-$(this).offset().top));
		mover.attr("pY", Math.round($(this).parent().offset().top));
		return false;
	});
	$("#main").mousemove(function(e){
		if(mover){
			var y=e.pageY;
			var mY=y-mover.attr("pY")-mover.attr("cY");
			if(mY<0) mY=0;
			if(mY>602) mY=602;
			$(".text").css("top",Math.round(mY/602*(710-$(".text").height()))+"px");
			mover.css("top",mY+"px");
		}
	});
	$("#main").mouseup(function(){
		mover=null;
	});
	$(window).mouseup(function(){
		mover=null;
	});
	mov=$("#mover",".scrollBox");
	cont=$(".text");
	if(cont.height()>710 && mov.length){
		mov.show();
		cont.attr("mS",710-cont.height());
		cont.bind("mousewheel",function(event, delta,dx,dy) {
			y=parseInt($(this).css("top"));
			delta=dy;
			if(delta>0)
				$(this).css("top", ((y+delta)>-0)?(-0):(y+delta)+"px");
			else
				if((y+delta)<parseInt($(this).attr("mS")))
					$(this).css("top", $(this).attr("mS")+"px");
				else
					$(this).css("top", (y+delta)+"px");
			y=$(this).attr("mS")!=0 ? parseInt($(this).css("top"))/$(this).attr("mS") : 0;
			y2=y*602;
			$("#mover").css("top", y2+"px");
			event.stopPropagation();
			event.preventDefault();
			return false;
		});
	}else{
		mov.hide();	
	}
	$(".winBg").click(function(){
		$(".winBg").fadeOut();
		$(".orderBox").hide();
	});
	$(".order").click(function(){
		var tov=$(this).parent().parent().parent().prev().html();
		$(".winBg").fadeIn(function(){
			$(".orderBox").find('h2').html("Товар: "+tov);
			$(".orderBox").find("input[name='item']").val(tov);
			$(".orderBox").show();
		});	
		return false;
	});
});
