$(document).ready(function(){
	$('#item_about').click(function(){
		hide_items();
		$('.menu li').each(function(index){
			$(this).removeClass('active');
		});
		if ($('.aboutcontent').css('display') == 'none')
		{
			
			$('#item_about').addClass('active');
			show_about();
		}
		else
		{
			hide_about();
		}
	});
	
	$('#item_projects').click(function(){
	
		hide_items();
		$('#item_projects').addClass('active');
	});
	
	$('#item_contact').click(function(){
		hide_items();
		
		$('.menu li').each(function(index){
			$(this).removeClass('active');
		});
		
		if ($('.contactcontent').css('display') == 'none')
		{
			$('#item_contact').addClass('active');
			show_contact();
		}
		else
		{
			hide_contact();
		}
	});
	
	var hash = document.location.hash;
	if (hash == "#about")
	{
		$('#item_about').addClass('active');
		show_about();
	}
	else if (hash == "#contact")
	{
		$('#item_contact').addClass('active');
		show_contact();
	}
});

function hide_items()
{
	if ($('.aboutcontent').css('display') == 'block')
	{
		hide_about();
	}
	
	if ($('.contactcontent').css('display') == 'block')
	{
		hide_contact();
	}
}

function show_about()
{
	$('.projects').animate({marginTop: 15}, 100);
	$('#item_contact').animate({marginTop: 392}, 500);
	$('.maincontent').animate({
		height: 0,
		opacity: 0
	}, 500, function(){
		$('.maincontent').css({display: 'none'});
	});
	
	$('.aboutcontent').css({display: 'block'}).animate({
		height: 424,
		opacity: 1
	}, 500);
	
	$('.we').delay(500).animate({
		opacity: 1
	}, 1000);
	
	if ($('#item_projects').hasClass('active'))
		setTimeout("$('#item_projects').removeClass('active');", 1000);
		
	$('.call').delay(1000).animate({opacity: 1}, 500);
}

function hide_about()
{
	$('.aboutcontent').animate({
		height: 0,
		opacity: 0
	}, 500, function(){
		$(this).css({display: 'none'});
		
		$('.main div').css({
			opacity: 0
		});
		$('.maincontent').css({
			height: 211,
			opacity: 1,
			display: 'block'
		});
		
		var time = 200;
		$('.main div').each(function(index){
			setTimeout("show_main_item('"+$(this).attr('id')+"')", time+=100);
		});
		
		$('#item_about').removeClass('active');
		//$('#item_projects').addClass('active');
	});
			
	$('#item_contact').animate({marginTop: 0}, 500);
	$('.projects').animate({marginTop: 20}, 100);
}


function show_contact()
{
	
	$('.maincontent').animate({
		height: 0,
		opacity: 0
	}, 500, function(){
		$('.maincontent').css({display: 'none'});
		$('.contactcontent').css({display: 'block'}).animate({
			height: 290,
			opacity: 1
		}, 500);
	});
	
	if ($('#item_projects').hasClass('active'))
		setTimeout("$('#item_projects').removeClass('active');", 1000);
		
	$('.call').delay(1000).animate({opacity: 1}, 500);
}

function hide_contact()
{
	$('.contactcontent').animate({
		height: 0,
		opacity: 0
	}, 500, function(){
		$(this).css({display: 'none'});
		
		$('.main div').css({
			opacity: 0
		});
		$('.maincontent').css({
			height: 211,
			opacity: 1,
			display: 'block'
		});
		
		var time = 200;
		$('.main div').each(function(index){
			setTimeout("show_main_item('"+$(this).attr('id')+"')", time+=100);
		});
		
		$('#item_contact').removeClass('active');
	});
	
}
