$(document).ready(function() {
  $('#header a').click(function() {

    stat = $(this).attr('status');
    $('#header a').each(function() { $( $(this).attr('href') ).hide(); });
    $('a[status=1]').attr('status', '0');

    if (stat != '1') { 
	$(this).attr('status', '1');
	$( $(this).attr('href') ).fadeIn();
    }

    if ($('a[status=1]').length == 0) {  
      $('#header-background').animate({'marginTop': '10em'});
    } else {
      $('#header-background').animate({'marginTop': '2em'});
    }

    return false;
  });
}); // end document.ready

function showPortfolioItem(item) {
    $('#portfolio .portfolioitem').hide();
    $('#portfolio_'+item).fadeIn();
}

function doPost() {
  
    $('.success, .failure, .datafail').hide();

    state = true;

    if ($('input[name=name]').val() == '') { state = false; }
    if (/^([a-zA-Z0-9_\.\-+])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($('input[name=email]').val()) == false) { state = false; }
    if ($('textarea').val() == '') { state = false; }
	
    if (state == true) {

	$.post('/post.php', $('#contact').serialize(), function(res, out) {
	    if (res == 'true') { $('.success').fadeIn(); $('#dopost').attr('disabled', 'disabled'); } else { $('.failure').fadeIn(); }
	}, 'text');

    } else {
	$('.datafail').fadeIn();
    }

    return false;
}
