var isMSIE = false;
var isFirefox = false;
if ( navigator.userAgent.indexOf ( 'MSIE' ) > -1 ) {
	isMSIE = true;
}
if ( navigator.userAgent.indexOf ( 'Firefox' ) > -1 ) {
	isFirefox = true;
}



var FlashStarted = false;
var SetPage = function ( ) {
	FlashStarted = true;
	document.getElementById ( "BackgroundHidden" ).style.visibility = "hidden";
	document.getElementById ( "BackgroundSWF" ).SetVariable ( "/:Page" , Page ); 
	document.getElementById ( "BackgroundSWF" ).SetPage ( );
};

var ScrollPointMax = 400;
var CheckScroll = function ( ) {
	var ScrollPoint = document.body.scrollTop;
	if ( ! ScrollPoint ) {
		ScrollPoint = document.documentElement.scrollTop;
	}
	if ( FlashStarted ) {
		if ( ScrollPoint >= ScrollPointMax ) { 
			document.getElementById ( "BackgroundSWF" ).SetVariable ( "/:PlayWater" , "Off" );
			
		} else {
			document.getElementById ( "BackgroundSWF" ).SetVariable ( "/:PlayWater" , "On" ); 
		} 
	}
};

var AnimateAlpha;
var AnimatePersonNew;
var AnimateInterval;
var AnimateDirection;
var SetPerson = function ( Person ) {
	if ( AnimateAlpha ) {
		return;
	}
	AnimatePersonNew = Person;
	ScrollPointMax = 0;
	
	// Fade in.
	//document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.opacity = 0;
	//document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.MozOpacity = 0;
	//document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.filter = "alpha(opacity=" + 0 + ")"; 
	document.getElementById ( AnimatePersonNew ).style.visibility = "visible";
	document.getElementById ( "PeopleMatrixContent" ).style.visibility = "hidden";
	//AnimateAlpha = 0;
	//AnimateDirection = true;
	//AnimateInterval = setInterval ( SetPersonDoAlphaAnimate , 10 );
	
	if ( typeof Taipan != 'undefined' && Taipan.EditMode ) {
		Taipan.WindowResize ( );
	}
};

var ResetPerson = function ( ) {
	if ( AnimateAlpha < 100 ) {
		return;
	}
	ScrollPointMax = 0;
	
	// Fade out.
	document.getElementById ( "PeopleMatrixContent" ).style.visibility = "visible";
	document.getElementById ( AnimatePersonNew ).style.visibility = "hidden";
	AnimateDirection = false;
	//AnimateInterval = setInterval ( SetPersonDoAlphaAnimate , 10 );
	
	if ( typeof Taipan != 'undefined' && Taipan.EditMode ) {
		Taipan.WindowResize ( );
	}
};
	
var SetPersonDoAlphaAnimate = function ( ) {	
	if ( AnimateDirection ) {	
		AnimateAlpha += 20;
		
		if ( AnimateAlpha > 100 ) {
			AnimateAlpha = 100;				
			clearInterval ( AnimateInterval );
			AnimateInterval = false;
			ScrollPointMax = 400;
			document.getElementById ( "AboutUsPeopleMatrixTable" ).style.visibility = "hidden";
		}
	} else {
		AnimateAlpha -= 20;
		
		if ( AnimateAlpha < 0 ) {
			AnimateAlpha = 0;				
			clearInterval ( AnimateInterval );
			AnimateInterval = false;
			ScrollPointMax = 400;
			document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.visibility = "hidden";
		}
	}
	
	document.getElementById ( "AboutUsPeopleMatrixTable" ).style.opacity = ( 100 - AnimateAlpha ) / 100;
	document.getElementById ( "AboutUsPeopleMatrixTable" ).style.MozOpacity = ( 100 - AnimateAlpha ) / 100;
	if (isMSIE) {
		document.getElementById ( "AboutUsPeopleMatrixTable" ).style.filter = "alpha(opacity="+( 100 - AnimateAlpha )+")"; 
	}
	
	document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.opacity = AnimateAlpha / 100;
	document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.MozOpacity = AnimateAlpha / 100;
	if (isMSIE) {
		document.getElementById ( "AboutUsPerson" + AnimatePersonNew ).style.filter = "alpha(opacity="+AnimateAlpha+")";
	}
};

