function OptionsHODlg::onWake(%this)
{
   if($pref::Video::fullScreen $= "true" || $pref::Video::fullScreen $= 1)
   {
      HOYesTick.setVisible(true);
      HONoTick.setVisible(false);
   }
   else
   {
      HOYesTick.setVisible(false);
      HONoTick.setVisible(true);
   }   
   
   HOSFXVolSlider.setValue($pref::SFX::channelVolume[$GuiAudioType]);
   HOMusicVolSlider.setValue($pref::SFX::channelVolume[$MusicAudioType]);
   
   sfxPlay(MusicMainMenu);
      
   Canvas.setWidescreen(OptionsHODlgCenter, 100, false);   
}

function OptionsHODlg::onResize(%this, %width, %height)
{
   Canvas.setWidescreen(OptionsHODlgCenter, 2000, true);
}

function OptionsHODlg::onSleep(%this)
{
   sfxStopAll();
}

function OptionsHODlg::playButtonPressSound(%this)
{
   sfxPlay(AudioButtonPress);
}

function OptionsHODlg::AudioUpdateSFXVolume(%this, %volume)
{
   %channel1 = $GuiAudioType;   
   %channel2 = $SimAudioType;
   
   sfxSetChannelVolume(%channel1, %volume);
   sfxSetChannelVolume(%channel2, %volume);   
   $pref::SFX::channelVolume[%channel1] = %volume;
   $pref::SFX::channelVolume[%channel2] = %volume;
   
   if (!isObject($AudioTestHandle))
      $AudioTestHandle = sfxPlayOnce(AudioButtonPress);
}

function OptionsHODlg::AudioUpdateMusicVolume(%this, %volume)
{   
   sfxSetChannelVolume($MusicAudioType, %volume);
   $pref::SFX::channelVolume[$MusicAudioType] = %volume;
}

function HOApplyGraphics()
{
   %newFullScreen = $pref::Video::fullScreen;
   
   if(%newFullScreen $= "true" || %newFullScreen $= 1)
   {
      %deskRes    = getFullscreenResolution();      
      %deskResX   = getWord(%deskRes, $WORD::RES_X);
      %deskResY   = getWord(%deskRes, $WORD::RES_Y);
      %aspectRatio = %deskResX / %deskResY;

      if(%aspectRatio > 4/3)
         %newRes = %deskResX SPC %deskResY;
         //%newRes = $pref::Video::ResolutionW;
      else
	      %newRes = $pref::Video::Resolution;
   }
   else
	   %newRes = $pref::Video::windowedRes;
	   
	%newBpp        = $pref::Video::BitsPerPixel;
	%newRefresh    = $pref::Video::RefreshRate;
	%newFSAA       = $pref::Video::FSAALevel;
	%newDevice     = $pref::Video::displayDevice;
   $pref::Video::displayDevice = %newDevice;

   %newMode = %newRes SPC %newFullScreen SPC %newBpp SPC %newRefresh SPC %newFSAA;
   if(%newMode !$= $pref::Video::mode)
   {
      $pref::Video::mode = %newMode;
      configureCanvas();
   }
}

// Toggle between windowed mode and full screen mode
function OptionsHODlg::ToggleFullScreen(%this, %full)
{
   sfxPlay(AudioButtonPress); //Button Press Sound
   
   if(%full $= "")
      $pref::Video::fullScreen = !$pref::Video::fullScreen;
   else
      $pref::Video::fullScreen = %full;   

   if($pref::Video::fullScreen $= "true" || $pref::Video::fullScreen $= 1)
   {
      HOYesTick.setVisible(true);
      HONoTick.setVisible(false);
   }
   else
   {
      HOYesTick.setVisible(false);
      HONoTick.setVisible(true);      
   }
      
   HOApplyGraphics();
   
   GuiCanvas::onResize(getWord(Canvas.Extent,0), getWord(Canvas.Extent,1));
}
