if (window.addEventListener) window.addEventListener("load", ONLOAD, false);
else if (window.attachEvent) window.attachEvent("onload", ONLOAD);
else window.onload = ONLOAD;


function ONLOAD () {
	flyMenu();
	$(".left-menu").slideUp(1);
	$(".left-menu:first").slideDown(1);
	$(".left-menu:first").addClass("opened");
	$(".left-menu-mini:first").slideUp(1);
	$(".left-menu-mini:first").addClass("closed");
	
	//Раскрытие меню
	$(".left-menu-mini").click(function () {
		$(".opened").slideUp(800);
		$(".opened").removeClass("opened")
		
		$(".closed").slideDown(100);
		$(".closed").removeClass("closed");
		
		$("#menu"+this.id).slideDown(800);
		$("#menu"+this.id).addClass("opened");
				
		$(this).slideUp(100);
		$(this).addClass("closed");

	});
	
	$(".main-blocks").hide();
	$(".main-blocks:first").show();
	$(".main-blocks:first").addClass("mb-opened");
	
	$(".mainnavigation").click(function() {
		$(".mb-opened").hide();
		$(".mb-opened").removeClass("mb-opened");
		$("#mblock"+this.id).fadeIn();
		$("#mblock"+this.id).addClass("mb-opened");
	});
	
}


function flyMenu() {
	var WIDTH=158;
	var SPEED=2.1;
	var X=0, i=0, child, interval;
	var mainCell=document.getElementById("flyBody");
	var bLeft=document.getElementById("fly-menu-left");
	var bRight=document.getElementById("fly-menu-right");
	if(mainCell && bLeft && bRight) {
	bRight.onmouseover= function () { clearInterval(interval); interval=setInterval(moveleft,20); }
	bRight.onmouseout= function () { clearInterval(interval); }
	bLeft.onmouseover= function () { clearInterval(interval); interval=setInterval(moveright,20); }
	bLeft.onmouseout= function () { clearInterval(interval); }
	}
	
	function moveleft() {
		if(mainCell) {
			X-=SPEED;
			if(X<-WIDTH) {
				X+=WIDTH;
				child=mainCell.firstChild;
				mainCell.removeChild(child);
				mainCell.appendChild(child);
			}
			mainCell.style.left=String(Math.round(X))+"px";
		}
	}
	function moveright() {
		if(mainCell) {
			X+=SPEED;
			if(X>0) {
				X-=WIDTH;
				child=mainCell.lastChild;
				mainCell.removeChild(child);
				mainCell.insertBefore(child,mainCell.firstChild);
			}
			mainCell.style.left=String(Math.round(X))+"px";
		}
	}
}
