// JavaScript Document
// Preload menu rollovers
mainmenurollover= new Image(); 
mainmenurollover.src="images/mainMenu-over.jpg";
sectionmenurollover= new Image(); 
sectionmenurollover.src="images/sectionMenu-over.jpg";
//Image fading functions
sectionImagesHome = new Array("images/sectionBackgrounds/DarkCrowd.jpg","images/sectionBackgrounds/NightViewOfStage.jpg","images/sectionBackgrounds/CrowdFromStage.jpg","images/sectionBackgrounds/Shoes.jpg","images/sectionBackgrounds/CrowdFaces.jpg","images/sectionBackgrounds/Kid.jpg")
sectionImagesGetInvolved = new Array("images/sectionBackgrounds/GetInvolved1.jpg","images/sectionBackgrounds/GetInvolved2.jpg","images/sectionBackgrounds/GetInvolved3.jpg")
sectionImagesWhatsOn = new Array("images/sectionBackgrounds/BecksAndTheBullets.jpg","images/sectionBackgrounds/Resplendents.jpg","images/sectionBackgrounds/Stylophone.jpg","images/sectionBackgrounds/KidsPerformer.jpg","images/sectionBackgrounds/Juggler.jpg","images/sectionBackgrounds/Drummer.jpg","images/sectionBackgrounds/Dharmas.jpg","images/sectionBackgrounds/Sukhothai.jpg","images/sectionBackgrounds/BlurredStage.jpg")
thisImage = 0
switch(section){
	case "WhatsOn":
		sectionImagesArray = sectionImagesWhatsOn
		break
	case "Home":
		sectionImagesArray = sectionImagesHome
		break
	case "GetInvolved":
		sectionImagesArray = sectionImagesGetInvolved
		break
	default:
	}
imgCt = sectionImagesArray.length
firstTime = true

function SetOpacity(object,opacityPct) {
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}

function FadeInNewImage(opacity) {
	foreground = document.getElementById("foregroundImage")
	SetOpacity(foreground,opacity)
	opacity = opacity + 5
	if (opacity <= 100) {
		setTimeout("FadeInNewImage("+opacity+")",50)
	}
}

function changeImage(overrideImage) {
	if (document.images) {
		if (firstTime) {
			thisImage = Math.floor(Math.random()*imgCt)
			firstTime = false
			//Set new image as foreground image, make it visible, then fade in
			document.foregroundImage.src=sectionImagesArray[thisImage]
			foreground = document.getElementById("foregroundImage")
			SetOpacity(foreground,0)
			document.foregroundImage.style.visibility='visible'
			FadeInNewImage(70)
			setTimeout('changeImage()',4000)
			}
		else {
			if (overrideImage) {
				thisImage = overrideImage;
				}
			else {
				thisImage++
				if (thisImage >= imgCt) {
					thisImage = 0
					}
				//Swap foreground image to background div only if this isn't the first time
				backgroundDiv=document.getElementById("sectionMenus")
				backgroundDiv.style.backgroundImage = 'url(' + document.foregroundImage.src + ')'
				//Set new image as foreground image, initially as opacity = 0 but then fading in
				foreground = document.getElementById("foregroundImage")
				SetOpacity(foreground,0)
				document.foregroundImage.src=sectionImagesArray[thisImage]
				}
			if (document.foregroundImage.complete) {
				window.status=sectionImagesArray[thisImage]+": downloaded = "+document.foregroundImage.complete
				FadeInNewImage(0)
				setTimeout('changeImage()',4000)
				}
			else {
				window.status=sectionImagesArray[thisImage]+": downloaded = False"
				setTimeout('changeImage('+thisImage+')',2000)
			}
			
		}
		
	}
}