/* ___________________________________________________
   
            JS-HM-091208js ~ rev. 2009.12.08
     XGB Web and Software Design ~ www.xgbdesign.com
   ___________________________________________________
*/
	

// Functions called from home page: _______________________________________________________________

function PostImageFlippers() {
	if (document.images) {
		var theme = Math.floor(Math.random() * 4);            // Select one of four themes at random; then...
		navset = NavigationSet(RandomNumberArray(), theme);   // ...declare and assign to a global variable for home-page navigation
		PostRecursionImage(theme);
		PostNavigationMap(theme);                             // Defined in JS-NV-091208.js
	}
}

function FlipTo(idx) {
	if (document.images)
		document.getElementById("flipper").src = navset[idx].src;
}

function Revert() {
	if (document.images)
		document.getElementById("flipper").src = navset[0].src;
}


// Functions called from here: ____________________________________________________________________

function RandomNumberArray() {
	var numImages = ImageArray().length;
	var rnArray = new Array(8);
	var selectedImages = new Array(numImages);

	// Initialize all images to the unselected state:
	for (var i = 0; i < numImages; ++i)
		selectedImages[i] = false;

	// Make sure no image is selected more than once:
	for (i = 1; i < 8; ++i) {
		do
			rnArray[i] = Math.floor(Math.random() * numImages);
		while (selectedImages[rnArray[i]] == true);
		selectedImages[rnArray[i]] = true;	
	}
	return rnArray;
}

function NavigationSet(rnArray, themeIndex) {
	var iArray = ImageArray();
	var nsArray = new Array(8);

	// Select a recursion image as the first element based on theme:
	nsArray[0] = new Image(631, 390);
	nsArray[0].src = "images/recursion" + themeIndex + ".png";

	// Select images for remaining array elements:
	for (var i = 1; i < 8; ++i) {
		nsArray[i] = new Image(631, 390);
		nsArray[i].src = "images/flipper/" + iArray[rnArray[i]] + ".jpg";
	}
	return nsArray;  
}

function PostRecursionImage(themeIndex) {
	var recursion = "Recursion: Just one part of what XGB Design is all about!";
	document.write("<a href='about.html'>");
	document.write("<img id='flipper' src='images/recursion" + themeIndex + ".png' alt='" + recursion + "' title='" + recursion + "' />");
	document.write("</a>");
}

function ImageArray() {
	return new Array("adpt1", "adpt2", "adpt3", "kceo1", "kceo2", "kceo3", 
		"kfec1", "kfec2", "kfec3", "kfsd1", "kfsd2", "kfsd3", "kfsd4", 
		"kspa1", "kspa2", "kspa3", "kspa4", "prog1", "prog2", "prog3", 
		"prog4", "sdfh1", "sdfh2", "xml1");
}
		
