$(window).load(function() {	
	var act='';
	var h_box=479;
	var h_cont;
	var end=true;
	
	$('#menu dd').css({display:'none', height:'0'});
	$('#menu dd').each(function(num){
		$(this).data({num:num})
	})
	if (location.hash.slice(0,3)=='#!/') {
		page=location.hash.slice(3);
		open_page('#'+page, true);
	}
	if ((location.hash=='#')||(location.hash=='')) {
		open_page('', false);
	}
	$('a').click(function(){
		if ($(this).attr('href').slice(0,3)=='#!/') {
			if (end) {
				end=false;
				page=$(this).attr('href').slice(3);	
				open_page('#'+page, true);
				return false;
			}
		}
	})
	function open_page(page, fl){
		if (act==page) {fl=false}
		if (page=='#page_Home') {fl=false}
		if (!fl) {
			location.hash='';
			h_cont=250;
			$('#footer_menu li a').removeClass('active');
			$('#footer_menu li').eq(0).find('a').addClass('active');
			$('#menu dt img').stop().animate({rotate:'0deg'});
			$('#menu dd').stop().animate({height:'0'},800, 'easeOutCirc',function(){
				$(this).css({display:'none'});
				act='';
				end=true;
			})
		} else {
			h_cont=730;
			location.hash='#!/'+page.slice(1);
			$(page).css({display:'block'});
			$('#footer_menu li a').removeClass('active');
			$('#footer_menu li').eq(($(page).data('num'))+1).find('a').addClass('active');
			$('#menu dt img').stop().animate({rotate:'0deg'});
			$('#menu dt img').eq($(page).data('num')).stop().animate({rotate:'-90deg'});
			if ((act=='')) {
					$(page).stop().animate({height:h_box},800,'easeOutCirc' , function(){
						act=page;
						end=true;
					});
			} else {
				$(act).stop().animate({opacity:'0'}, function(){})
				$(act).stop().animate({height:'0'},{duration:800 , easing:'easeOutCirc', step:function(now){
					$(page).css({height:h_box-now})										  
				}, complete:function(){
					$(this).css({display:'none'});
					act=page;
					end=true;
				}})
			}
		}
	}
	setHeight();
	h=new_h;
	var h_cont_new;
	center_box();
	function setHeight(){
		new_h=$(window).height();
	}
	setInterval(setNew,60);
	function setNew(){
		setHeight();
		if ((h!=new_h)||(h_cont_new!=h_cont)) {
			h=new_h;
			center_box();
		}
	}
	function center_box(){
		if ((h-250)>h_cont) {
			m_top=~~((h-250-h_cont)/2);
		} else m_top=0
		$('#content').stop().animate({marginTop:m_top},1000, 'easeOutCirc');
		h_cont_new=h_cont;
	}
})
