// JavaScript Document

// 2ci_Jscripts_Array_Adv.js
// Main Rollover Javascript functions

// Builds global arrays for image names based on inputs for number of icons, screenshots and logos.
// Caches a base path to 'root/images' folder from input
// Builds temp arrays of image objects to preload images 

// Maybe improve this by dropping tmp arrays and instea use names to load the image?
// Then in code check if img = null before displaying?
// remove vsafe in that case?

// Basepath to website 'images' folder
var vBasePath     = 'noPath';
// Global variable to flag is name arrays have been built and can be used
var vSafe         = 0;

// Global Arrays for Image Names
var vLogoNames    = new Array();
var vScreenNames  = new Array();
var vIconOnNames  = new Array();
var vIconOffNames = new Array();


// Simple build name function to account for leading '0' infront of number
// Note: Will NOT work with more than 99 files
function BuildName (tHead, tTail, tIndex)
{
	var tmpName = tHead;
	// Account for single digit
	if (tIndex < 10) tmpName = tmpName + "0";
	// Add actual index
    tmpName = tmpName + tIndex;
	tmpName = tmpName + tTail;
	return tmpName;
}


// Main preloader function
// Pass in the number of sequential icons (on and off total the same), screenshots and Logos
// Pass in the basepath modifier to be applied to url to link into root/images folder
function preloadPageImages(numIcons, numScreens, numLogos, basepath) 
{	
	if (document.images)
	{
		// window.status = 'downloading please wait';		
		var i = 0;
		vBasePath = basepath;	

		// New tmp array to hold preloads
		aImageIconOff = new Array ();
		aImageIconOn  = new Array ();
		aImageScreen  = new Array ();
		aImageLogo    = new Array ();
		
		// Preload on/off icons - always in pairs
		if (numIcons > 0 )
		{
			for	(i=0; i<numIcons; i++)
				{
				vIconOnNames[i]      = BuildName("icons/i", ".jpg", i+1 );
				vIconOffNames[i]     = BuildName("icons/ih", ".jpg", i+1 );		
				aImageIconOn[i]      = new Image();
				aImageIconOn[i].src  = vIconOffNames[i];
				aImageIconOff[i]     = new Image();		
				aImageIconOff[i].src = vIconOnNames[i];
				}
		}
		
		// Preload Screenshots - if any
		if (numScreens > 0 )
		{
			for	(i=0; i<numScreens; i++)
				{
				vScreenNames[i]     = BuildName("Screenshots/s",  ".jpg", i+1 );
				aImageScreen[i]     = new Image();
				aImageScreen[i].src =  vScreenNames[i];
				}
		}
		
		// Preload Logos - if any
		if (numLogos > 0 )
		{
			for	(i=0; i<numLogos; i++)
				{
				vLogoNames[i]     = BuildName("Logo/Logo",  ".jpg", i+1 );
				aImageLogo[i]     = new Image();
				aImageLogo[i].src =  vLogoNames[i]; 
				}
		}
		
		vSafe = 1;  // flag to tell functions that name arrays are full
		// window.status = '';
	} // endif doc.image
} 





// MouseOver - places highlighted icon 
// Supply indexNum as the number of the icon/screenshot to display
// To avoid updating the Logo image use logNum = -1 
function setHover(name, indexNum, logoNum)
{	
	if (document.images)
	{
		if (vSafe == 1)
		{
			// Force first icon to standard (off) as its auto lit when loading page		
			document.images.icon_01.src = vIconOnNames[0];
			// Update screenshot
			document.images.vScreen.src = vScreenNames[indexNum-1];
			// Update Logo if requested
			if (logoNum > 0)	{ document.images.vLogo.src   = vLogoNames[logoNum-1]; }  // &&  vLogoNames[logoNum-1] != 'undefined'
			// update Icon
			obj = eval('document.images.' + name);
			obj.src = vIconOffNames[indexNum-1];	
			//window.status = 'Passed';
			//return true;
		}
	}
	
	//window.status = 'Failed';
	//return true;
}


// Mouseout - places standard icon 
// Supply indexNum as the number of the icon/screenshot to display
// To avoid updating the Logo image use logNum = -1 
function setNormal(name, indexNum, logoNum)
{
	if (document.images)
	{
		if (vSafe == 1 )
		{
		// Update screenshot back to background view
		document.images.vScreen.src = vBasePath + "images/bgAssets/V_ScreenshotBlankborder.jpg";
		// Update Logo if requested
		if (logoNum > 0) 	{ document.images.vLogo.src   = vBasePath + "images/bgAssets/V_LogoBlank.jpg"; }
		// update Icon
		obj = eval('document.images.' + name);
		obj.src = vIconOnNames[indexNum-1];	
		}
	}
}









/*

		// Limit max images
		if (numIcons   > 24) numIcons   = 24;
		if (numScreens > 24) numScreens = 24;
		if (numLogos   > 12) numLogos   = 12;
		
		
function isDefined(property) {
  return (typeof property != 'undefined');
}


function BuildNameArrays(numIcons, numScreens, numLogos) 
{
	var i = 0;
	// Build Names
	for	(i=0; i<numIcons; i++)
	{			
		vIconOnNames[i]  = BuildName("icons/i", ".jpg", i+1 );
		vIconOffNames[i] = BuildName("icons/ih", ".jpg", i+1 );
	}
	
	for	(i=0; i<numScreens; i++)
		{  vScreenNames[i] = BuildName("Screenshots/s",  ".jpg", i+1 ); 	}
		
	for	(i=0; i<numLogos; i++)
		{  vLogoNames[i] = BuildName("Logo/Logo",  ".jpg", i+1 ); 	}
}
*/
