/* for use with /library/index.php
 * requires jQuery 1.2.6+
 * collapses content and adds functionality to expand collapsed content
 */
$(function(){

	// hide all the more infos now that we can make links to show them
	$('.articleListPopUp').add('#premContLegend').css('display','none');
	
	// select all issue_link and attach click events
	$('.issue_link').before('<a class="expander" title="click to expand this issue">&nbsp;</a>').prev().
		css({ // show a little plus sign next to it
			'background-image':'url("/images/more.gif")',
			'background-position':'0px 50%',
			'padding-left':'12px',
			'background-repeat':'no-repeat',
			'border-width':'',
			'text-decoration':'none',
			'cursor':'pointer'}).
		/*attr('title','click to expand this issue').*/
		bind(
			'click',
			function() {
				this.blur(); // get rid of the funky outline
				$(this).//the link that was clicked
					parent().//the div containing the link
					parent().// the div that contains this whole issue
					find('.articleListPopUp'). // the issue drilldown
					slideToggle(
						0,
						function(){
							// set the plus/minus sign
							$(this). // the animated box
								parent(). // it's parent, the issue_set
								find('a.expander'). // the link that was clicked
								css('background-image',
									'url("/images/'+($(this).is(':visible')?'less':'more')+'.gif")').
								attr('title','click to '+($(this).is(':visible')?'contract':'expand')+' this issue');
							// show/hide the legend depending on whether anything is expanded
							$('#premContLegend').
								css('display',
									($('.articleListPopUp').is(':visible')?'inline':'none'));
						}
					);
				return false;
			}
		);
	
	// and let's add a showall/hideall
	$('#summaryheader').before('<a title="click to expand all">&nbsp;</a>').prev().
		data('showall',false).// cache the current setting
		css({ // show the plus widget
			'background-image':'url("/images/more.gif")',
			'background-position':'0px 50%',
			'padding-left':'12px',
			'background-repeat':'no-repeat',
			'text-decoration':'none',
			'cursor':'pointer'}).
		bind( // bind the click event
			'click',
			function(){
				//alert('go');
				if($(this).data('showall')){// if it is all showing
					$('.articleListPopUp').
						slideUp(0); // hide it
					$('#premContLegend').hide(); // and hide the legend
					$(this).data('showall',false);
				} else { //otherwise
					$('.articleListPopUp').
						slideDown(0); //show it
					$('#premContLegend').show(); // and show the legend
					$(this).data('showall',true);
				}
				//change the plus/minus signs
				$(this).add('a.expander').
					css('background-image',
						'url("/images/'+($(this).data('showall')?'less':'more')+'.gif")').
					not(this).
					attr('title',
						'click to '+($(this).data('showall')?'contract':'expand')+' this issue');
					$('#summaryheader').prev().
						attr('title',
						'click to '+($(this).data('showall')?'contract':'expand')+' all issues');
				return false;
			}
		);
});