var showing = -1;

function showExpertiseDetail(id) {
	if (showing == id) {
		hideExpertiseDetail(showing);
		return;
	} else if (showing != -1) {
		$('#expertiseHeader_' + showing).fadeTo(100, 1);
		$('#expertiseHeader_' + id).fadeTo(500, 0.1);
		$('#expertiseDetail_' + showing).fadeOut(250, function() { showing = -1; showExpertiseDetail(id); }); // animate({height: 'hide', paddingTop : 0, paddingBottom: 0 }, function() { showExpertiseDetail(id)});
		return;
	} else {
		$('#expertiseHeader_' + id).fadeTo(500, 0.1);
	}
	$('#expertiseDetail_' + id).fadeIn(250, function() { $('.foldOut').animate({height: 'show', paddingTop : '14pt', paddingBottom : '14pt', marginBottom: '14pt'}); });
	
	// $('#expertiseDetail_' + id).animate({height: 'show', paddingTop : '14pt', paddingBottom : '7pt'});
	showing = id;
}

function hideExpertiseDetail(id, showId) {
	showing = -1;
	$('#expertiseHeader_' + id).fadeTo(100, 1.0);
	$('#expertiseDetail_' + id).fadeOut(250); // animate({height: 'hide', paddingTop : 0, paddingBottom: 0 }, function() { showExpertiseDetail(id)});
	// $('#expertiseDetail_' + id).fadeOut(100); // animate({height: 'hide', paddingTop : 0, paddingBottom: 0 });
	$('.foldOut').animate({height: 'hide', paddingTop : '0', paddingBottom: '0', marginBottom: '0' });
}

$(document).ready(function() {
	$('.expertiseHeader').show();
	$('.expertiseDetail').hide();
	// $('.expertiseDetail').hide().css({paddingTop : 0, paddingBottom: 0});
	$('.foldOut').hide().css({paddingTop : '0', paddingBottom: '0'});
	// showExpertiseDetail(19);
	
	$('.expertiseLinkedProjectsScroller').each(function() {
		$(this).attr('scrollerX', 0);
		$(this).attr('scrollerMax', $('.expertiseLinkedProject', this).length * (64 + 10) - 323);
	});
	
	$('.expertiseForwardButton').click(function() {
		$('.expertiseLinkedProjectsScroller', this.parentNode).each(function() {
			var current = parseInt($(this).attr('scrollerX'));
			var scrollerMax = parseInt($(this).attr('scrollerMax'));
			
			var scroll = 200;
			if (current + scroll > scrollerMax) {
				scroll = scrollerMax - current;
			}
			
			$(this).animate({marginLeft: '-=' + scroll + 'px'}, 500, 'linear');
			$(this).attr('scrollerX', current + scroll);

		});
	}); 
	
	$('.expertiseBackButton').click(function() {
		$('.expertiseLinkedProjectsScroller', this.parentNode).each(function() {
			var current = parseInt($(this).attr('scrollerX'));
			var scrollerMax = parseInt($(this).attr('scrollerMax'));

			var scroll = -200;
			if (current + scroll < 0) {
				scroll = 0 - current;
			}
			$(this).animate({marginLeft: '-=' + scroll + 'px'}, 500, 'linear');
			$(this).attr('scrollerX', current + scroll);
		});
	});
});