void CGUIWindowBoxeeWizardResolution::OnInitWindow()
{
   CGUIWindow::OnInitWindow();
   
   delete m_xrandr;
   m_xrandr = new CXRandR();
   
   if (!m_wizardCompletedOnce)
   {             
      CONTROL_DISABLE(CONTROL_NEXT);
   }
   
   if (m_afterResolutionChange)
   {
       CGUIListContainer *pList = (CGUIListContainer *)GetControl(CONTROL_SD_HD);
       if (pList)
         pList->SetSingleSelectedItem();

      ShowResolutionsList(IsResolutionHD(m_newResolution), &m_newResolution);     
      
      CStdString origHz;
      origHz.Format("%.2f", m_originalResolution.hz);
      CStdString newHz;
      newHz.Format("%.2f", m_newResolution.hz);

      if (m_newResolution.name != m_originalResolution.name || origHz != newHz)
      {
         CGUIDialogYesNo *pDlgYesNo = (CGUIDialogYesNo*)m_gWindowManager.GetWindow(WINDOW_DIALOG_YES_NO);
         pDlgYesNo->SetHeading("Resolution Change");
         pDlgYesNo->SetLine(0, "Do you want to keep this resolution");
         pDlgYesNo->SetLine(1, "(will revert automatically in 6 seconds)");
         pDlgYesNo->SetLine(2, "");
         pDlgYesNo->SetLine(3, "");
         pDlgYesNo->SetChoice(0, "Revert");
         pDlgYesNo->SetChoice(1, "Keep");
         pDlgYesNo->SetDefaultChoice(0);
         pDlgYesNo->SetAutoClose(6000);
         pDlgYesNo->DoModal();
         
         if (!pDlgYesNo->IsConfirmed())
         {
           m_afterResolutionChange = false;   
           // Set the requested resolution
           g_graphicsContext.SetVideoResolution(m_originalResolutionId, TRUE);
           // Reload the fonts to they will scale correctly
           g_fontManager.ReloadTTFFonts();
           // Close the dialog and restart it so it will re-set the size of the labels to 
           // fit for the new resolutions
           Close();
                    
           m_gWindowManager.ActivateWindow(WINDOW_BOXEE_WIZARD_RESOLUTION);
         }
         else
         {
            int xbmcResolutionId = GetXBMCResolutionId();
            if (xbmcResolutionId != -1)
            {
               g_guiSettings.SetInt("videoscreen.resolution", xbmcResolutionId);
               g_guiSettings.SetInt("videoplayer.displayresolution", xbmcResolutionId);
               g_guiSettings.SetInt("pictures.displayresolution", xbmcResolutionId);
               g_settings.Save();
               delete m_xrandr;
               m_xrandr = new CXRandR();
            }
         
            m_wizardCompletedOnce = true;
            CONTROL_ENABLE(CONTROL_NEXT);
            SET_CONTROL_FOCUS(CONTROL_NEXT, 0);            
         }
      }
      else
      {
         m_wizardCompletedOnce = true;
         CONTROL_ENABLE(CONTROL_NEXT);
         SET_CONTROL_FOCUS(CONTROL_NEXT, 0);         
      }
   }
   else if (m_resolutionChangedOnce || m_wizardCompletedOnce)
   {
      XOutput output = GetCurrentOutput();
      XMode currentResolution =  m_xrandr->GetCurrentMode(output.name);
      ShowResolutionsList(IsResolutionHD(currentResolution), &currentResolution);      
   }
   else
   {
      XOutput output = GetCurrentOutput();
      XMode currentResolution =  m_xrandr->GetCurrentMode(output.name);
      CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), CONTROL_SD_HD, IsResolutionHD(currentResolution) ? VALUE_HD : VALUE_SD);
      OnMessage(msg); 
   }
}