
//
// Quick links
// ************************************************************/
 
/*	

	To use add post data variable in the form of either 
	
	http://mysite.com/flashdemo/index.html?ibdm=1  				 // where 1 indicates the movie from the list below (zero indexed) OR
	http://mysite.com/flashdemo/index.html?ibdm=quick_overview   // where the name indicates the movie to be loaded 
	http://mysite.com/flashdemo/index.html?ibdm=14&try=true		 // where adding "&try=true" launches the try (if there is no try the watch it is launched instead) 
	http://mysite.com/flashdemo/index.html?loop=true
	
	Names of movies that can be loaded: 
	
	0	Intro
	1	Log on
	2	Setup a new recipient
	3	Making a payment
	4	Making a bulk payment	

*/

//
// Auto loop
// ************************************************************/

/*

	If the simulation is started using the following link: when in PlayAll mode and playback completes on the 
	last watch it the demo automatically plays all movies from the begining again infinitely  

	http://mysite.com/flashdemo/index.html?loop=true
	

*/

var ibdMovies = [ "quick_overview","how_to_register","log_on_off","help_and_support","security_and_personal_details","your_statements","applying_for_overdraft","text_alerts_and_mobile_banking","setting_up_payments","paying_bills_and_credit_cards","direct_debits_and_standing_orders","international_payments","applying_for_a_loan","applying_for_a_credit_card","ordering_travel_money"];
var ibdloop = false;
var ibdQuickLinkTimer;


// Load child movie if main loaded else try again in 1000 milliseconds 
function doStartMovie(childMovie, isTry)
{	
	var isCommandSent = false;
	var m = getFlashMovie();
		
	if(m && m.PercentLoaded() == 100)
	{
		setMovieName(childMovie);
		if(ibdloop == true)
		{
			setIsPlayallLoop();
		}

		if(isTry == "true")
		{			
			m.TGotoLabel("/main", "playtry");
		}
		else
		{
			m.TGotoLabel("/main", "playmovie");			
		}
		isCommandSent = true;
	}
	
	if(!isCommandSent)
	{
		ibdQuickLinkTimer = setTimeout("doStartMovie('" + childMovie + "', '" + isTry + "')", 1000);
	}
}



function doSetLoopOnly()
{
	var isCommandSent = false;
	var m = getFlashMovie();
			
	if(m && m.PercentLoaded() == 100)
	{
		setIsPlayallLoop();
		isCommandSent = true;
	}
	
	if(!isCommandSent)
	{
		ibdQuickLinkTimer = setTimeout("doSetLoopOnly()", 1000);
	}
}


// if post data includes movie to quick launch then do quick launch
function processPost()
{
	
	
	var s = window.location.toString();
	var pb = [];
	var movieName;
	var isTry = false;
	
	if(s.indexOf("?") != -1)
	{
		pb = s.split("?");
	}
	else if(s.indexOf(",") != -1)
	{
		pb = s.split(",");
	}	
	
	if(pb.length > 1)
	{
		var pbn = pb[1].split("&");
		for(var i = 0 ; i < pbn.length ; i++)
		{			
			var p = pbn[i].split("=");
			if(p[0] == "ibdm")
			{
				var r = /^[0-9]*$/;				
				if(r.test(parseInt(p[1], 10)))
				{
					movieName = ibdMovies[parseInt(p[1], 10)];
				}
				
			}
			if(p[0] == "try" && p[1] == "true")
			{
				isTry = true;
			}
			
			if(p[0] == "loop" && p[1] == "true")
			{
				
				ibdloop = true;
				
			}
		}
	}
	
	if(movieName && testValidMovie(movieName))
	{		
		ibdQuickLinkTimer = setTimeout("doStartMovie('" + movieName + "', '" + isTry + "')", 1000);
	}
	else if(ibdloop)
	{
		ibdQuickLinkTimer = setTimeout("doSetLoopOnly()", 1000);
	}
	
}

// Test to ensure the movie passed via post exists
function testValidMovie(childMovie)
{
	for(var i = 0 ; i < ibdMovies.length ; i++)
	{
		if(ibdMovies[i] == childMovie)
		{
			return true;
		}
	}
	return false;
}

function setMovieName(movieName)
{	
	var m = getFlashMovie();
	
	if(m)
	{
		m.SetVariable("movieTitle", movieName);
		m.SetVariable("isQuicklink", true);
	}
}

function setIsPlayallLoop()
{
	var m = getFlashMovie();
		
	if(m)
	{
		m.SetVariable("isPlayallLoop", true);
	}
}

function getFlashMovie()
{
	if(window.document["main"])
	{
		return window.document["main"];		
	}
	else if(document["main"])
	{
		return document["main"];
	}
	return null;
}

function getFlashVersion()
{	
	try // ie
	{
		try
		{
			// avoid fp6 minor version lookup issues
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try
			{
				axo.AllowScriptAccess = 'always';
			}
			catch(e)
			{
				return '6,0,0';
			}
		}
		catch(e){}

		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	}
	catch(e) // other browsers
	{

		try
		{
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
			{
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		}
		catch(e){}
	}
	return 'NA';
}

processPost();

