void InitDocument(bool forceLoad)
	{
		// may be serliazing an already initialized object, ensure we handle reference
		// counting correctly.
		if (m_pCompilingNotification)
		{
			m_pCompilingNotification->RemoveReference();
			m_pCompilingNotification = 0;
		}

		// Load the compiling notification rml
		IGUISystem* pGUI = PerModuleInterface::g_pSystemTable->pGUISystem;

		if (forceLoad)
		{
			// Clear style sheet cache so any changes to RCSS files will be applied
			pGUI->ClearStyleSheetCache();
		}

		IGUIDocument* pDocument = forceLoad ? NULL : pGUI->GetDocument("CompilingNotification");
		if (pDocument == NULL)
		{
			pDocument = pGUI->LoadDocument("/GUI/compiling-notification.rml", "CompilingNotification");
		}

		if (pDocument != NULL)
		{
			pDocument->Show();
			m_pCompilingNotification = pDocument->Element()->GetElementById("compiling");
			
			pDocument->RemoveReference();
		}
	}
	void InitDocument(bool forceLoad)
	{
		// may be serliazing an already initialized object, ensure we handle reference
		// counting correctly.
		if (m_pCounterElement)
		{
			m_pCounterElement->RemoveReference();
			m_pCounterElement = 0;
		}

		// Load and show the fps counter
		SystemTable* pSystemTable = PerModuleInterface::GetInstance()->GetSystemTable();
		IGUISystem* pGUI = pSystemTable->pGUISystem;

		if (forceLoad)
		{
			// Clear style sheet cache so any changes to RCSS files will be applied
			pGUI->ClearStyleSheetCache();
		}

		IGUIDocument* pDocument = forceLoad ? NULL : pGUI->GetDocument("FPSCounter");
		if (pDocument == NULL)
		{
			pDocument = pGUI->LoadDocument("/Assets/GUI/fps-counter.rml", "FPSCounter");
		}

		if (pDocument != NULL)
		{
			pDocument->Show();
			m_pCounterElement = pDocument->Element()->GetElementById("fps");
			
			pDocument->RemoveReference();
		}
	}
	void InitDocument(bool forceLoad)
	{
		// may be serializing an already initialized object, ensure we handle reference
		// counting correctly.
		if (m_pSplashElement)
		{
			m_pSplashElement->RemoveEventListener( "click", this, 0 );
			m_pSplashElement->RemoveReference();
			m_pSplashElement = 0;
		}
		if (m_pDocument)
		{
			m_pDocument->RemoveReference();
			m_pDocument = 0;
		}

		// Load and show the splashscreen
		IGUISystem* pGUI = PerModuleInterface::g_pSystemTable->pGUISystem;

		if (forceLoad)
		{
			// Clear style sheet cache so any changes to RCSS files will be applied
			pGUI->ClearStyleSheetCache();
		}

		//Always load document in order to reset its state correctly
		m_pDocument = pGUI->LoadDocument("/GUI/splashscreen.rml", "Splashscreen");


		if (m_pDocument != NULL)
		{
			m_pDocument->Show();
			m_pSplashElement = m_pDocument->Element()->GetElementById("splash");
			m_pSplashElement->AddEventListener( "click", this, 0 );
		}
	}
	void InitDocument(bool forceLoad)
	{
		// may be serializing an already initialized object, ensure we handle reference
		// counting correctly.
		if (m_pInputElement)
		{
			m_pInputElement->RemoveEventListener( "click", this, 0 );
			m_pInputElement->RemoveReference();
			m_pInputElement = 0;
		}
		if ( m_pInfoElement )
		{
			m_pInfoElement->RemoveReference();
			m_pInfoElement = 0;
		}

		// Load and show the input element
		SystemTable* pSystemTable = PerModuleInterface::GetInstance()->GetSystemTable();
		IGUISystem* pGUI = pSystemTable->pGUISystem;

		if (forceLoad)
		{
			// Clear style sheet cache so any changes to RCSS files will be applied
			pGUI->ClearStyleSheetCache();
		}

		IGUIDocument* pDocument = forceLoad ? NULL : pGUI->GetDocument("Input");
		if (pDocument == NULL)
		{
			pDocument = pGUI->LoadDocument("/Assets/GUI/input.rml", "Input");
		}

		if (pDocument != NULL)
		{
			pDocument->Show();
			m_pInputElement = pDocument->Element()->GetElementById("input");
			m_pInputElement->AddEventListener( "click", this, 0 );

			// Make input element same size as window
			char buff[16];
			float windowWidth, windowHeight;
			PerModuleInterface::GetInstance()->GetSystemTable()->pGame->GetWindowSize( windowWidth, windowHeight );
			_itoa_s( (int)windowWidth, buff, 10 );
			m_pInputElement->SetProperty( "width", buff );
			_itoa_s( (int)windowHeight, buff, 10 );
			m_pInputElement->SetProperty( "height", buff );
			
			// Set up info element in the bottom right corner
			m_pInfoElement = pDocument->Element()->GetElementById("info");
			m_pInfoElement->SetProperty( "display", "none" );

			int left;
			left = (int)( windowWidth - m_pInfoElement->GetClientWidth() );
			_itoa_s( left, buff, 10 );
			m_pInfoElement->SetProperty( "left", buff );
			
			int top;
			top = (int)( windowHeight - m_pInfoElement->GetClientHeight() );
			_itoa_s( top, buff, 10 );
			m_pInfoElement->SetProperty( "top", buff );
			

			pDocument->RemoveReference();
		}
	}