var ifxExpanded = false;

$(document).ready(function() {
	$('.ifxElementButton').mousedown(function() {
		var buttonName = $(this).attr('id');
		
		if (ifxExpanded == false) { // We're opening a tab
			$('body').animate({paddingTop:150}, 'normal');
			$('.ifxElementButton').animate({top:150}, 'normal');
			if (buttonName == 'departmentsButton') {
				$('#departmentsElement').show().animate({top:0}, 'normal',
					function() { ifxExpanded = buttonName; });
				$('#topicsButton,#aboutButton').fadeTo('normal', 0.5);
			} else if (buttonName == 'topicsButton') {
				$('#topicsElement').show().animate({top:0}, 'normal',
					function() { ifxExpanded = buttonName; });
				$('#departmentsButton,#aboutButton').fadeTo('normal', 0.5);
			} else if (buttonName == 'aboutButton') {
				$('#aboutElement').show().animate({top:0}, 'normal',
					function() { ifxExpanded = buttonName; });
				$('#departmentsButton,#topicsButton').fadeTo('normal', 0.5);
			}
		
		} else if (ifxExpanded == buttonName) { // We're closing a tab
			$('body').animate({paddingTop:0}, 'normal');
			$('.ifxElementButton').animate({top:0}, 'normal');
			if (buttonName == 'departmentsButton') {
				$('#departmentsElement').animate({top:-150}, 'normal',
					function() { ifxExpanded = false; });
				$('#topicsButton,#aboutButton').fadeTo('normal', 1.0);
			} else if (buttonName == 'topicsButton') {
				$('#topicsElement').animate({top:-150}, 'normal',
					function() { ifxExpanded = false; });
				$('#departmentsButton,#aboutButton').fadeTo('normal', 1.0);
			} else if (buttonName == 'aboutButton') {
				$('#aboutElement').animate({top:-150}, 'normal',
					function() { ifxExpanded = false; });
				$('#departmentsButton,#topicsButton').fadeTo('normal', 1.0);
			}

		} else { // We're switching tabs
			ifxExpanded = buttonName;
			if (buttonName == 'departmentsButton') {
				$('#departmentsElement').css({top:0}).hide().fadeIn('normal');
				$('#topicsElement,#aboutElement').hide().css({top:-150});
				$('#departmentsButton').fadeTo('normal', 1.0);
				$('#topicsButton,#aboutButton').fadeTo('normal', 0.5);
			} else if (buttonName == 'topicsButton') {
				$('#topicsElement').css({top:0}).hide().fadeIn('normal');
				$('#departmentsElement,#aboutElement').hide().css({top:-150});
				$('#topicsButton').fadeTo('normal', 1.0);
				$('#departmentsButton,#aboutButton').fadeTo('normal', 0.5);
			} else if (buttonName == 'aboutButton') {
				$('#aboutElement').css({top:0}).hide().fadeIn('normal');
				$('#departmentsElement,#topicsElement').hide().css({top:-150});
				$('#aboutButton').fadeTo('normal', 1.0);
				$('#departmentsButton,#topicsButton').fadeTo('normal', 0.5);
			}
		}
	});
});

