var twitapi = window.twitapi || {};

twitapi.common = (function($){
	
	function init() {
		_setupCategoryNav();
	}
	
	function _setupCategoryNav() {
		// handle clicks on each category
		$('#sd h3').click(function(ev){
			ev.stopPropagation();
			var $li = $(this).parent();
			if ($li.is('.active')) {
				$li.removeClass('active');
			}
			else {
				$li.addClass('active');
			}
			return false;
		});
		
		// handle expand all and collapse all
		$('#sd span.expand').click(function(ev){
			ev.stopPropagation();
			$('#sd > ul > li').addClass('active');
			return false;
		});
		$('#sd span.collapse').click(function(ev){
			ev.stopPropagation();
			$('#sd > ul > li').removeClass('active');
			return false;
		});
		
		// find active link
		$('#sd a[href="'+document.location.pathname+'"]').addClass('active').parent().parent().parent().addClass('active');
	}
	
	
	return {
		init:init
	}
})(jQuery);

jQuery(document).ready(twitapi.common.init);
