/**
 * plus-minus.js is the non-ajax version of expand-item
 * in that it hides/shows content already on the page 
 * rather than making a separate http request (which won't
 * always be needed).
 * 
 * This can really only be used in conjuction with a 
 * <ui:box type="expander" /> at the moment..
 */ 
 $(document).ready( function(){
 			
	var ex         = $(".expander:not(.grey),ul.theme-listing li:not(.grey),.expandcollapse").addClass("collapsed");
	var openCount  = 0;
	var totalCount = ex.size();
	
	ex.find( "h4,h5:not(.flat)" ).css( {"cursor":"pointer"} ).toggle( 
		function(){
			$(this).addClass("clicked");
			var t = $(this), p = $(this).parent();
			p.removeClass( "collapsed" );
			p.find( ".content,.theme-content,.toggle" ).slice(0,1).slideDown(200, function(){
				t.find("span.pm").addClass("minus");
			});
			$(".collapse-all").removeClass("inactive");
			if( ++openCount == totalCount ){
				$(".expand-all").addClass("inactive");
			}
		}, 
		function(){
			$(this).removeClass("clicked");
			var t = $(this), p = $(this).parent();
			p.find( ".content,.theme-content,.toggle" ).slice(0,1).slideUp(200, function(){
				p.addClass( "collapsed" );
				t.find("span.pm").removeClass("minus");
			});
			$(".expand-all").removeClass("inactive");
			if( --openCount == 0 ){
				$(".collapse-all").addClass("inactive");
			}
		}
	).append( '<span class="pm"><span>&nbsp;</span></span>' );
	
	$("ul.theme-listing li").find("h4,h5").each(function(i,elem){
		$(this).css({"border-color":$(this).css("color")});
		$(this).find("span").css({"border-color":$(this).css("color")})
		$(this).find("a").css({"color":$(this).css("color")})
	});
	
 /* expand/collapse all functionaility */
	$(".expand-collapse-all").show();
	
	$(".expand-all").click(function(){
		// $(".expander.collapsed h4,ul.theme-listing li.collapsed h5,.toc .expand-collapse-links .expand-section").click();
		$(".toc .expand-collapse-links .expand-section").click();
		$(this).parent().parent().find(".show-hide-abstracts").show()
		$(this).addClass("inactive");
		$(".collapse-all").removeClass("inactive");
		return false;
	});
	$(".collapse-all").click(function(){
		// $(".expander:not(.collapsed) h4,ul.theme-listing li:not(.collapsed) h5").click();
		$(".toc .expand-collapse-links .collapse-section").click();
		$(this).parent().parent().find(".show-hide-abstracts").hide();
		$(this).addClass("inactive");
		$(".expand-all").removeClass("inactive");
		return false;
	});
	
	
 /* expand-collapse toc menu items functionality */

//- when the "collapse" link is clicked -->	
	$(".collapse-section").click( function(){
		var t = $(this), p = t.parent(), abstractLinks = p.parent().find(".show-hide-abstracts");
		p.parent().parent().find(".toggle").slideUp(function(){
			if (abstractLinks.size() > 0)
				abstractLinks.hide();
		});
		p.find(".expand-section").removeClass("inactive");
		t.addClass("inactive");
		
		return false;
	});
//- when the "show" link is clicked -->	
	$(".expand-section").click( function(){
		var t = $(this), p = t.parent(), abstractLinks = p.parent().find(".show-hide-abstracts");
		p.parent().parent().find(".toggle").slideDown(function(){
			if (abstractLinks.size() > 0)
				abstractLinks.show();
		});
		p.find(".collapse-section").removeClass("inactive");
		t.addClass("inactive");
		
		return false;
	});
	
//- open the menu relating to the issue we are currently looking at
	(function(){
		var open = false;
		$(".expandcollapse:not(.toc) .toggle li").each(function(i,elem){
			if($(elem).find("a").size()==0) open = elem;
		})
		// "click" on the h5 element in question
		if(open) $(open).parent().prev().click();
	})()

	
 });
 
 // -- show the expand/collapse links & hide all the expanders -->
document.write('<style type="text/css">.expand-collapse-all,.expand-collapse-links{display:block} .box.expander .content, ul.theme-listing ul,.expandcollapse .toggle, .stat-collection .toggle{display: none}</style>');