// global flag
var isIE = false;

// global request and XML document objects
var req;
 
//
// Work our way through the xml and start rotating the images.
//


var currentmediumdrawitem = 0;
var currentmediumclearitem = 0;

var mediumdraworder = new Array();
mediumdraworder[0] = new Array(1,2,3,4,5,6,7,8);
mediumdraworder[1] = new Array(8,7,6,5,4,3,2,1);
mediumdraworder[2] = new Array(4,5,6,7,8,1,2,3);
mediumdraworder[3] = new Array(5,4,3,2,1,8,7,6);
mediumdraworder[4] = new Array(5,6,7,8,1,2,3,4);
mediumdraworder[5] = new Array(4,3,2,1,8,7,6,5);
mediumdraworder[6] = new Array(2,3,6,7,5,8,1,4);
mediumdraworder[7] = new Array(5,8,6,7,2,3,1,4);
mediumdraworder[8] = new Array(2,3,1,4,6,7,5,8);
mediumdraworder[9] = new Array(8,1,4,5,7,2,3,6);

var currentsmalldrawitem = 0;
var currentsmallclearitem = 0;

var smalldraworder = new Array();
smalldraworder[0] = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32);
smalldraworder[1] = new Array(1,2,5,6,9,10,13,14,3,4,7,8,11,12,15,16,17,18,21,22,25,26,29,30,19,20,23,24,27,28,31,32);
smalldraworder[2] = new Array(1,2,5,6,9,10,13,14,16,30,32,31,28,27,24,23,20,19,17,3,4,7,8,11,12,15,29,26,25,22,21,18);
smalldraworder[3] = new Array(6,9,8,11,22,25,24,27,5,10,7,12,21,26,23,28,2,13,4,15,18,29,20,31,1,14,3,16,17,30,19,32);
smalldraworder[4] = new Array(4,12,7,15,21,29,18,26,3,11,1,9,2,10,5,13,6,14,8,16,22,30,24,32,23,31,20,28,19,27,17,25);

/*
var longpause = 5000;
var mediumpause = 250;
var shortpause = 75;
*/
var longpause   = 2500;
var mediumpause = 175;
var shortpause  = 37;


function InitializeMarquee(){
	if(randBool()) {
		setTimeout('DrawMediumImage(1)',longpause);
	} else {
		setTimeout('DrawSmallImage(1)',longpause);
	}
	// Collect Array of DisplayGroup Entities
}

function DrawMediumImage(init){

	if (init){
		currentmediumdrawitem = 0;
		randomval = Math.floor(Math.random() * mediumdraworder.length);
		localmediumdraworder = mediumdraworder[randomval];
	}

	element = document.getElementById('marqueemedium' + localmediumdraworder[currentmediumdrawitem]);
	element.style.backgroundImage = 'url("marquee.php?size=medium&rand='+Math.random()+'")';
	
	if (currentmediumdrawitem >= 7){
		setTimeout('ClearMediumImage(1)',longpause);
		setTimeout('DrawLargeImage()', mediumpause);
	} else {
		currentmediumdrawitem++;
		setTimeout('DrawMediumImage(0)',mediumpause);
	}

}

function ClearMediumImage(init){

	if (init){
		currentmediumclearitem = 0;
		randomval = Math.floor(Math.random() * mediumdraworder.length);
		localclearorder = mediumdraworder[randomval];	
	}
	
	element = document.getElementById('marqueemedium' + localclearorder[currentmediumclearitem]);
	element.style.backgroundImage = '';
	
	if (currentmediumclearitem >= 7){
		if(randBool()) {
			setTimeout('DrawMediumImage(1)',longpause);
		} else {
			setTimeout('DrawSmallImage(1)',longpause);
		}
	} else {
		currentmediumclearitem++;
		setTimeout('ClearMediumImage(0)',mediumpause);
	}

}

function DrawSmallImage(init) {
	if (init){
		currentsmalldrawitem = 0;
		randomval = Math.floor(Math.random() * smalldraworder.length);
		localsmalldraworder = smalldraworder[randomval];
	}

	element = document.getElementById('marqueesmall' + localsmalldraworder[currentsmalldrawitem]);
	element.style.backgroundImage = 'url("marquee.php?size=small&rand='+Math.random()+'")';
	
	if (currentsmalldrawitem >= 31){
		setTimeout('ClearSmallImage(1)',longpause);
		setTimeout('DrawLargeImage()', mediumpause);
	} else {
		currentsmalldrawitem++;
		setTimeout('DrawSmallImage(0)',shortpause);
	}
}

function ClearSmallImage(init) {
	if (init){
		currentsmallclearitem = 0;		
		randomval = Math.floor(Math.random() * smalldraworder.length);
		localclearorder = smalldraworder[randomval];	
	}
	
	element = document.getElementById('marqueesmall' + localclearorder[currentsmallclearitem]);
	element.style.backgroundImage = '';
	
	if (currentsmallclearitem >= 31){
		if(randBool()) {
			setTimeout('DrawMediumImage(1)',longpause);
		} else {
			setTimeout('DrawSmallImage(1)',longpause);
		}
	} else {
		currentsmallclearitem++;
		setTimeout('ClearSmallImage(0)',shortpause);
	}
}

function DrawLargeImage() {
	element = document.getElementById('marquee');
	element.style.backgroundImage = 'url("marquee.php?size=large&rand='+Math.random()+'")';
}

function randBool() {
	randomval = Math.floor(Math.random()*10)%2;
	return randomval
}