$(function(){
	function box_null(){
		$('.box').css({top:'336px', left:'475px', width:'0', height:'0'});
		$('.text').css({display:'none'});
		$('#content > article').css({display:'none'})
		$('#content').find('.box').css({top:'336px', left:'475px', width:'0', height:'0'})
		$('#content').find('.text').animate({opacity:'hide'},0)
	}
	function content_null(){
		$('.box_content').css({display:'none'});
		$('.min_height').css({display:'block'});
	}
	function content_open(){
		$('.box_content').css({display:'block'});
		$('.min_height').css({display:'none'});
	}
	function open_page(){
		$(page).css({display:'block'})
		$(page+' .close img').css({ top:'30px', left:'30px', width:'0', height:'0', zIndex:1})
		$(page+' .box').animate({top:'0', left:'0', width:'950px', height:'671px'},400, 'easeOutQuad', function(){
			$(page).find('.text').stop().animate({opacity:'show'},400, function(){
				$(page+' .close .img').stop().animate({ top:'0px', left:'0px', width:'100%', height:'100%', zIndex:2},400, 'easeOutCirc')
				act=page;
			});
		});
	}
	function active_page(){
		var nav=page.substr(6);
		nav='.nav'+nav;
		$(nav).addClass('active').unbind ('mouseleave', menu_unhover);
		menu_hover.call($(nav));
	}
	content_null();
	box_null();
	var act;
	$('a').click(function(){
		page=$(this).attr('href');
		if (page.substr(page.indexOf('#'),6)=='#page_') {
			
				
			if (act) {
				$('.menu > li, #footer_menu li').removeClass('active').bind ('mouseleave', menu_unhover).mouseleave();
				menu_unhover.call($('.menu > li'));
				active_page()
				if (act!='#page_1') {
					$(act+' .close img').stop().animate({ top:'30px', left:'30px', width:'0', height:'0', zIndex:1},400, 'easeOutCirc')
						$(act).find('.text').stop().animate({opacity:'hide'},400, function(){
							$(act).find('.box').animate({top:'336px', left:'475px', width:'0', height:'0'},400, 'easeOutQuad', function(){
								box_null();
								if (page=='#page_1') {act=page; content_null();} else {	open_page(); content_open();}
							});															   
						});
				} else {if (page=='#page_1') { act=page; content_null();} else {open_page(); content_open();}}
			} else {
				if (page=='#page_1') {
					content_null();
				} else {
					content_open();
				}
				$('header').stop().stop().animate({opacity:'show'},400);
				active_page();
				$('.splash').stop().animate({opacity:'hide'},400);
				if (page=='#page_1') {act=page;} else {	open_page();}
			}
			
				return false;
			}
	})
})
