var mmfgCarousel = new Class({	

	Implements: [Events],
	
	initialize: function (el){
		var el = $(el);

		this.wScrollable = el.getElement(".visitedScroll");
		this.pageSize = this.wScrollable.getSize().x;

		this.wScrollContent = this.wScrollable.getElement(".visitedScrollContent");
		this.wPrev = el.getElement(".visitedPrev");
		this.wNext = el.getElement(".visitedNext");

		this.wPrev.addEvent('click', this.prev.bind(this));		
		this.wNext.addEvent('click', this.next.bind(this));
		
		this.scroll('left');

		this.scrolling = 0;
	},
	
	prev: function (e) {
		e.stop();
		if (!this.scrolling) {
			this.scrolling = 1;
			this.scroll('left');
		}
	},

	next: function (e) {
		e.stop();
		if (!this.scrolling) {
			this.scrolling = 1;
			this.scroll('right');
		}
	},
	
	scroll: function (dir) {	
		var scrollFx = new Fx.Scroll(this.wScrollable);
			scrollFx.addEvent("complete", (function () {this.scrolling = 0;}).bind(this));

		var curpos = $(this.wScrollable).getScroll().x;
		var newpos = 0;

		if (dir == 'left') { newpos = curpos - this.pageSize;}
		else if (dir == 'right') {newpos = curpos + this.pageSize;} 

		scrollFx.start(newpos, 0);
		
		if (newpos <= 0) {
			this.wPrev.style.visibility = 'hidden';
			this.wNext.style.visibility = 'visible';

		} else if (this.wScrollContent.getSize().x - newpos - this.pageSize < 5) {
			this.wPrev.style.visibility = 'visible';
			this.wNext.style.visibility = 'hidden';

		} else {
			this.wPrev.style.visibility = 'visible';
			this.wNext.style.visibility = 'visible';		
		}
	}		
});
