// global vars
var iCounter = 0;
var iStepper = 2;
var iWaiter  = 100; //25; // 100;
var iTimeout = 18000; //16000;
var arPages = new Array(
				  							"focus/servex.html",
					  						"focus/printex.html",
						  					"focus/cryptlib.html",
						  					"focus/hostdrive.html",
//										  				"focus/transit.html",
							  				"focus/jprotector.html"
								  		 );
var visibleFrame   = "fader_1";
var invisibleFrame = "fader_2";	
var outfaderFrame  = "fader_1";
var infaderFrame   = "fader_2";											 
var preloaderPage  = arPages[1];
var timeoutID      = 0;			
var iWork          = 0;

function fade() 
{
	// calculate various indices
	iMod   = iCounter % arPages.length;
	iIndex = (iMod < (arPages.length - 1)) ? (iMod + 1) : 0;
	iWork  = (iIndex < (arPages.length - 1)) ? (iIndex + 1) : 0;
	// get access to next preloader page
  preloaderPage = arPages[iWork];
  // increment counter for next fader
	iCounter++;
	// get hold of frame about to fade in
	infaderFrame = document.getElementById(invisibleFrame);
	// set its new source
	infaderFrame.src = arPages[iIndex];
	// get hold of fader about to fade out
	outfaderFrame = document.getElementById(visibleFrame);
	// exchange for next call
	work           = visibleFrame;
	visibleFrame   = invisibleFrame;
	invisibleFrame = work;
	// and fade simultaneously
	doFade(100, 0);
} // fade

function doFade(outStep, inStep) 
{
  // decrease opacity of page to fade out
	outfaderFrame.style.opacity = outStep/100;
	outfaderFrame.style.filter  = "alpha(opacity=" + outStep + ")"; // IE
	outStep -= iStepper;
	// increase opacity of pade to fade in
	infaderFrame.style.opacity = inStep/100;
	infaderFrame.style.filter  = "alpha(opacity=" + inStep + ")"; // IE
	inStep += iStepper;
	// more to do?
	if (outStep >= 0) 
	  // that's the case => wait and then continue fading
		window.setTimeout(function () { doFade(outStep, inStep); }, iWaiter);
	else
{
		// preload next
		document.getElementById("fader_0").src = preloaderPage;
		// for a correct href load displayed doc into both frames 
		document.getElementById(invisibleFrame).src = document.getElementById(visibleFrame).src;
	} // else
} // doFade

function setProductInFocus() 
{
	// first call?
	if (true == fFirst)
	  // that's the case => simply change flag
	  fFirst = false;
	else
		// fade a bit
		fade();
  // wait for next shot
	timeoutID = setTimeout('setProductInFocus()', iTimeout);
} // setProductInFocus()

function Random() 
{
	// any timer active?
	if (0 != timeoutID)
	{
	  // that's the case => clear it
	  clearTimeout(timeoutID);
	  // reset
	  timeoutID = 0;
	} // if
	// set flag
	fFirst = true;
	// get a new random counter
	iCounter = Math.round(Math.random() * (arPages.length - 1));
	// set as source for fader_1
	document.getElementById("fader_1").src = arPages[iCounter];
	document.getElementById("fader_2").src = arPages[iCounter];
	// and start timer loop
	setProductInFocus();
} // Random()
