
var mmfgCarousel = new Class({	

	Implements: [Events],
	
	initialize: function(el, pageSize){
		this.pageSize = pageSize;
		
		this.wScrollable = $(el).getChildren('.visitedScroll')[0];
		this.wScrollContent = this.wScrollable.getChildren('.visitedScrollContent')[0];
		this.wPrev = $(el).getChildren('.visitedPrev')[0];
		this.wNext = $(el).getChildren('.visitedNext')[0];

		this.wPrev.addEvent('click', this.prev.bind(this));		
		this.wNext.addEvent('click', this.next.bind(this));
		
		this.scroll('left');
	},
	
	prev: function(e) {
		e.preventDefault();
		this.scroll('left');
	},

	next: function(e) {
		e.preventDefault();
		this.scroll('right');
	},
	
	scroll: function(dir) {	
		var scrollFx = new Fx.Scroll(this.wScrollable);
		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';		
		}
	}		
		

});