var flashScroller = {
	slot: 0,
	width: -630,
	slots: null,
	buttonOff: true,
	init: function() {
		flashScroller.slots = $('free-games-scroller').select('.free-games-feature');
		Event.observe($('buttons').select('.prev')[0], 'click', function(){
			flashScroller.scroll('prev'); return false;
		});
		Event.observe($('buttons').select('.next')[0], 'click', function(){
			flashScroller.scroll('next'); return false;
		});
	},
	scroll: function(direction) {
		var maxSlots = flashScroller.slots.length - parseInt(1);
		switch (direction) {
			case "next":
				if (flashScroller.slot == maxSlots) {
					return;
				}
				flashScroller.slot++;
				break;
			case "prev":
			
				if (flashScroller.slot == 0) {
					return;
				}
				flashScroller.slot--;
				break;
		}
		//new width to scroll towards
		var position = flashScroller.width * flashScroller.slot;
		
		//left positioning on all the scroll divs
		for (i = 0; i < flashScroller.slots.length; i++) {
			flashScroller.slots[i].morph('left: ' + position + 'px', {
				duration: .5
			});
		}
		
		
		flashScroller.scrollCheck(flashScroller.slot, maxSlots);		
	},
	scrollCheck: function(slotNum, maxSlot) {
		if (slotNum == 0) {
			$('buttons').select('.prev')[0].addClassName('off');
			flashScroller.buttonOff = true;
		} else if (slotNum == maxSlot) {
			$('buttons').select('.next')[0].addClassName('off');
			flashScroller.buttonOff = true;
		} else {
			if (this.buttonOff == true) {
				$('buttons').select('.prev')[0].removeClassName('off');
				$('buttons').select('.next')[0].removeClassName('off');
				flashScroller.buttonOff = false;
			}
		}
	}
}

document.observe('dom:loaded',flashScroller.init);