<!--
//define some globals

var check = new Array();
var imagenum = new Array();

var filepath = new Array();
var filename = new Array();
var fileext = new Array();

var detect = navigator.userAgent.toLowerCase();

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function getElementByClass(classname){
	var inc=0;
	var customcollection = new Array();
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname){
			customcollection[inc++]=alltags[i];
		}
	}
	return customcollection;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.className != "body-right")
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.className != "body-right")
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function addDiv(index) {
	var obj = document.getElementById(index);
	var ileft = findPosX(obj) + obj.width - 43;
	var itop = findPosY(obj) + obj.height - 25;
	//alert(ileft+"-"+itop);
	var divstring = '<div id="div'+index+'" style="left:'+ileft+'px; position:absolute; top:'+itop+'px; width:37px; height:19px; background-image:url(/Img/arrow.gif); z-index:100; cursor:pointer;" onClick="refreshIt(document.getElementById(\''+index+'\'))"></div>';
	var divelem = getElementByClass('body-right');
	divelem[0].innerHTML += divstring;
	
	//Stupid hack to get IE to display div properly. I hate Javascript.
	document.getElementById('div'+index).style.width = "36px";
	document.getElementById('div'+index).style.width = "37px";
}

//increment check if image exists
function testImage(url,checkIndex) {
	var tempImage = new Image();
	tempImage.onload = function() {
		if(checkIt('opera')){
			if(tempImage.complete){
				check[checkIndex] ++;
			}
		}else{
			check[checkIndex] ++;
		}
		if(check[checkIndex] == 2) {
			addDiv(checkIndex);
		}
	}
	tempImage.src = url;
}

function refreshIt(image) {
  var imgIndex = image.id;
	
	/*if (!imagenum[imgIndex]) {
		initImageCycle(image);
	}*/
		
	//utilise the check variable to cycle the current imagenum
	if(check[imgIndex] > 0){
		imagenum[imgIndex] = imagenum[imgIndex] + 1;
		imagenum[imgIndex] = ((imagenum[imgIndex]-1)%check[imgIndex])+1;
	} else {
		imagenum[imgIndex] = 1;
	}
	
	//set image source to correct image name and number
	image.src = filepath[imgIndex] + filename[imgIndex] + imagenum[imgIndex] + fileext[imgIndex];
	
	//setTimeout('refreshIt('+imgIndex+')',100); // refresh every 5 secs
}

function initImageCycle(image){
	var imgIndex = image.id;
	
	if(!imagenum[imgIndex]){
	
		//get image details
		var tempstring = image.src;
		filepath[imgIndex] = tempstring.substring(0,tempstring.lastIndexOf("/")+1);
		filename[imgIndex] = tempstring.substring(tempstring.lastIndexOf("/")+1,tempstring.lastIndexOf(".")-1);
		fileext[imgIndex] = tempstring.substring(tempstring.lastIndexOf("."));
	
		check[imgIndex] = 0;
		imagenum[imgIndex] = 1;
	
		//use image details to check for similarly named images
		for (var x = 1; x <= 9; x++) {
			var newfile = filepath[imgIndex] + filename[imgIndex] + x + fileext[imgIndex];
			testImage(newfile,imgIndex);
		}
	}
}
//-->