/* ---http://www.gogogadgetearl.com/.../expand-collapse.js------------------ */
/* ---copyright-2007-gogogadgetearl--all-rights-reserved-------------------- */


ec = {
	triggerClass:'collapse',
	init : function() {	 
		var dateHeaders, i, content, headerHTML;
		//provide the element that has all of the collapseable elements
		ec.content_entries = document.getElementById('content-entries');
		if( !ec.content_entries ){ return; }
		//grab the elements that are to be clicked
		dateHeaders = ec.content_entries.getElementsByTagName( 'h4' );
		if( !dateHeaders ){ return; }
		//loop thru and assign click event to the <span> tags within the date headers
		for( i = 0; i < dateHeaders.length; i++ ) {
			//set the <ul> tags to be the ones that roll-up
			content = dateHeaders[i].parentNode.getElementsByTagName( 'ul' )[0];
			if( !content ){ return; }
			//grab the original height of the <ul> tags
			content.defaultHeight = content.offsetHeight;
			headerHTML = dateHeaders[i].getElementsByTagName('span')[0].innerHTML;
			if( !headerHTML ){ return; }
			//add the expand/collapse icon - this is typically hidden and replaced by a background image
			dateHeaders[i].getElementsByTagName('span')[0].innerHTML = '<span class="ec-icon"><span>[-]</span></span> ' + headerHTML;
			dateHeaders[i].getElementsByTagName('span')[0].content=content;
			//add the click event to the date headers
			YAHOO.util.Event.addListener( dateHeaders[i].getElementsByTagName('span')[0], 'click', ec.toggle);
		}
	},
	toggle : function() {
		var attributes, anim;
		//make 'c' the <ul>
		var c = this.content;
		//if the <ul> is not collapsed/hidden
		if( !c.hidden ) {
			YAHOO.util.Dom.addClass( c, 'hidden' );
			//provide collapsing animation attributes
			attributes = { height: {from:c.defaultHeight, to:8} };
			//create the animation object
			anim = new YAHOO.util.Anim( c, attributes, .6, YAHOO.util.Easing.easeOut );
			anim.animate();
			//when it's done with the animation run the doneHide function
			anim.onComplete.subscribe( ec.doneHide );
		} else {  //if the <ul> is collapsed/hidden
			//change the status of hidden
			c.hidden = c.hidden ? false : true;
			//return the day's class name to the default
			c.parentNode.className = 'block';
			//provide expanding animation attributes
			attributes = { height: { from:8, to:c.defaultHeight-1 } };
			//create the animation object
			anim = new YAHOO.util.Anim( c, attributes, .6, YAHOO.util.Easing.easeOut );
			anim.animate();
			//change the expand/collapse icon to [+]
			c.parentNode.getElementsByTagName('h4')[0].getElementsByTagName('span')[0].getElementsByTagName('span')[0].getElementsByTagName('span')[0].innerHTML = '[-]';
		}
	},
	doneHide : function() {
		//make 'c' the <ul>
		var c=this.getEl();
		//change the status of hidden
 		c.hidden = c.hidden ? false : true;
		//change the day's class name
 		c.parentNode.className = 'block-collapsed';
		//change the expand/collapse icon back to [-]
 		c.parentNode.getElementsByTagName('h4')[0].getElementsByTagName('span')[0].getElementsByTagName('span')[0].getElementsByTagName('span')[0].innerHTML = '[+]';
	},
	hideContents : function() {
		YAHOO.util.Dom.addClass( 'collapse', 'dynamic' );
		//initialize the script
		ec.init();
	}
}	
YAHOO.util.Event.onAvailable( 'collapse', ec.hideContents );
YAHOO.util.Event.addListener( window, 'load', ec.init );



