var stretchers = $$('div.accordion');
var togglers = $$('h3.toggler');
var StartStatus = true;
stretchers.setStyles({'height': '0', 'overflow': 'hidden'});
var scroll = new Fx.Scroll(window, {duration: 800, transition: Fx.Transitions.backOut, fps: 60});

window.addEvent('load', function(){
	
	//initialization of togglers effects
	togglers.each(function(toggler, i) {
		toggler.color = toggler.getStyle('background-color');
		toggler.$tmp.first = toggler.getFirst();
		
		toggler.$tmp.fx = new Fx.Style(toggler, 'background-color', {'wait': false, 'transition': Fx.Transitions.Quart.easeOut});
		
	});
	
	//the accordion
	var myAccordion = new Accordion(togglers, stretchers, {
		'opacity': false,
		'start': false,
		'transition': Fx.Transitions.Quad.easeOut,
		onActive: function(toggler){
			toggler.$tmp.fx.start('#D57223');
			toggler.$tmp.first.setStyle('color', '#FFFFFF');
			toggler.$tmp.first.setStyle('background', 'url(/img/pfeil_unten.gif) no-repeat left center');
			//alert(StartStatus);
			if (StartStatus != true) {
				(function() {scroll.scrollTo(0,toggler.getTop()-20);}).bind(toggler).delay(500);
			} else {
				StartStatus = false;
			}	
		},
		onBackground: function(toggler){
			toggler.$tmp.fx.stop();
			toggler.setStyle('background-color', toggler.color).$tmp.first.setStyle('color', '#D57223');
			toggler.$tmp.first.setStyle('background', 'url(/img/h3_bg.gif) repeat-y left center');
		}
	});
	
});

window.addEvent('domready', function(){
	
	$$('.CTitle').each(function(heading){
		new Element('a', {
			'href': '#MainTopic',
			'class': 'toTop'
		}).setHTML('top').injectBefore(heading.getFirst());
	});
	
	new SmoothScroll();
	
});
