//--------------------------------------------------------------------------
//
// DLO Wildcard Script v1.0
//
// To use this script each page needs to include the following elements:
//
// imgWildcard - image placeholder
// lnkWildcard - used to set the linking properties
//
// ** - the page must also have access to MM_SwapImages
//--------------------------------------------------------------------------

// Use 3 array elements per wildcard (1 - image / 2 - over state image / 3 - navigate url)
wildcards = new Array()

// In House Banner 01 Wildcard
wildcards[0] = '../images/GFX/Wildcard/housebnnr01_prod.gif'
wildcards[1] = '../images/GFX/Wildcard/housebnnr01_over_prod.gif'
wildcards[2] = '../images/GFX/Wildcard/housebnnr01_supp.gif'
wildcards[3] = '../images/GFX/Wildcard/housebnnr01_over_supp.gif'
wildcards[4] = '../images/GFX/Wildcard/housebnnr01_Stor.gif'
wildcards[5] = '../images/GFX/Wildcard/housebnnr01_over_Stor.gif'
//wildcards[6] = '../adlinks/housebnnr01.tpl?command=showpage&cart='
wildcards[6] = '../openfm/openfm_web.tpl?command=showpage&cart='

// In House Banner 02 Wildcard
wildcards[7] =  '../images/GFX/Wildcard/housebnnr02_prod.gif'
wildcards[8] =  '../images/GFX/WildCard/housebnnr02_over_prod.gif'
wildcards[9] =  '../images/GFX/Wildcard/housebnnr02_supp.gif'
wildcards[10] = '../images/GFX/WildCard/housebnnr02_over_supp.gif'
wildcards[11] = '../images/GFX/Wildcard/housebnnr02_stor.gif'
wildcards[12] = '../images/GFX/WildCard/housebnnr02_over_stor.gif'
//wildcards[13] = '../adlinks/housebnnr02.tpl?command=showpage&cart='
wildcards[13] = '../openfm/openfm_web.tpl?command=showpage&cart='

// Randomly select the starting index
var rand_max = (wildcards.length / 7) - 1;
var start_index = get_random(rand_max) * 7;

// Preload the images
MM_preloadImages(wildcards[start_index]);
MM_preloadImages(wildcards[start_index + 1]);
MM_preloadImages(wildcards[start_index + 2]);
MM_preloadImages(wildcards[start_index + 3]);
MM_preloadImages(wildcards[start_index + 4]);
MM_preloadImages(wildcards[start_index + 5]);

// Functions for setting the WildCard over/out
function wildcardOver()
{
	getPageElement("imgWildcard").src = wildcards[start_index + 1];
}

function wildcardOut()
{
	getPageElement("imgWildcard").src = wildcards[start_index];
}

// Cross Browser support for getElementById
function getPageElement(id)
{
	if(document.layers)
	{ return document.layers[id]; }
	
	if(document.all)
	{ return document.all[id]; }
	
	if(!document.all && document.getElementById)
	{ return document.getElementById(id); }
	
	return false;
}


// Function that returns a random number from 0 to inputNumber
function get_random(inputNumber)
{
    var ranNum= Math.round(Math.random()*inputNumber);
    return ranNum;
}

// LoadWildcard needs to be called in the body.onLoad() event
function LoadWildcard(section,cartID)
{
	wildcards[6] += cartID
	wildcards[13] += cartID
	
	var link_index = start_index + 6;
	
	if (section == 'supp')
		start_index += 2;
	else if (section == 'stor')
		start_index += 4;
	
	// Set the image
	var imgWildcard = getPageElement("imgWildcard");
	
	if (imgWildcard != false)
		imgWildcard.src = wildcards[start_index];
		
	// Set the link info
	var lnkWildcard = getPageElement("lnkWildcard");
	
	if (lnkWildcard != false)
		lnkWildcard.href = wildcards[link_index];
}