// Name: homepage.js

// Find the index of the background image given the model name
// INPUT: 	string modelName = name of model
// OUTPUT:	integer intModelPosition = index of the model
function getBackgroundImagePath(modelName) {
	for (i=0;i<=aryModelPagePath.length;i++) {
		if (modelName == aryModelNames[i]) {
			intModelPosition = i;
		} else if (modelName == "Z") {
			intModelPosition = 7;
		}
	}

	if (intModelPosition == 7) {
		valPath = strComingVehicleURLPath;
	} else {
		valPath = aryModelPagePath[intModelPosition];
	}

	return valPath
}

// Background image object to hold the image path, alt tag value and URL path.
function objBackground(path, alt, href) {
	this.path = path;
	this.alt = alt;
	this.href = href;
}

// Select a random integer that is between 0 (inclusive) and max (exclusive)
function selectRandomB(max) {
	var r = Math.random();

	r *= max;
	r = parseInt(r);
	if (isNaN(r)) r = 0;
	else r %= max;
	
	return r;
}

function selectRandom(max) {
	var r = Math.random() * (max * 5);

	
	r = Math.round(r/5)
	
	return r
}

// Create a new background image object and store it in the background image array
function fillBackgroundImageArray(imagePath, imageAltTag, imageHref) {
	aryBackgroundImage[intArrayIndex++] = new objBackground(imagePath, imageAltTag, imageHref);	//increment the photo index and store the new image object into the array
}

// Redirects to the current visible vehicle model homepage
function gotoVehicleHomepage() {
	location.href = aryBackgroundImage[thisBG].href;
}

// Redirects to the model page given the index of the model
function gotoModelPagePath(aryValue) {
	location.href = aryModelPagePath[aryValue];
}

// Jellybean functionality start here
var beanTimeout;

function beanOn(imageName) {
	var theImage
	
	if (beanIsLoaded) {
		if (beanTimeout) {clearTimeout(beanTimeout)}
		theImage = eval("document." + ((is.ns) ? "jellyBeanDiv.document." : "all.") + "jBean");
		theImage.src =  imageName;
		jellyBean.show();
	}
}

function beanOff() {
	if (beanIsLoaded) {
		beanTimeout = setTimeout("jellyBean.hide()",1000);
	}
}
