$(document).ready(function(){
    hmain = $("#main").height()-50;
    $("#demo").css({'height' : hmain});
    
    $("img.down").mouseenter(function(){
		t = $("#in").position().top; //0  -1000
		if (t<0) { t = t * (-1); }
		h = $("#in").height(); //1000
		H = $("#demo").height();  //200
		z = h - H - t + 15;
		if (z<0) { z = 0;}
		if ((H + t) > h) {
				z = 0;
			}
		time = z*8;
		$("#in").animate({ "top": "-="+z+"px" }, time );
    });

    $("img.down").mouseleave(function(){
      $("#in").stop();
    });
    $("img.up").mouseenter(function(){
		t = $("#in").position().top; //0
		if (t<0) { t = t * (-1); }
		H = $("#demo").height();  //300
		z = t;
		
		time = z*8;
		$("#in").animate({ "top": "+="+z+"px" }, time );
    });

    $("img.up").mouseleave(function(){
      $("#in").stop();
    });
// 2
    wt1 = $("#t1").width();
    $("#in2").css({'width' : wt1});
    $("img.left").mouseenter(function(){
		t = $("#in2").position().left; //0  -1000
		if (t<0) { t = t * (-1); }
		h = $("#in2").width(); //1000
		H = $("#demo2").width();  //200
		z = h - H - t + 15;
		time = z*5;
		$("#in2").animate({ "left": "-="+z+"px" }, time );
    });

    $("img.left").mouseleave(function(){
      $("#in2").stop();
    });
    
    $("img.right").mouseenter(function(){
		t = $("#in2").position().left; //0
		if (t<0) { t = t * (-1); }
		H = $("#demo2").width();  //300
		z = t;
		
		time = z*5;
		$("#in2").animate({ "left": "+="+z+"px" }, time );
    });

    $("img.right").mouseleave(function(){
      $("#in2").stop();
    });

	$("#demo").mousewheel(function(event, delta) {
		var dir = delta > 0 ? 'Up' : 'Down', vel = Math.abs(delta);
		t = $("#in").position().top; //0  -1000
		if (t<0) { t = t * (-1); }
		h = $("#in").height(); //1000
		H = $("#demo").height();  //200
		if (delta < 0) {
			// вниз
			z = 10;
			xx = '-';
			if ((H + t) > h) {
				z = 0;
			}
		}
		if (delta > 0) {
			// вверх
			z = 10;
			xx = '+';
			if ($("#in").position().top >= 0) {
				z = 0;
			}
		}
		time = z*8;
		$("#in").animate({ "top": xx+"="+z+"px" }, 10 );
		return false;
	});
	$("#demo2").mousewheel(function(event, delta) {
		var dir = delta > 0 ? 'Up' : 'Down', vel = Math.abs(delta);
		t = $("#in2").position().left; //0  -1000
		if (t<0) { t = t * (-1); }
		h = $("#in2").width(); //1000
		H = $("#demo2").width();  //200
		if (delta < 0) {
			// вниз
			z = 10;
			xx = '-';
			if ((H + t) > h) {
				z = 0;
			}
		}
		if (delta > 0) {
			// вверх
			z = 10;
			xx = '+';
			if ($("#in2").position().left >= 0) {
				z = 0;
			}
		}
		time = z*8;
		$("#in2").animate({ "left": xx+"="+z+"px" }, 10 );
		return false;
	});

	});




