
//-------------------------------------------------------------------------------------------------------------------------------------
//-- Globals
//-------------------------------------------------------------------------------------------------------------------------------------

var objCurrentMovie = null;
var strFlashFile = "";
var strSavedURL = "";
var strWebMode = "";
var strEnsureLatest = "";
var strAlternativeOutput = "";
var bIsReady = false;
var nTimer = -1;

var objTrace;
var nAttemptCount = 0;

//-------------------------------------------------------------------------------------------------------------------------------------
//-- Flash API
//-------------------------------------------------------------------------------------------------------------------------------------

function JS_API_GetMovie ( strMovieName )
{
	if (navigator.appName.indexOf ("Microsoft") != -1) return window[strMovieName];
	else return document[strMovieName];
}

//-------------------------------------------------------------------------------------------------------------------------------------
//-- Banner functions
//-------------------------------------------------------------------------------------------------------------------------------------

function JS_API_BannerWrite ()
{
	strFlashFile = 'SWF/BannerLoader.swf';
	strWebMode = '?web=true';
	strEnsureLatest = '&ensurelatest=' + new Date();
	strAlternativeOutput = '<a href="jobsearch.php" title="Search for Jobs"><img src="Images/Banners/NoFlash.jpg" alt="Search for Jobs" /></a>';
	
	JS_Flash_Write ( 'Banner', strFlashFile + strWebMode + strEnsureLatest, 522, 192, 7, false, strAlternativeOutput, '', '' );
}

// Called from within Flash movie
function JS_API_BannerReady ()
{
	bIsReady = true;
	//objTrace.innerHTML += "ready : " + bIsReady + "<br/>";
}

// Called from within Flash movie
function JS_API_BannerSearch ()
{
	AdvSearchWithFilters();
	//window.open('jobsearch.php','_self');
}
	
function JS_API_BannerLoadFile ( strNewURL )
{
	JS_Banner_ClearLoad(); // cancel any current load process
	strSavedURL = strNewURL; // save the new URL
	JS_Banner_TryLoad(); // try to load
}

function JS_Banner_TryLoad ()
{
	if (!objCurrentMovie) objCurrentMovie = JS_API_GetMovie("Banner"); // get flash object	
	
	if ( bIsReady && objCurrentMovie )
	{
		//objTrace.innerHTML += "loaded <br/>";
		objCurrentMovie.SetVariable("strExternalURL", strSavedURL); // set var in flash
		objCurrentMovie.LoadFile(); // call function to load new movie
		JS_Banner_ClearLoad();
	}
	else
	{
		//objTrace.innerHTML += "not ready <br/>";
		nTimer = setTimeout ( "JS_Banner_TryLoad()", 500 ); // banner not initialised, wait a second then try again	
		
		nAttemptCount ++;			
		if ( nAttemptCount > 3 ) bIsReady = true;
	}	
	
}

function JS_Banner_ClearLoad ()
{
	clearTimeout(nTimer);
}

//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------


