var position = 0;
var current = null;

function left() {
	var w = $$(".Contents")[0].getWidth();
	
	if (current == null && position > 0) {
		current = new Effect.Move(
			$$(".Gallery")[0],
			{
				x: w,
				y: 0,
				duration: .5,
				transition: function(pos) {
					pos = pos - 1;
					return 1 - Math.abs(pos * pos * pos);
				},
				afterFinish: function() {
					current = null;
				}
			}
		);
		position--;
	} else if (current == null) {
		current = new Effect.Move(
			$$(".Gallery")[0],
			{
				x: -w * ($$(".Gallery img").length - 1),
				y: 0,
				duration: .5,
				transition: function(pos) {
					pos = pos - 1;
					return 1 - Math.abs(pos * pos * pos);
				},
				afterFinish: function() {
					current = null;
				}
			}
		);
		
		position = $$(".Gallery img").length - 1;
	}
}

function right() {
	var w = $$(".Contents")[0].getWidth();
	
	if (current == null && position < $$(".Gallery img").length - 1) {
		current = new Effect.Move(
			$$(".Gallery")[0],
			{
				x: -w,
				y: 0,
				duration: .5,
				transition: function(pos) {
					pos = pos - 1;
					return 1 - Math.abs(pos * pos * pos);
				},
				afterFinish: function() {
					current = null;
				}
			}
		);
		position++;
	} else if (current == null) {
		current = new Effect.Move(
			$$(".Gallery")[0],
			{
				x: w * position,
				y: 0,
				duration: .5,
				transition: function(pos) {
					pos = pos - 1;
					return 1 - Math.abs(pos * pos * pos);
				},
				afterFinish: function() {
					current = null;
				}
			}
		);
		
		position = 0;
	}
}