I feel like this bit of code could have been written more elegantly, especially with the huge if/else statements. Can somebody help me break this down? It would really help me out in the future.
// Contact
var c = 0;
var contactHeight = $('#contact-keebs').outerHeight();
$('#mail-wrap').click(function (e) {
e.preventDefault();
if (c++ % 2 == 0) {
$('#contact-button').addClass('project-button').css('width', '71px').text('Projects');
$('.mail-icon').attr('src', site.theme_path + '/img/icon-projects.png');
$('#contact-button').shuffleLetters({callback:function(){
if ($(window).scrollTop() != 0) {
$('html, body').animate({
scrollTop : 0
},200, function() {
$('#contact-keebs').fadeIn(200);
$('body').css({
height : contactHeight,
overflow : 'hidden'
});
$('#contact-info, #clients').addClass('animated fadeInUp');
});
} else {
$('#contact-keebs').fadeIn(200);
$('body').css({
height : contactHeight,
overflow : 'hidden'
});
$('#contact-info, #clients').addClass('animated fadeInUp');
}
}
});
} else {
$('#contact-button').removeClass('project-button').css('width', '96px').text('Get in touch');
$('.mail-icon').attr('src', site.theme_path + '/img/icon-contact.png');
$('#contact-button').shuffleLetters({callback:function(){
if ($(window).scrollTop() != 0) {
$('html, body').animate({
scrollTop : 0
},200, function() {
$('#contact-info, #clients').removeClass('animated fadeInUp');
$('body').css({
height : '',
overflow : ''
});
$('#contact-keebs').fadeOut(200);
});
} else {
$('#contact-info, #clients').removeClass('animated fadeInUp');
$('body').css({
height : '',
overflow : ''
});
$('#contact-keebs').fadeOut(200);
}
}
});
}
});
HTML
// Button
<div id="mail-wrap">
<div class="icon-wrap">
<img class="mail-icon" src="img/icon-contact.png" alt="Contact" height="26" width="24">
</div>
<a id="contact-button" href="#">Get in touch</a>
</div>
// Contact section
<div id="contact-keebs">
<span class="contact-overlay"></span>
<div id="contact-wrapper">
<div id="contact-info">
<h1>Title statement</h1>
<h2>Email</h2>
</div>
<div id="clients">
<h2>Clients & Partners</h2>
<ul id="client-list">
<li>Client 1</li>
<li>Client 2</li>
<li>Client 3</li>
<li>Client 4</li>
<li>Client 5</li>
<li>Client 6</li>
<li>Client 7</li>
<li>Client 8</li>
</ul>
</div>
</div>
</div>