$(document).ready(function(){
//	Check scroll
//	if(window.opera){
//		clearInterval(Menu.scrollId);
//		Menu.scrollId = setInterval(function(){scroll(0,0);}, 1);
//	}
//	Bind hash change event
	if(typeof Menu.intervalIds != 'object'){
		Menu.intervalIds = {};
	}
	$(document).bind('hashChange', function(e, newHash){
		if( newHash.length > 0 ) {
			AjE.checkLang();
			Menu.gotoPage(newHash);
		}
	});
	
//	Some hack to remove scrollbar
	$(document.documentElement).css('overflow', 'hidden');
if (document.location.hash.length > 0) {
		AjE.checkLang();
		Menu.showMenuWithContent();
//		Menu.gotoPage(document.location.hash);
	} else {
		var menuClosed = true;
		var menuMinHeight = $("#header-menu").height();
		var winheight = $(window).height();
		var galtop = winheight / 2 - $('#gallery').height() / 2 - 80;
		var studtop = winheight / 2 - $('#studio').height() / 2 + 25;
		$('#gallery, #studio').fadeIn('slow').css('z-index: 100');
		
//		Language select
		$("div.line").mouseover(function(){
			$(this).find('a').css('display','block').click(function(e){
				e.preventDefault();
				var language = $(this).attr('rel');
				var selected = $(this).parent();
//				console.log(selected);
				var id = selected.attr("id");
				var unselected = $("#"+ids[id]);
				if( $.browser != 'mozilla' ) {
					selected.css( 'top', selected.offset().top );
					unselected.css( 'top', unselected.offset().top );
				}
				var small = {};
				small.height = 21;
	//			document.location.hash = '#'+AjE.redirect[id];
				
				var bottom = $(window).height() - unselected.height();
				selected.removeClass('lines').css('background-color', '#000');
				unselected.removeClass('lines').css('background-color', '#000');
				
				/*				Main page animation				*/
				Menu.mainSelect(selected, unselected, language);
			});
		}).mouseout(function(){
			$(this).find('a').unbind().css('display', 'none');
		});
		$("div.line").click( function(e){
			if($(e.target).hasClass("line")){
				$("div").unbind().css('cursor', 'default');
				var selected = $(this);
				var id = selected.attr("id");
				var unselected = $("#"+ids[id]);
				if( $.browser != 'mozilla' ) {
					selected.css( 'top', selected.offset().top );
					unselected.css( 'top', unselected.offset().top );
				}
				var small = {};
				small.height = 21;
	//			document.location.hash = '#'+AjE.redirect[id];
				
				var bottom = $(window).height() - unselected.height();
				selected.removeClass('lines').css('background-color', '#000');
				unselected.removeClass('lines').css('background-color', '#000');
				
				/*				Main page animation				*/
				Menu.mainSelect(selected, unselected, 'ru');
	//			Menu.gotoPage('#'+id);
		//		selected.animate({
		//			top: -big.height.max
		//		}, speed, null, function(){
		//			selected.addClass('line-menu').css({
		//				'background-image':'url(shared/images/'+id+'-big.png)'
		//			});
		//			if(id == 'gallery') {
		//				selected.html(menuHtml);
		//			}
		//			selected.animate({
		//				top: '0'
		//			}, 'slow', null, function(){
		//				selected.hover( 
		//						function() {
		//							selected.animate({
		//								height: big.height.max
		//							}, 500, null, function(){
		//								$('#menu-items').fadeIn('fast', function(){
		//								});
		//							});
		//						},
		//						function() {
		//							selected.stop(true, true).animate({
		//								height: big.height.min
		//								,'background-position': '4.7% 0'
		//							}, 400);
		//							$('#menu-items').css('display', 'none').parent().animate({
		//								height: big.height.min
		//							}, 'fast', null, function(){
		//								$('#menu-items').css('display', 'none');
		//							});
		//						}
		//				);
		//			});
		//		});
		//		unselected.animate({
		//			top:end
		//		}, speed, null, function(){
		//			var demoheight = (id=='studio')?510:521;
		//			var demotop = 65;//(id=='studio')?:;
		////			alert(unselected.offset().top +'='+tmp);
		//			$('.content').css({
		//				'background-image':'url(shared/images/demo-back-'+id+'.png)'
		//				,'top': demotop
		//				,'height':demoheight
		//				}).fadeIn(1500);
		//			unselected.addClass('line-bottom').removeAttr('style').css({
		//				'display':'block'
		//				, 'background-image':'url(shared/images/'+unselected.attr('id')+'-small.png)'
		//			}).animate({
		//				bottom: 0
		//			}, 'slow');
		//		});
				}
			});
	}
	/*					End of animation				*/
//       try to decode it: 1041107210731099321076109110881099
});
