var scroll = null;
var mscroll = null;

$(document).ready(function()
	{
		$(document).pngFix();

		$("#short").css({opacity: 0}).show();
		$("#book").css({backgroundPosition: '0px 0px'});
		$("#comments").hide();
		$("#opacity").css({opacity: '0.85'});
		if (document.getElementById('poetry').clientHeight > 640) {$("#down").addClass("visible");}

if ($('#short')[0]) {
		$("#contents").mouseover(function()
			{
				stopAnimate();
				$("#addcomment").hide();
				$('#book').animate({backgroundPosition: '(0px 0px)'});
				$('#contents').animate({width: '414px'});
				$('#hider').animate({left: '554px'});
				$('#pn').animate({left: '654px'});
				$('#up').animate({left: '554px'});
				$('#down').animate({left: '554px'});
				$("#short").animate({opacity: 0}, 200);
				$("#full").animate({opacity: 1}, 1000);
		  });

		$("#contents").mouseout(function()
			{
				stopAnimate();
				$('#book').animate({backgroundPosition: '(-274px 0px)'});
				$('#contents').animate({width: '140px'});
				$('#hider').animate({left: '280px'});
				$('#pn').animate({left: '380px'});
				$('#up').animate({left: '280px'});
				$('#down').animate({left: '280px'});
				$("#full").animate({opacity: 0}, 200);
				$("#short").animate({opacity: 1}, 1000);
				$("#book").queue(function ()
					{
						$("#addcomment").show();
						$(this).dequeue();
					});
		  });
}

		$("#up").mouseover(function()
			{
				if (!scroll) scroll = setInterval(function()
					{
						var top = document.getElementById('page').scrollTop;
						document.getElementById('page').scrollTop = document.getElementById('page').scrollTop - 7;
						checkScroll(top);
					}, 25);
		  });

		$("#down").mouseover(function()
			{
				if (!scroll) scroll = setInterval(function()
					{
						var top = document.getElementById('page').scrollTop;
						document.getElementById('page').scrollTop = document.getElementById('page').scrollTop + 7;
						checkScroll(top);
					}, 25);
		  });

		$("#up").mouseout(function()
			{
				if (scroll) {clearInterval(scroll); scroll = null}
		  });

		$("#down").mouseout(function()
			{
				if (scroll) {clearInterval(scroll); scroll = null}
		  });







		$("#mup").mouseover(function()
			{
				if (!mscroll) mscroll = setInterval(function()
					{
						var top = document.getElementById('mhider').scrollTop;
						document.getElementById('mhider').scrollTop = document.getElementById('mhider').scrollTop - 7;
						checkMenuScroll(top);
					}, 25);
		  });

		$("#mdown").mouseover(function()
			{
				if (!mscroll) mscroll = setInterval(function()
					{
						var top = document.getElementById('mhider').scrollTop;
						document.getElementById('mhider').scrollTop = document.getElementById('mhider').scrollTop + 7;
						checkMenuScroll(top);
					}, 25);
		  });


		$("#mup").mouseout(function()
			{
				if (mscroll) {clearInterval(mscroll); mscroll = null}
		  });

		$("#mdown").mouseout(function()
			{
				if (mscroll) {clearInterval(mscroll); mscroll = null}
		  });

		$("#mdown").addClass("visible");











		$("#page").scroll(function()
			{
				checkScroll(10000);
		  });

		$("#addcomment").click(function()
			{
				$("#comments").show();
				$("#letter").css({left: Math.floor(($("body").width() / 2) - 271) + 'px'});
				var lh = ($("#letter").height() + 40); if (lh < 1234) {lh = 1234;}
				$("#opacity").css({height: lh + 'px'});
			});

		$("#viewcommentlink").click(function()
			{
				$("#comments").show();
				$("#letter").css({left: Math.floor(($("body").width() / 2) - 271) + 'px'});
				var lh = ($("#letter").height() + 40); if (lh < 1234) {lh = 1234;}
				$("#opacity").css({height: lh + 'px'});
			});

		$("#addcommentlink").click(function()
			{
				$("#comments").show();
				$("#letter").css({left: Math.floor(($("body").width() / 2) - 271) + 'px'});
				var lh = ($("#letter").height() + 40); if (lh < 1234) {lh = 1234;}
				$("#opacity").css({height: lh + 'px'});
			});

		$("#comments").click(function(event)
			{
				if (event.target.id == "opacity")
					{
						$("#comments").queue(function ()
							{
								$(this).hide();
								$(this).dequeue();
							});
					}
			});

	});

function stopAnimate()
	{
		$('#book').stop();
		$("#contents").stop();
		$('#hider').stop();
		$('#mhider').stop();
		$('#pn').stop();
		$('#up').stop();
		$('#down').stop();
		$('#mup').stop();
		$('#mdown').stop();
		$('#full').stop();
		$('#short').stop();
	}

function checkScroll(top)
	{
		$("#up").addClass("visible");
		$("#down").addClass("visible");
		if (top == document.getElementById('page').scrollTop)
			{
				$("#up").addClass("visible");
				$("#down").removeClass("visible");
			}
		if (document.getElementById('page').scrollTop == 0)
			{
				$("#down").addClass("visible");
				$("#up").removeClass("visible");
			}
		if (document.getElementById('poetry').clientHeight < 640)
			{
				$("#down").removeClass("visible");
			}
	}

function checkMenuScroll(top)
	{
		$("#mup").addClass("visible");
		$("#mdown").addClass("visible");
		if (top == document.getElementById('mhider').scrollTop)
			{
				$("#mup").addClass("visible");
				$("#mdown").removeClass("visible");
			}
		if (document.getElementById('mhider').scrollTop == 0)
			{
				$("#mdown").addClass("visible");
				$("#mup").removeClass("visible");
			}
		if (document.getElementById('menu').clientHeight < 466)
			{
				$("#mdown").removeClass("visible");
			}
	}


function submitForm()
	{
    var f = "document.form.", o = new Array("name", "email", "comment");
    var w = new Array("Введите, пожалуйста, свое имя.",
                      "Введите, пожалуйста, свой E-mail.",
                      "Это вам не игрушки!",
                      "Мне, кажется, что в поле «E-mail» вы ввели какой-то бред!",
                      "В поле «E-mail» введены недопустимые символы.");
    for (i = 0; i < o.length; i++)
      {
        var e = eval(f + o[i]);
        if (e.value == "") {alert(w[i]); e.focus(); return false}
      }
    var e = eval(f + o[1]);
	  var s = "!#$%&'()*+,/:;<=>?[\]^`{|}~", g = 0, a = 0, d = 0;
    for (i = 0; i < e.value.length; i++)
      {
        var c = e.value.charAt(i); if (c == "@") a++; if (c == ".") d++;
        for (j = 0; j < s.length; j++) {if (c == s.charAt(j)) g = 1}
      }
    if (!((a == 1) & (d >= 1))) g = 2;
    if (g > 0) {alert(w[w.length - g]); e.focus(); return false}
    return true;
	}