// Javascript code by K Burton 23/9/2008
// Animated buttons with delayed navigation
//globals
var strGotoUrl="";
var iGUrlDelay = 5;
var fTimerActive = false;
var fHasUnloopedGifs = false;
var ImgArray = new Array();

// test for internet explorer 7
function isIE7() {
	 if (navigator.appVersion.indexOf("MSIE 7.0") != -1)
		return true
	
	return false;
}

// ImageProxy Class  - to get arround problems with the playback of unlooped animated gif images in IE 7
//class ImageProxy construtor
function ImageProxy(fileName){
	if (isIE7() && fHasUnloopedGifs) // Is IE7 don't cache images
	 	this.src = fileName;
	else //not IE7 so cache images
	{
		this.m_imgImage = new Image();
		this.m_imgImage.src = fileName;
		this.src = this.m_imgImage.src;
	}
}

function setUpButtons()
{
	// button 1 index
	ImgArray[0] = new ImageProxy("assets/CatButtonSleephome.gif");
	ImgArray[1] = new ImageProxy("assets/CatButtonBlinkhome.gif");
	ImgArray[2] = new ImageProxy("assets/CatButtonClickhome.gif");
	// button 2 the girls
	ImgArray[3] = new ImageProxy("assets/CatButtonSleepgirls.gif");
	ImgArray[4] = new ImageProxy("assets/CatButtonBlinkgirls.gif");
	ImgArray[5] = new ImageProxy("assets/CatButtonClickgirls.gif");
	// button 3 the boys
	ImgArray[6] = new ImageProxy("assets/CatButtonSleepboys.gif");
	ImgArray[7] = new ImageProxy("assets/CatButtonBlinkboys.gif");
	ImgArray[8] = new ImageProxy("assets/CatButtonClickboys.gif");
	// button 4 the nursery
	ImgArray[9] = new ImageProxy("assets/CatButtonSleepnursery.gif");
	ImgArray[10] = new ImageProxy("assets/CatButtonBlinknursery.gif");
	ImgArray[11] = new ImageProxy("assets/CatButtonClicknursery.gif");
	// button 5 Kittens
	ImgArray[12] = new ImageProxy("assets/CatButtonSleepkittens.gif");
	ImgArray[13] = new ImageProxy("assets/CatButtonBlinkkittens.gif");
	ImgArray[14] = new ImageProxy("assets/CatButtonClickkittens.gif");	
	// button 6 photo album
	ImgArray[15] = new ImageProxy("assets/CatButtonSleepphoto.gif");
	ImgArray[16] = new ImageProxy("assets/CatButtonBlinkphoto.gif");
	ImgArray[17] = new ImageProxy("assets/CatButtonClickphoto.gif");
	// button 7 show news
	ImgArray[18] = new ImageProxy("assets/CatButtonSleepshow.gif");
	ImgArray[19] = new ImageProxy("assets/CatButtonBlinkshow.gif");
	ImgArray[20] = new ImageProxy("assets/CatButtonClickshow.gif");
	// button 8 links
	ImgArray[21] = new ImageProxy("assets/CatButtonSleeplinks.gif");
	ImgArray[22] = new ImageProxy("assets/CatButtonBlinklinks.gif");
	ImgArray[23] = new ImageProxy("assets/CatButtonClicklinks.gif");
	// button 9 email me
	ImgArray[24] = new ImageProxy("assets/CatButtonSleepemail.gif");
	ImgArray[25] = new ImageProxy("assets/CatButtonBlinkemail.gif");
	ImgArray[26] = new ImageProxy("assets/CatButtonClickemail.gif");
}

// load images as early as possible
setUpButtons(); 

function changeImage(strImageName,iIndex)
{
  document.images[strImageName].src = ImgArray[iIndex].src;
  return true;
}

function navigatePause(strURL,iDelayMs)
{	
	
	if (fTimerActive == false)
	{
		// copy locals as they go out of scope!
		strGotoUrl = strURL; 
		iGUrlDelay = iDelayMs;

		fTimerActive = true;
		setTimeout('doNavigate(strGotoUrl)',iGUrlDelay);
	}
	// else a second button has been clicked so need to stop the timer and start again 
}

function doNavigate(strURL)
{
	fTimerActive = false;
	top.location.href = strURL;
}

