	var idFromBrowseTo = 0;

	function passToFlash( flashId, varName, varValue )
	{
		var flashObj = null;
		
		flashObj = window.top.document.getElementById( flashId );

		if( flashObj )
		{
			if( typeof( flashObj.SetVariable ) != "undefined" )
			{
				// as2 (also called, but not working for as3)
				flashObj.SetVariable( varName, varValue );
			}

			// as3
			if( 	( typeof( flashObj.openPageDynamic ) != "undefined" ) 
				&&	( varName == "activePageId" ) )
			{
				if( varValue )
				{
					flashObj.openPageDynamic( varValue );
				}
			}
			
			
			
			if( 	( typeof( flashObj.browserWindowWidth ) != "undefined" ) 
					&&	( varName == "windowWidth" ) )
			{
				if( varValue )
				{
					flashObj.browserWindowWidth( varValue );
				}
			}
			
			if( 	( typeof( flashObj.browserWindowHeight ) != "undefined" ) 
					&&	( varName == "windowHeight" ) )
			{
				if( varValue )
				{
					flashObj.browserWindowHeight( varValue );
				}
			}
		}
	}
	
	function SetDimensions()
	{
		passToFlash( "swfobjId", "windowWidth", document.body.clientWidth );
		passToFlash( "swfobjId", "windowHeight", document.body.clientHeight );
	}
	

	function historyHandler()
	{
		this.onAddressChange = function( event )
		{
			if( event && event.path && event.path.length )
			{
				var menuId = getIdFromPath( event.path );
				
				if( menuId.length )
				{
					if( idFromBrowseTo != menuId )
					{
						pushDeeplink( menuId );
					}
				}
				
				idFromBrowseTo = 0;
			}
			
		};
		
		this.olgaAddHistory = function( data )
		{
			
			if ( data && data.length && ( data != "0" ) )
			{
				var currentId = getIdFromPath( SWFAddress.getValue() );
				if( currentId != data )
				{
					idFromBrowseTo = data;
					SWFAddress.setValue( data );
				}
				
				// TODO xml request the title from the back-end and store it in an array
				var pageTitle = data;
				// SWFAddress.setTitle( pageTitle );
				
				// add to statistics tracker
				if( typeof( trackStatistics ) == "function" ) 
					trackStatistics( pageTitle );
			}
		};
		
		
	};

	function pushDeeplink( id )
	{
		passToFlash( "swfobjId", "activePageId", id );
	}

	function getIdFromPath( path )
	{
		var menuId		= "";
		var firstChar	= path.substr( 0, 1 );
		if( ( firstChar == "/" ) && ( path.length > 1 ) )
		{
			menuId = path.substr( 1 );
		}
		else
		{
			if( path != "/" )
				menuId = path;
		}
		return( menuId )
	}
	
	Event.observe(window, "load", function(event)
	{
		if( window.document.location.hash.length )
			menuId = getIdFromPath( window.document.location.hash.replace( "#", "" ) );
		
		document.historyHandler = new historyHandler();
		// SWFAddress.addEventListener( SWFAddressEvent.EXTERNAL_CHANGE, document.historyHandler.onAddressChange );
		// IE(8) needs SWFAddressEvent.CHANGE...
		SWFAddress.addEventListener( SWFAddressEvent.CHANGE, document.historyHandler.onAddressChange );
		LoadFlash();
	});

	Event.observe(window, "resize", function(event) {SetDimensions();});
