var picIndex = 0;
var PIC_COUNT = 2;
var picArray = ['images1.jpg', 'images2.jpg', 'images3.jpg', 'images4.jpg'];

var zIndex = 0;

function doPicUp() {

	if (picIndex == 1) {
		return;
	}

	if (1 == picIndex) {
		picIndex = PIC_COUNT;
	} else {
		picIndex = picIndex - 1;
	}

	picElem = $('matt-roper-' + picIndex);
	picElem.setStyle("z-index", zIndex++);
	
	movePicUp(picElem);
	
}

function doPicDown() {

	if (picIndex == PIC_COUNT) {
		return;
	}
	
	picIndex = (picIndex % PIC_COUNT) + 1 ;
	picElem = $('matt-roper-' + picIndex);
	picElem.setStyle("z-index", zIndex++);
	movePicDown(picElem);
}

function movePicUp(picElem) 
{
	position = $("polaroid").getPosition();
	movePic(picElem, position.y, -440);
}

function movePicDown(picElem) 
{
	position = $("polaroid").getPosition();
	movePic(picElem, -440, position.y);
}

var moveanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
function movePic(element, moveFrom, moveTo) 
{
	// Only one at a time
	if (moveanim.timer != null) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}
	
	moveanim.time = 0;
	moveanim.begin = moveFrom;
	moveanim.change = moveTo - moveFrom;
	moveanim.duration = 25; // Original
	moveanim.element = element;
	
	// Callback to the animation function
	moveanim.timer = setInterval("moveVertAnim();", 15);
}

function moveVertAnim()
{
	if (moveanim.time > moveanim.duration) {
		clearInterval(scrollanim.timer);
		moveanim.timer = null;
	}
	else {
		move = sineInOut(moveanim.time, moveanim.begin, moveanim.change, moveanim.duration);
		moveanim.element.top = move;
		moveanim.element.setPosition({y: move});
		moveanim.time++;
	}
}