window.addEvent('domready', function(){

	var scroll = new Fx.Scroll('tour', {
		wait: false,
		duration: 500,
		offset: {'x': -0, 'y': -0 },
		transition: Fx.Transitions.Quad.easeInOut
	});
	var pos = 0;
	var frames = $$('#tour .frame');
	var tourLinks = $$('.tour-nav');

	scroll.toElement(frames[0].id);

	$$('.next-frame').each(function(next, i) {
		next.addEvent('click', function(event) {
			event = new Event(event).stop();
			tourLinks[pos].removeClass('active');
			if(pos < frames.length -1) {
				pos++;
				scroll.toElement(frames[pos].id);
			} else {
				pos = 0;
				scroll.toElement(frames[pos].id);
			}
			tourLinks[pos].addClass('active');
		});
	});
	
	tourLinks.each(function(section , i) {
        if(i>=4){
            i-=4;
        }
		if(i < frames.length)
		{
			section.addEvent('click', function(event){
				event = new Event(event).stop();
				section.blur();
				scroll.toElement(frames[i].id);
				tourLinks[pos].removeClass('active');
				section.addClass('active');
				pos = i;
			});
		}
	});
});
