var screenShots = new Array();
var currShot = new Array();
var ssWin = false;
function screenShotWindow(inUrl) {
	ssWin = window.open(inUrl,'Magmic_ssWin','width=709,height=385');
	ssWin.focus();
}

function checkImageName(imgName) {
	if(!imgName) {
		//default name
		imgName = 'ssDisplay';
	}
	if(!currShot[imgName]) {
		currShot[imgName] = 0;
	}
	return imgName;
}

function checkForScreenShots(imgName) {
	if(!imgName) {
		imgName = 'ssDisplay';
	}
	if(screenShots[imgName].length) {
		if(!currShot[imgName]) {
			currShot[imgName] = 0;
		}
		return screenShots[imgName].length;
	}
	else {
		return false;
	}
}

function showScreenShot(num,imgName) {
	imgName = checkImageName(imgName);
	if (checkForScreenShots(imgName)) {
		display = document.images[imgName];
		// if the image has loaded
		if (display) {
			display.src = screenShots[imgName][num];
		}
		// keep the rotation in sync, regardless of losd status
		currShot[imgName] = num;
	}
}
function nextScreenShot(slowRotate,imgName) {
	imgName = checkImageName(imgName);
	var nextShot = currShot[imgName]+1;
	if (nextShot >= screenShots[imgName].length) {
		nextShot = 0;
	}
	showScreenShot(nextShot,imgName);
	//reset the rotation timer.
	if(slowRotate) {
		skipNextShot(imgName);
	}
			
}
function prevScreenShot(slowRotate,imgName) {
	imgName = checkImageName(imgName);
	var prevShot = currShot[imgName]-1;
	if (prevShot <= 0) {
		prevShot = screenShots[imgName].length-1;
	}
	showScreenShot(prevShot,imgName);
	//reset the rotation timer.
	if(slowRotate) {
		skipNextShot(imgName);
	}
}
var ssInterval = false;
var skipShot = new Array();

function skipNextShot(imgName) {
	skipShot[imgName] = true;
}

function rotateSShots() {
	for(name in screenShots) {
		if(checkForScreenShots(name)) {
			if(!skipShot[name]) {
				nextScreenShot(false,name);
			}
			else {
				skipShot[name] = false;
			}
		}
	}
}
window.setInterval('rotateSShots()',3000);


