This should simplify it
$$('#leftnav_container #modules h2').invoke('observe','click',function(){
container = this.next('div');
Effect.toggle(container , 'blind', { duration: 0.3 });
});
Firstly if you are only running one method on all elements in the array returned from $$()
then you can use the PrototypeJS method invoke()
.
http://api.prototypejs.org/language/Enumerable/prototype/invoke/
Then Effect.toggle()
will check if the element is visible and do the appropriate up/down effect.
Try this out and let me know if it works for you.