function preload(images) {
	if (typeof document.body == "undefined") return;
	try {

		var div = document.createElement("div");
		var s = div.style;
			s.position = "absolute";
		s.top = s.left = 0;
		s.visibility = "hidden";
		document.body.appendChild(div);
		div.innerHTML = "&lt;img src=\"" + images.join("\" /&gt;&lt;img src=\"") + "\" /&gt;";
		var lastImg = div.lastChild;
		lastImg.onload = function() { document.body.removeChild(document.body.lastChild); };
	 }
	 catch(e) {
		// Error. Do nothing.
	}
}

$(document).ready(function(){
	$('#menu div.menu').hover(
		function(){
			var i = 0;
			$(this).find('div.sub_menu div').each(function(){
				var el = $(this);
				//debugger;
				clearTimeout(el.data('timer'));
				el.data('timer', setTimeout(function(){el.fadeIn(200);}, i * 60));
				i++;
			});
		},
		function(){
			var i = $(this).find('div.sub_menu div').length;
			$(this).find('div.sub_menu div').each(function(){
				var el = $(this);
				//debugger;
				clearTimeout(el.data('timer'));
				el.data('timer', setTimeout(function(){el.fadeOut(200);}, i * 60));
				i--;
			});
		}
	);
	
	preload(new Array('/des/spoiler_arrow_up.png'));
	
	$('.content .spoiler .spoiler_head').click(function(){
		$(this).next().slideToggle('normal', function(){
			alignBlocks();
			if($(this).is(':visible'))
				$(this).prev().find('img').attr('src', '/des/spoiler_arrow_up.png');
			else
				$(this).prev().find('img').attr('src', '/des/spoiler_arrow_down.png');
		});
	});
});

$(window).scroll(function() {
	var scroll = $(document).scrollTop();
	var offset = $('#catalog').offset().top + $('#catalog').height();
	
	if (scroll > offset && !$('#to_top').is(':visible'))
	{
		$('#to_top').css('left', $('#middle').offset().left + 115);
		$('#to_top').fadeIn('fast');
	}
	
	if (scroll <= offset && $('#to_top').is(':visible'))
	{
		$('#to_top').hide();
	}
});

$(window).resize(function(){
	if ($('#to_top').is(':visible'))
		$('#to_top').css('left', $('#middle').offset().left + 115);
});

function toTop()
{
	$("body:not(:animated)").animate({ scrollTop: 0}, 1000);
	$("html").animate({ scrollTop: 0}, 500);
}


