function worklist() {
	var toLoad = 3;
	var top = 0;
	var step = 0;
	var minTop = 0;
	var maxTop = 0;
	var targetTop = 0;
	var process = false;
	var canMaximize = false;
	var viewportH = 338; //$("#animation").innerHeight();
	$("#worklist").css("width", $("#animation").width()-40);

	$("#down").click(
		function () {
			if (parseInt($("#worklist").css("top")) == minTop) return;
			if (process) return;
			/* если список стоит берем его положение и отнимаем шаг скролла */
			if (!process) {
				oldTop = parseInt($("#worklist").css("top"));
				targetTop = oldTop - step;
			}
			else {
				targetTop = targetTop - step;
			}
			if (targetTop < minTop) {
				targetTop = minTop;
				return;
			}
			$("#worklist").animate({"top": targetTop + "px"}, function() {
					process = false;
					if ( parseInt($("#worklist").css("top")) != maxTop ) {
						$("#up").removeAttr("class").animate({"opacity" : 1}, 300 );
					}
					if ( parseInt($("#worklist").css("top")) == minTop ) {
						$("#down").addClass("inactive").animate({"opacity" : 0.3}, 300 );
					}
				});
			process = true;
		}
	);

	$("#up").click(
		function () {
			if ( parseInt($("#worklist").css("top")) == maxTop ) return;
			if (process) return;
			if (!process) {
				oldTop = parseInt($("#worklist").css("top"));
				targetTop = oldTop + step;
			}
			else {
				targetTop = targetTop + step;
			}
			if (targetTop > maxTop) {
				targetTop = maxTop;
				return;
			}
			$("#worklist").animate({"top": targetTop + "px"}, function() {
					process = false;
					if ( parseInt($("#worklist").css("top")) == maxTop ) {
						$("#up").addClass("inactive").animate({"opacity" : 0.3}, 300 );
					}
					if ( parseInt($("#worklist").css("top")) != minTop ) {
						$("#down").removeAttr("class").animate({"opacity" : 1}, 300 );
					}
				});
			process = true;
		}
	);

	$("#btnMaximize").click(
		function() {
			if (process || !canMaximize) return;
			oldTop = parseInt($("#worklist").css("top"));
			$("#btnMinimize").removeAttr("class");
			$("#btnMaximize").addClass("selected");
			$("#worklist").animate({"top": "0px", "duration": 500}, function(){  });
			$("#animation").animate({"height": $("#worklist").outerHeight( {margin: true} ) + "px", "duration": 1000}, function(){process = false});
			$("#down, #up").hide();
			process = true;
			return false;
		}
	);

	$("#btnMinimize").click(
		function() {
			if (process) return;
			$("#btnMaximize").removeAttr("class");
			$("#btnMinimize").addClass("selected");
			$("#animation").animate({"height": viewportH + "px", "duration": 500}, function(){  });
			$("#worklist").animate({"top": oldTop+"px", "duration": 1000}, function(){
				process = false;
				$("#down, #up").show();
			});
			process = true;
			return false;
		}
	);

	$.get(
		document.location.href.substring(0, document.location.href.indexOf("?"))+"?server_server=give_me_a_bit_images",
		{},
		function (responce, textStatus) {
			$("#worklist").append($(responce)).find("IMG").load(
				function(){
					toLoad--;
					if (toLoad == 0) {
						$.get(
							document.location.href.substring(0, document.location.href.indexOf("?"))+"?server_server=give_me_many_images",
							{},
							function(responce2, textStatus2) {
								$("#worklist").append(responce2);
								$("#down").removeAttr("class").animate({"opacity" : 1}, 300 );
								var count = $("#worklist > .img_item").length;
								step = viewportH;
								Math.ceil(count / 3);
								minTop = -1*(Math.ceil(count / 3) * viewportH - step);
								canMaximize = true;
							}
						);
						$("#up, #down").addClass("inactive").css("opacity", 0.3).show();
					}
				});
		},
		"html"
	);
}


//main
$(worklist);
