var listdivs = null;
var opendiv = null;
var collapsetime = 0.7;

function initNews(){
  listdivs = $$('div.news');
  listdivs.each( function(div){
     div.test = div.down('.singleNews');
		 div.test.setStyle({
       display : 'none'
       });
		 div.openbtn = div.down('.showDetailsh2');
		 div.openbtn2 = div.down('.showDetailsSpan');
     div.openbtn.observe('click', showDetails);
     div.openbtn2.observe('click', showDetails);
     div.closebtn = div.down('.closeButton');
     div.closebtn.observe('click', closeWindow);
  });
}

function showDetails(event){
  var div = $(Event.element(event)).up('.news');
  if(opendiv){
  opendiv.openbtn2.show();
    new Effect.Parallel( [
    new Effect.BlindUp(opendiv.test, {sync : true})
    ],
    {
      duration : collapsetime,
      transition : Effect.Transitions.sinoidal
     }
    );
  }
  if(opendiv != div){
  div.openbtn2.hide();
	opendiv = div;
	new Effect.Parallel( [
	new Effect.BlindDown(div.test, {sync : true})
	],
    {
      duration : collapsetime,
      transition : Effect.Transitions.sinoidal
     }
		);
  }else{
  opendiv = null;
  }
}

function closeWindow (event){
  var div = $(Event.element(event)).up('.news');
  div.openbtn2.show();
  if(opendiv){
		new Effect.Parallel( [
    new Effect.BlindUp(opendiv.test, {sync : true})
    ],
    {
      duration : collapsetime,
      transition : Effect.Transitions.sinoidal
     }
		);
  }
	opendiv = null;
}

addEvent(window,'DOMContentLoaded', initNews);

