// JavaScript Document
window.addEvent('domready', function() {
var lastid =1;
var theid;
var thecount;
var shown='';
var thesize;
var start_widths = new Array();

var shownews = function(){
		id = this.id.replace('newshead','');
		if (shown != ''){
			//shrink old one
			var myEffect = new Fx.Morph('newssub' + shown, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
			myEffect.start({
				'height': [start_widths[shown], 1]
			});
		}
		
		if (id != shown){
			//grow the new one
			var myEffect = new Fx.Morph('newssub' + id, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
			myEffect.start({
				'height': [1, start_widths[id]]
			});
			shown = id;
		}else{
			//we just needed to shrink so set open to nothing
			shown = '';
		}
}

	$$('[class=NewsBG]').each(function(el){
			
		theid = el.get('id');
		thecount = theid.replace('newshead','');
		
		$(theid).addEvent('click',shownews);
		
		//get the size of the child element before we start
		thesize = $('newssub' + thecount).getSize();
		start_widths[thecount] = thesize.y;
		
		//set it to 0 if it is not the first one
		if (shown != ''){
			$('newssub' + thecount).setStyle('height', '1px');
		}else{
			shown = thecount;			
		}
		$('newshead' + thecount).setStyle('cursor', 'pointer');

	});
	


});