var ShowLightbox = function ( Page ) {
	var LightboxHideAll = document.getElementById ( "LightboxHideAll" );
	var Lightbox = document.getElementById ( "Lightbox" );
	var LightboxTitle = document.getElementById ( "LightboxTitle" );
	var LightboxHTML = document.getElementById ( "LightboxHTML" );
	var LightboxFlash = document.getElementById ( "LightboxFlash" );
	var ContactUsFormFieldSelectah = document.getElementById ( "ContactUsFormFieldSelectah" );
	
	
	var Title;
	var Src;
	var Video;
	switch ( Page ) {
		case "UnderstandingSeries":
			Title = "Understanding Series";
			Src = "LightboxUnderstandingSeries.html";
			break;
			
		case "GeneralAdviceWarning":
			Title = "General Advice Warning";
			Src = "LightboxGeneralAdviceWarning.html";
			break;
			
		case "PrivacyStatement":
			Title = "Privacy Statement";
			Src = "LightboxPrivacyStatement.html";
			break;
			
		case "NewsArchive":
			Title = "Newsletter Archive";
			Src = "LightboxNewsArchive.html";
			break;
			
		case "LocationMap":
			Title = "Level 1, Rosny Plaza, 18 Ross Avenue";
			Src = "LightboxLocationMap.html";
			break;			
			
		case "MLCOwenFund":			
		case "MLCNatalieRules":			
		case "MLCParkerMarket":
		case "MLCMichelleStayingInvested":			
		case "MLCBrianLatestEconomic":			
		case "MLCBrianComparingApples":
			Video = "Flash/" + Page + ".swf";
			break;
	}
	
	if ( ! Src ) {
		LightboxHTML.style.visibility = "hidden";
	} else {
		LightboxHTML.style.visibility = "visible";
		LightboxHTML.src = "Templates/"+Src;
	}
	
	if ( ! Video ) {
		LightboxFlash.style.visibility = "hidden";
	} else {
		LightboxFlash.style.visibility = "visible";
		
		var flashvars = { };
		var params = {
			menu: "false"
		};
		var attributes = {
			id: "LightboxFlash",
			name: "LightboxFlash"
		};
		
		swfobject.embedSWF(Video, "LightboxFlash", "320", "180", "9.0.0","", flashvars, params, attributes);
	}
	
	// send to top of window.
	scroll ( 0 , 0 );
	
	if ( ! Title ) {
		LightboxTitle.style.visibility = "hidden";
	} else {
		LightboxTitle.style.visibility = "visible";
		LightboxTitle.innerHTML = Title;	
	}
	
	if ( isMSIE && ContactUsFormFieldSelectah ) {
		ContactUsFormFieldSelectah.style.visibility = 'hidden';	
	}
	LightboxHideAll.style.visibility = 'visible';
	Lightbox.style.visibility = 'visible';		
};

var HideLightbox = function ( ) {
	var LightboxHideAll = document.getElementById ( "LightboxHideAll" );
	var Lightbox = document.getElementById ( "Lightbox" );	
	var LightboxFlash = document.getElementById ( "LightboxFlash" );
	var LightboxTitle = document.getElementById ( "LightboxTitle" );
	var LightboxHTML = document.getElementById ( "LightboxHTML" );
	var ContactUsFormFieldSelectah = document.getElementById ( "ContactUsFormFieldSelectah" );	
	LightboxHideAll.style.visibility = 'hidden';
	Lightbox.style.visibility = 'hidden';
	LightboxTitle.style.visibility = "hidden";
	LightboxHTML.style.visibility = "hidden";
	LightboxFlash.style.visibility = "hidden";
	LightboxFlash.innerHTML = "";
	if ( isMSIE && ContactUsFormFieldSelectah ) {
		ContactUsFormFieldSelectah.style.visibility = 'visible';	
	}
};

var StartFlash = function ( ) {
	var flashvars = { };	
	var params = {
		menu: "false",
		wmode: "opaque",
		AllowScriptAccess: "always"
	};
	var attributes = {
		id: "BackgroundSWF",
		name: "BackgroundSWF"
	};
	
	swfobject.embedSWF ( "Flash/Background.swf", "BackgroundSWF", "955", "600", "9.0.0","", flashvars, params, attributes );
};



if ( isMSIE ) {
	
	window.attachEvent ( 'onload' , StartFlash );
	//setInterval ( CheckScroll , 100 );
} else {
	StartFlash ();
}


if ( typeof Taipan !== "undefined" ) {
	var TestTaipan = setInterval ( function ( ) {
		if ( FlashStarted ) {
			clearInterval ( TestTaipan );
			document.getElementById ( "BackgroundSWF" ).SetVariable ( "/:PlayWater" , "Off" );
		}
	} , 100 );
}

