// 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: 'short', transition: Fx.Transitions.Sine.easeOut});
			myEffect.start({
				'height': [start_widths[shown], 1]
			});
		}
		
		if (id != shown){
			//grow the new one
			var myCookie = Cookie.write('newssub', 'newssub' + id);
			var myEffect = new Fx.Morph('newssub' + id, {duration: 'short', 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 = '';
			var myCookie = Cookie.write('newssub', '');
		}
}

	$$('[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

		$('newssub' + thecount).setStyle('height', '1px');

		$('newshead' + thecount).setStyle('cursor', 'pointer');

	});
	
	var myCookie = Cookie.read('newssub');
	if (myCookie != null){
		id = myCookie.replace('newssub','');
			var myEffect = new Fx.Morph('newssub' + id, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
			myEffect.start({
				'height': [1, start_widths[id]]
			});
			shown = id;
	}
	


});


