// This class was written by Gregory Athons

function animatedSlider(div,bk,fw) {
	
	var p = this;
	this.marginLeft = 0;
	this.totalPages = 0;
	this.animation = false;
	this.windowWidth = $(div).getParent().getStyle("width").toInt();
	
	//set totalPages
	this.totalPages = Math.ceil($(div).getStyle("width").toInt() / this.windowWidth);
	
	
	//move backwards
	$(bk).addEvent("click", function() {
		if(p.animation) { return; }
		if(p.marginLeft != 0) {
			new Fx.Tween($(div),{
				duration:1000,
				onComplete:function() { p.animation = false; }
			}).start("margin-left",p.marginLeft,(p.marginLeft + p.windowWidth));
			p.animation = true;
			p.marginLeft += p.windowWidth;
		}
	});
	
	//move forward
	$(fw).addEvent('click', function() {
		if(p.animation) { return; }
		if(p.marginLeft != (((p.totalPages - 1) * p.windowWidth) * -1)) {
			new Fx.Tween($(div), {
				duration:1000,
				onComplete:function() { p.animation = false; }
			}).start("margin-left",p.marginLeft,(p.marginLeft - p.windowWidth));
			p.animation = true;
			p.marginLeft -= p.windowWidth;
		}
	});
	
} //end function