window.addEvent('domready', function(){
	
	var acclinks = $$('h3.atStart');
	acclinks.each(function(el){
		el.addEvent('mouseenter', function(){
			el.addClass('activeacc');
		});
		el.addEvent('mouseleave', function(){
			el.removeClass('activeacc');
		});
	});

	var lastclicked;
	var previousitem;

	var accordion = new Accordion('h3.atStart', 'div.atStart', {
		opacity: false,
		alwaysHide: true,
		show: -1,
		duration: 500,
		onActive: function(toggler, element){
			acclinks.removeClass('activeacc');
			toggler.addClass('activeacc2');
			previousitem = lastclicked;
			lastclicked = toggler;
			if(previousitem){
				previousitem.removeClass('activeacc2');
			}
			//scroll.toElement(lastclicked);
		},
		onComplete: function(toggler, element){
			//alert(this);
			//console.log(lastclicked);
			if(lastclicked.hasClass('activeacc2')){
				//scroll.toElement(lastclicked);
				var elpos = lastclicked.getPosition();
				var pos = {x: 0, y: elpos.y-100};
				scroll.scrollTo(0,elpos.y-50);
			};
			//alert("remove class from"+element);
			//lastclicked = "";
			//scroll.toElement(toggler);
		},
		onBackground: function(toggler, element){
			//toggler.setStyle('background', '#222');
			//toggler.removeClass('activeacc2');
		}
	}, $('acc'));

	var scroll = new Fx.Scroll(window, {
		wait: false,
		duration: 700,
		transition: Fx.Transitions.Quad.easeInOut
	});

});