//
// LSanBoeuf: 31 October 2009: SBDC-Iraq.com Image Rotation Enhancement
//
// This javascript file is referenced from /Cms/templates/standard/header.php
//

var picDelay = 3000;			// milliseconds between each rotation cycle
var picArray = new Array();		// array of pictures to be rotated
var imgCount = 3;				// number of image blocks in which to rotate pictures

//var picBase = "/SBDC";			// picture path base, to account for the development and test environments
var picBase = "";				// picture path base, for the live site. comment out the entry above.
	
function picInit() {
	
	// Initialize the picture array with image src the paths
	
	picArray[0] = new Image();
	picArray[0].src = picBase + "/files/Cms/banners/header/pic001.bmp";
	picArray[1] = new Image();
	picArray[1].src = picBase + "/files/Cms/banners/header/pic002.bmp";
	picArray[2] = new Image();
	picArray[2].src = picBase + "/files/Cms/banners/header/pic003.bmp";
	picArray[3] = new Image();
	picArray[3].src = picBase + "/files/Cms/banners/header/pic004.bmp";
	picArray[4] = new Image();
	picArray[4].src = picBase + "/files/Cms/banners/header/pic005.bmp";
	picArray[5] = new Image();
	picArray[5].src = picBase + "/files/Cms/banners/header/pic006.bmp";
	picArray[6] = new Image();
	picArray[6].src = picBase + "/files/Cms/banners/header/pic007.bmp";
	picArray[7] = new Image();
	picArray[7].src = picBase + "/files/Cms/banners/header/pic008.bmp";
	picArray[8] = new Image();
	picArray[8].src = picBase + "/files/Cms/banners/header/pic009.bmp";
	picArray[9] = new Image();
	picArray[9].src = picBase + "/files/Cms/banners/header/pic010.bmp";
	picArray[10] = new Image();
	picArray[10].src = picBase + "/files/Cms/banners/header/pic011.bmp";
	picArray[11] = new Image();
	picArray[11].src = picBase + "/files/Cms/banners/header/pic012.bmp";
	picArray[12] = new Image();
	picArray[12].src = picBase + "/files/Cms/banners/header/pic013.bmp";

	// Initialize the image blocks with the first X images
	for (i = 0; i < imgCount; i++) {
		document.picRandom[i].src = picArray[i].src;
	}

	// Start the timer
	timerID = setTimeout("picRandomly()", picDelay);

}
	
function picRandomly() {
	// Select the image to change; 1,2,3
	imgID = parseInt(Math.random() * imgCount);
	
	// Get a new picID for imgID. Don't reuse the same one and don't show one already in another imgID.
	imgSrc = document.picRandom[imgID].src;
	while (imgSrc == document.picRandom[imgID].src) {
		picID = parseInt(Math.random() * picArray.length);
		var imgFound = false;
		for (i = 0; i < imgCount; i++) {
			if (document.picRandom[i].src == picArray[picID].src) imgFound = true;
		}
		if (!imgFound) document.picRandom[imgID].src = picArray[picID].src;
	}
	
	// Restart the timer
	timerID = setTimeout("picRandomly()", picDelay);
}
