/*
	Javascript code to interface with flash applications

*/
var imageIndex = 0;
var numberOfImages;
var flash;
var timer;

// this function lets flash know when to update the image stack
function imageSwap() {
	var newImg = null, oldImg = document.getElementById("img" + imageIndex);
	
	imageIndex = (imageIndex + 1) % numberOfImages;
	newImg = document.getElementById("img" + imageIndex);
	if (oldImg && newImg) {
		oldImg.setAttribute("class", "");
		oldImg.setAttribute("className", ""); // IE
		newImg.setAttribute("class", "on");
		newImg.setAttribute("className", "on"); // IE
	}
	
	flash.imageSwap();
}

// manually change out flash imagery from thumbnails
function selectImage(img) {
	var oldImg = document.getElementById("img" + imageIndex);
	var newImg = document.getElementById("img" + img);
	
	if(oldImg && newImg) {
		clearInterval(timer);
		
		oldImg.setAttribute("class", "");
		oldImg.setAttribute("className", ""); // IE
		newImg.setAttribute("class", "on");
		newImg.setAttribute("className", "on"); // IE
		imageIndex = img;
		flash.imageSwap();

		timer = setInterval("imageSwap()", 8000);
	}
}

// getNum called from flash movie, used to get current 
// imageIndex back into the flash environment
function getNum() {
	return imageIndex;
}

// sets initial image count once flash has loaded the xml, then
// builds out thumbnail selectors in HTML and sets interval timer
function setImageCount(cnt) {
	var curImg;
	// builds thumbnail selectors. If this fails, then flash video just autorotates
	if(buildSelectors()) {
		curImg = document.getElementById("img0");
		if (curImg) {
			curImg.setAttribute("class", "on");
			curImg.setAttribute("className", "on"); // IE
		}
	}
	
	flash = (navigator.appName.indexOf ("Microsoft") != -1) ? window["flashapp"] : document["flashapp"];
	numberOfImages = cnt;
	timer = setInterval("imageSwap()", 8000);
}
