$(document).ready(function() {

	// hide items except first
	$('#getInvolved ul.campaigns li:not(:first)').hide();
	// add on class to first nav item
	$('#getInvolved ul.navs li:first-child').addClass('on');

	// changed selected item on click
	$('#getInvolved .navs li').live('click', function() {
		// remove on classes, add on class to current
		$('#getInvolved .navs li').removeClass('on');
		$(this).addClass('on');
		// hide items, get selected item index, show selected item
		$('#getInvolved ul.campaigns li').hide();
		var selectedItem = $(this).find('a').attr('id').split('-').pop();
		selectedItem = parseInt(selectedItem,10);
		$('#getInvolved ul.campaigns li:eq(' + selectedItem + ')').fadeIn('slow');
		return false;
	});

	$('#getInvolved ul.prevnext li.prev').live('click', function() {
		// don't do anything if it's currently animating
		if ($('body').hasClass('animating')) { } else {
			// get html from last item
			var lastItem = $('#getInvolved ul.navs li:last-child').html();
			var lastItem = '<li>' + lastItem + '</li>';
			// put it at the end of the list, remove first item, reset margin
			$('#getInvolved ul.navs').prepend(lastItem);
			$('#getInvolved ul.navs li:last-child').remove();
			$('#getInvolved ul.navs').css({left: '-92px'});
			// hide all items, fade in selected item, add on class to nav
			$('#getInvolved ul.campaigns li').hide();
			$('#getInvolved ul.navs li').each(function(i) { if ($(this).hasClass('on')) {
					totalItems = $('#getInvolved ul.navs li').size();
					selectedItem = $(this).find('a').attr('id').split('-').pop();
					selectedItem = parseInt(selectedItem,10);
					selectedItem = selectedItem - 1;
					if(selectedItem < 0) {
						selectedItem = totalItems;
						selectedItem = selectedItem - 1;
					}
				}
			});
			$('#getInvolved ul.campaigns li:eq(' + selectedItem + ')').fadeIn('slow');
			$('#getInvolved ul.navs li.on').removeClass('on').prev().addClass('on');
			// stop click function
			$('body').addClass('animating');
			$('#getInvolved ul.navs').animate({left: '0px'}, 'slow', function() {
				// allow click function again
				$('body').removeClass('animating');
			});
		};
		return false;
	});

	$('#getInvolved ul.prevnext li.next').live('click', function() {
		// don't do anything if it's currently animating
		if ($('body').hasClass('animating')) { } else {
			// hide all items, fade in selected item, add on class to nav
			$('#getInvolved ul.campaigns li').hide();
			$('#getInvolved ul.navs li').each(function(i) { if ($(this).hasClass('on')) {
					totalItems = $('#getInvolved ul.navs li').size();
					selectedItem = $(this).find('a').attr('id').split('-').pop();
					selectedItem = parseInt(selectedItem,10);
					selectedItem = selectedItem + 1;
					if(selectedItem == totalItems) {
						selectedItem = 0;
					}
				}
			});
			$('#getInvolved ul.campaigns li:eq(' + selectedItem + ')').fadeIn('slow');
			$('#getInvolved ul.navs li.on').removeClass('on').next().addClass('on');
			// stop click function
			$('body').addClass('animating');
			// move navs
			$('#getInvolved ul.navs').animate({left: '-92px'}, 'slow', function() {
				// get html from first item
				var firstItem = $('#getInvolved ul.navs li:first-child').html();
				var firstItem = '<li>' + firstItem + '</li>';
				// put it at the end of the list, remove first item, reset margin
				$('#getInvolved ul.navs').append(firstItem);
				$('#getInvolved ul.navs li:first-child').remove();
				$('#getInvolved ul.navs').css({left: 0});
				// allow click function again
				$('body').removeClass('animating');
			});
		};
		return false;
	});

    
});

$(window).load(function() {

	$.fn.equalizeHeights = function(){
		return this.height( Math.max.apply(this, $(this).map(function(i,e){ return $(e).height() }).get() ) )
	}
	$('#contentBottom .container .home').equalizeHeights();

});
