Fx.ScrollWindow = Fx.Base.extend({

			initialize: function(options){
				this.setOptions(options);
				this.now = [];
				var b = document.body;
				var stop = this.clearTimer.bind(this);
				if (!this.options.continuer){
					if (b.addEventListener) b.addEventListener('DOMMouseScroll', stop, false);
					else b.onmousewheel = stop;
				}
			},

			setNow: function(){
				[0,1].each(function(i){
					this.now[i] = this.compute(this.from[i], this.to[i]);
				}, this);
			},

			scrollTo: function(x, y){
				if (this.timer && this.options.wait) return;
				var left = Window.getScrollLeft();
				var top =  Window.getScrollTop();
				var width = Window.getWidth();
				var height = Window.getHeight();
				var fullWidth = Window.getScrollWidth();
				var fullHeight = Window.getScrollHeight();
				var maxScrollWidth = fullWidth - width;
				var maxScrollHeight = fullHeight - height;
				if (x > maxScrollWidth) x = maxScrollWidth;
				if (y > maxScrollHeight) y = maxScrollHeight;
				return this.custom([left, top], [x, y]);
			},

			toElement: function(el){
				return this.scrollTo($(el).getLeft(), $(el).getTop());
			},

			increase: function(){
				window.scrollTo(this.now[0], this.now[1]);
			}

		});

window.addEvent('domready', function(){
  	var titles = $$('div.title');
  	var contents = $$('div.text');
	var currentheader = null;

  	var visionAccordion = new Accordion(titles,contents, {
		alwaysHide:true,
		start:true,
		wait: false,
		duration: 1000,
		transition: Fx.Transitions.linear,
		opacity: false,
		onComplete: function(){
			//window.scrollTo(currentheader.getLeft(),currentheader.getTop());
			var scroller = new Fx.ScrollWindow({duration: 1000, wait: false, transition: Fx.Transitions.sineInOut});
			scroller.toElement(currentheader);
		}
	});
	
	titles.each(function(el){
		el.addEvent('click', function() {
			currentheader = el;
		});
	});
});
