// DWAccordeon 0.2
// by Leo Gerber, diewebdesigner.com
// using Prototype and Sriptaculous


document.observe("dom:loaded", function(){
  // for each toggleNest
	$$('.dwaccord-container').each(function(item){
		var thisSlide = item.down( '.dwaccord-content' );
		var thisToggle = item.down( '.dwaccord-toggle' );
		var thisMore = thisToggle.down( '.more' );
		thisMore.setStyle({ visibility: 'visible' });
		// Fix IE width bug for content
		contWidth = item.getWidth();
		thisSlide.setStyle({ width: contWidth });
		if (! thisToggle.hasClassName('act')) {
			thisSlide.hide();
		}

		Event.observe(thisToggle, 'click', function(){
			if (thisToggle.hasClassName('act')) {
				thisToggle.removeClassName('act');
				new Effect.SlideUp( thisSlide, { duration:1.5, scaleX:false } );
				new Effect.Appear(thisMore);
			} else {
				thisToggle.addClassName('act');
				new Effect.SlideDown( thisSlide, { duration:1.5, scaleX:false } );
				new Effect.Fade(thisMore);
			}
		});
	});
	
	$$('.dwaccord-container-bottom').each(function(item){
		var thisBlindBottom = item.down('.dwaccord-content-bottom');
		var thisToggleBottom = item.down('.dwaccord-toggle-bottom');
		var thisMoreBottom = thisToggleBottom.down( '.more' );
		thisMoreBottom.setStyle({ visibility: 'visible' });
		// Fix IE width bug for content
		contWidth = item.getWidth();
		thisBlindBottom.setStyle({ width: contWidth });
		if (! thisToggleBottom.hasClassName('act')) {
				thisBlindBottom.hide();
		}
		Event.observe(thisToggleBottom, 'click', function() {
			if (thisToggleBottom.hasClassName('act')) {
				thisToggleBottom.removeClassName('act');
				new Effect.Appear(thisMoreBottom);
				thisMoreBottom.removeClassName('act');
				new Effect.BlindUp( thisBlindBottom, { duration:1.5 } );
			} else {
				thisToggleBottom.addClassName('act');
				new Effect.BlindDown ( thisBlindBottom, { duration:1.5 } );
				new Effect.Fade(thisMoreBottom);
			}
		});
	});
});
