//-----------------------------------------------------------------------------
// Handle events of GUI controls of the play minigame menu.
//-----------------------------------------------------------------------------

function playMinigameDlg::onWake(%this)
{
   %this.isPlayingMinigame = false;
   
   //%pXml = loadMenuXML();
   //parsePlayMinigameMenuXML(%pXml);
   //%pXml.delete();
   
   Canvas.setWidescreen(PlayMinigameDlgCenter, 100, false);
   
   %this.page = 1;
   %this.update();
}

function PlayMinigameDlg::pm1(%this)
{
   switch(%this.page)
   {
      case 1: %this.playMinigame(1);
      case 2: %this.playMinigame(6);
      case 3: %this.playMinigame(15);
      case 4: %this.playMinigame(7);
   }
}

function PlayMinigameDlg::pm2(%this)
{
   switch(%this.page)
   {
      case 1: %this.playMinigame(2);
      case 2: %this.playMinigame(5);
      case 3: %this.playMinigame(16);
      case 4: %this.playMinigame(14);
   }   
}


function PlayMinigameDlg::pm3(%this)
{
   switch(%this.page)
   {
      case 1: %this.playMinigame(11);
      case 2: %this.playMinigame(9);
      case 3: %this.playMinigame(4);
      case 4: %this.playMinigame(10);
   }   
}

function PlayMinigameDlg::pm4(%this)
{
   switch(%this.page)
   {
      case 1: %this.playMinigame(12);
      case 2: %this.playMinigame(13);
      case 3: %this.playMinigame(3);
      case 4: %this.playMinigame(8);
   }         
}

function PlayMinigameDlg::previous(%this)
{
   %this.page--;
   if(%this.page < 1)
      %this.page = 4;
   
   %this.update();
}

function PlayMinigameDlg::next(%this)
{
   %this.page++;
   if(%this.page > 4)
      %this.page = 1;
      
   %this.update();      
}

function PlayMinigameDlg::update(%this)
{
   %path = "scriptsAndAssets/data/ui/menu/minigames/page" @ %this.page @ "/"; //
   
   %path = %path @ %this.page @ "_";
   
   PM1.setBitmap(%path @ "1");
   PM2.setBitmap(%path @ "2");
   PM3.setBitmap(%path @ "3");
   PM4.setBitmap(%path @ "4");
   
   %setActive1 = false;
   %setActive2 = false;
   %setActive3 = false;
   %setActive4 = false;
   
   %num1 = 1;
   %num2 = 1;
   %num3 = 1;
   %num4 = 1;
   
   switch$($CurPlayerNum)
   {
      case 1:
         switch(%this.page)
         {
            case 1:
               if(PlayerProfile.Minigame1_1)  { %setActive1 = true; %num1 = 1;  }
               if(PlayerProfile.Minigame2_1)  { %setActive2 = true; %num2 = 2;  }
               if(PlayerProfile.Minigame11_1) { %setActive3 = true; %num3 = 11; }
               if(PlayerProfile.Minigame12_1) { %setActive4 = true; %num4 = 12; }
            case 2:
               if(PlayerProfile.Minigame6_1)  { %setActive1 = true; %num1 = 6;  }
               if(PlayerProfile.Minigame5_1)  { %setActive2 = true; %num2 = 5;  }
               if(PlayerProfile.Minigame9_1)  { %setActive3 = true; %num3 = 9;  }
               if(PlayerProfile.Minigame13_1) { %setActive4 = true; %num4 = 13; } 
            case 3:
               if(PlayerProfile.Minigame15_1) { %setActive1 = true; %num1 = 15; }
               if(PlayerProfile.Minigame16_1) { %setActive2 = true; %num2 = 16; }
               if(PlayerProfile.Minigame4_1)  { %setActive3 = true; %num3 = 4;  }
               if(PlayerProfile.Minigame3_1)  { %setActive4 = true; %num4 = 3;  }
            case 4:
               if(PlayerProfile.Minigame7_1)  { %setActive1 = true; %num1 = 7;  }
               if(PlayerProfile.Minigame14_1) { %setActive2 = true; %num2 = 14; }
               if(PlayerProfile.Minigame10_1) { %setActive3 = true; %num3 = 10; }
               if(PlayerProfile.Minigame8_1)  { %setActive4 = true; %num4 = 8;  }    
         }
      case 2:
         switch(%this.page)
         {
            case 1:
               if(PlayerProfile.Minigame1_2)  { %setActive1 = true; %num1 = 1;  }
               if(PlayerProfile.Minigame2_2)  { %setActive2 = true; %num2 = 2;  }
               if(PlayerProfile.Minigame11_2) { %setActive3 = true; %num3 = 11; }
               if(PlayerProfile.Minigame12_2) { %setActive4 = true; %num4 = 12; }
            case 2:
               if(PlayerProfile.Minigame6_2)  { %setActive1 = true; %num1 = 6;  }
               if(PlayerProfile.Minigame5_2)  { %setActive2 = true; %num2 = 5;  }
               if(PlayerProfile.Minigame9_2)  { %setActive3 = true; %num3 = 9;  }
               if(PlayerProfile.Minigame13_2) { %setActive4 = true; %num4 = 13; }    
            case 3:
               if(PlayerProfile.Minigame15_2) { %setActive1 = true; %num1 = 15; }
               if(PlayerProfile.Minigame16_2) { %setActive2 = true; %num2 = 16; }
               if(PlayerProfile.Minigame4_2)  { %setActive3 = true; %num3 = 4;  }
               if(PlayerProfile.Minigame3_2)  { %setActive4 = true; %num4 = 3;  }
            case 4:
               if(PlayerProfile.Minigame7_2)  { %setActive1 = true; %num1 = 7;  }
               if(PlayerProfile.Minigame14_2) { %setActive2 = true; %num2 = 14; }
               if(PlayerProfile.Minigame10_2) { %setActive3 = true; %num3 = 10; }
               if(PlayerProfile.Minigame8_2)  { %setActive4 = true; %num4 = 8;  }    
         }
      case 3:
         switch(%this.page)
         {
            case 1:
               if(PlayerProfile.Minigame1_3)  { %setActive1 = true; %num1 = 1;  }
               if(PlayerProfile.Minigame2_3)  { %setActive2 = true; %num2 = 2;  }
               if(PlayerProfile.Minigame11_3) { %setActive3 = true; %num3 = 11; }
               if(PlayerProfile.Minigame12_3) { %setActive4 = true; %num4 = 12; }
            case 2:
               if(PlayerProfile.Minigame6_3)  { %setActive1 = true; %num1 = 6;  }
               if(PlayerProfile.Minigame5_3)  { %setActive2 = true; %num2 = 5;  }
               if(PlayerProfile.Minigame9_3)  { %setActive3 = true; %num3 = 9;  }
               if(PlayerProfile.Minigame13_3) { %setActive4 = true; %num4 = 13; }    
            case 3:
               if(PlayerProfile.Minigame15_3) { %setActive1 = true; %num1 = 15; }
               if(PlayerProfile.Minigame16_3) { %setActive2 = true; %num2 = 16; }
               if(PlayerProfile.Minigame4_3)  { %setActive3 = true; %num3 = 4;  }
               if(PlayerProfile.Minigame3_3)  { %setActive4 = true; %num4 = 3;  }
            case 4:
               if(PlayerProfile.Minigame7_3)  { %setActive1 = true; %num1 = 7;  }
               if(PlayerProfile.Minigame14_3) { %setActive2 = true; %num2 = 14; }
               if(PlayerProfile.Minigame10_3) { %setActive3 = true; %num3 = 10; }
               if(PlayerProfile.Minigame8_3)  { %setActive4 = true; %num4 = 8;  }    
         }
      case 4:
         switch(%this.page)
         {
            case 1:
               if(PlayerProfile.Minigame1_4)  { %setActive1 = true; %num1 = 1;  }
               if(PlayerProfile.Minigame2_4)  { %setActive2 = true; %num2 = 2;  }
               if(PlayerProfile.Minigame11_4) { %setActive3 = true; %num3 = 11; }
               if(PlayerProfile.Minigame12_4) { %setActive4 = true; %num4 = 12; }
            case 2:
               if(PlayerProfile.Minigame6_4)  { %setActive1 = true; %num1 = 6;  }
               if(PlayerProfile.Minigame5_4)  { %setActive2 = true; %num2 = 5;  }
               if(PlayerProfile.Minigame9_4)  { %setActive3 = true; %num3 = 9;  }
               if(PlayerProfile.Minigame13_4) { %setActive4 = true; %num4 = 13; }    
            case 3:
               if(PlayerProfile.Minigame15_4) { %setActive1 = true; %num1 = 15; }
               if(PlayerProfile.Minigame16_4) { %setActive2 = true; %num2 = 16; }
               if(PlayerProfile.Minigame4_4)  { %setActive3 = true; %num3 = 4;  }
               if(PlayerProfile.Minigame3_4)  { %setActive4 = true; %num4 = 3;  }
            case 4:
               if(PlayerProfile.Minigame7_4)  { %setActive1 = true; %num1 = 7;  }
               if(PlayerProfile.Minigame14_4) { %setActive2 = true; %num2 = 14; }
               if(PlayerProfile.Minigame10_4) { %setActive3 = true; %num3 = 10; }
               if(PlayerProfile.Minigame8_4)  { %setActive4 = true; %num4 = 8;  }    
         }
   }
   
   PM1.setActive(%setActive1);
   PM2.setActive(%setActive2);
   PM3.setActive(%setActive3);
   PM4.setActive(%setActive4);
   
   %highScoreVector = PlayerProfile.getFieldValue("MinigameStars"@$CurPlayerNum);
   
   %highScore = getWord(%highScoreVector, %num1-1);
   if(%highScore > 0)
   {
      Star1.setBitmap("scriptsAndAssets/data/ui/minigame/star" @ %highScore);
      Star1.setVisible(%setActive1);      
   }
   else
      Star1.setVisible(false);
      
   %highScore = getWord(%highScoreVector, %num2-1);
   if(%highScore > 0)   
   {
      Star2.setBitmap("scriptsAndAssets/data/ui/minigame/star" @ %highScore);
      Star2.setVisible(%setActive2);      
   }
   else
      Star2.setVisible(false);   

   %highScore = getWord(%highScoreVector, %num3-1);
   if(%highScore > 0)   
   {
      Star3.setBitmap("scriptsAndAssets/data/ui/minigame/star" @ %highScore);
      Star3.setVisible(%setActive3);
   }
   else
      Star3.setVisible(false);   

   %highScore = getWord(%highScoreVector, %num4-1);
   if(%highScore > 0)
   {
      Star4.setBitmap("scriptsAndAssets/data/ui/minigame/star" @ %highScore);
      Star4.setVisible(%setActive4);      
   }
   else
      Star4.setVisible(false);   
}

function PlayMinigameDlg::onResize(%this, %width, %height)
{
   Canvas.setWidescreen(PlayMinigameDlgCenter, 2000, true);
}
/*
// Parse XML file looking for menu text tags
function parsePlayMinigameMenuXML(%pXml)
{
   if(!isObject(%pXml))
      return;
      
   // Push the first child element named "playminigame" onto the XML document stack.
   if(!%pXml.pushFirstChildElement("playminigame"))
   {
      echo("Failed to load 'playminigame' tag.");
      return;
   }
   
   if(%pXml.pushFirstChildElement("minigame1"))
   {
      PlayMinigame1ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame2"))
   {
      PlayMinigame2ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame3"))
   {
      PlayMinigame3ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame4"))
   {
      PlayMinigame4ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame5"))
   {
      PlayMinigame5ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   
   if(%pXml.pushFirstChildElement("minigame6"))
   {
      PlayMinigame6ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   
   if(%pXml.pushFirstChildElement("minigame7"))
   {
      PlayMinigame7ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame8"))
   {
      PlayMinigame8ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame9"))
   {
      PlayMinigame9ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame10"))
   {
      PlayMinigame10ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   
   if(%pXml.pushFirstChildElement("minigame11"))
   {
      PlayMinigame11ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame12"))
   {
      PlayMinigame12ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("minigame13"))
   {
      PlayMinigame13ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   if(%pXml.pushFirstChildElement("minigame14"))
   {
      PlayMinigame14ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   if(%pXml.pushFirstChildElement("minigame15"))
   {
      PlayMinigame15ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
   if(%pXml.pushFirstChildElement("minigame16"))
   {
      PlayMinigame16ButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("back"))
   {
      MainMenuPlayButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
}
*/
function playMinigameDlg::playMinigame(%this, %minigame)
{
   %winScaleX = 1.0 / 800 * getWord(PlayMinigameDlgCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(PlayMinigameDlgCenter.getExtent(),1);
   
   %this.minigameToRun = %minigame;
   
   sfxStopAll();
//   MainMenuGui.playButtonPressSound();

   new GuiControl(Minigame) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "1";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
   };
   
   new GuiControl(MinigameCircles) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "1";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "1 1";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";   
   };   
   
   new GuiControl(MinigameParticleFx) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "1";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "1 1";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";   
   };
   
   new GuiPlasticBitmapCtrl(WinText) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      Profile = "GuiLCAPassThruProfile";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "2 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "0";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      useVariable = "0";
      tile = "0";      
      rotation = "0";
      deltaRotation = "0";
      noClip = "0";
      DML = "scriptsAndAssets/data/ui/minigame/wineffect/win_text.png";
   };
   
   exec("scriptsAndAssets/client/scripts/minigame/util.cs");
   exec("scriptsAndAssets/client/scripts/minigame/MiniGameParticleFx.cs");   
   
   new GuiPlasticBitmapCtrl(HintNumber) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      Profile = "GuiLCAPassThruProfile";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "800 600";
      MinExtent = "2 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "0";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      useVariable = "0";
      tile = "0";      
      rotation = "0";
      deltaRotation = "0";
      noClip = "0";
      DML = "scriptsAndAssets/data/ui/minigame/wineffect/hint_number/0.png";
   };
   
   MinigameCircles.setExtent(800*%winScaleX,600*%winScaleY);
   MinigameParticleFx.setExtent(800*%winScaleX,600*%winScaleY);
   
   WinText.setPosition(0*%winScaleX,0*%winScaleY);
   WinText.setExtent(800*%winScaleX,600*%winScaleY);
      
   HintNumber.setPosition(0*%winScaleX,0*%winScaleY);
   HintNumber.setExtent(800*%winScaleX,600*%winScaleY);

   PlayMinigameDlgCenter.add(MinigameCircles);
   PlayMinigameDlgCenter.add(MinigameParticleFx);
   PlayMinigameDlgCenter.add(WinText);
   PlayMinigameDlgCenter.add(HintNumber);
   
   %this.isPlayingMinigame = false;
   switch$(%minigame)
   {
      case 1:
            // From swatter with love
            $CurTake = 1;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "SpyLevel";
            exec("scriptsAndAssets/client/ui/InsectMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/InsectMinigame.cs");
            %this.curMinigame = InsectMinigame;
      case 2:
            // Unlock the vault
            $CurTake = 2;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "SpyLevel";
            exec("scriptsAndAssets/client/ui/SliderMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/SliderMinigame.cs");
            %this.curMinigame = SliderMinigame;
      case 3:
            // You have the right to remain clothed
            $CurTake = 2;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "GangsterLevel";
            exec("scriptsAndAssets/client/ui/BejeweledMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/BejeweledMinigame.cs");
            %this.curMinigame = BejeweledMinigame;
      case 4:
            // Blackout
            $CurTake = 3;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "GangsterLevel";
            exec("scriptsAndAssets/client/ui/MazeMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/MazeMinigame.cs");
            %this.curMinigame = MazeMinigame;
      case 5:
            // Master of scrambled picture
            $CurTake = 1;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "KungFuLevel";
            exec("scriptsAndAssets/client/ui/PicResortMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/PicResortMinigame.cs");
            %this.curMinigame = PicResortMinigame;
      case 6:
            // To the hotel
            $CurTake = 3;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "KungFuLevel";
            exec("scriptsAndAssets/client/ui/MazeMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/MazeMinigame.cs");
            %this.curMinigame = MazeMinigame;
      case 7:
            // Tyrannosaurus wrecked
            $CurTake = 2;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "DinosaurLevel";
            exec("scriptsAndAssets/client/ui/PipeMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/PipeMinigame.cs");
            %this.curMinigame = PipeMinigame;
      case 8:
            // Getting the gang back together
            $CurTake = 4;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "SciFiLevel";
            exec("scriptsAndAssets/client/ui/PicResortMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/PicResortMinigame.cs");
            %this.curMinigame = PicResortMinigame;
      case 9:
            // Unbaggin the Wagon
            $CurTake = 4;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "WesternLevel";
            exec("scriptsAndAssets/client/ui/SliderMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/SliderMinigame.cs");
            %this.curMinigame = SliderMinigame;
      case 10:
            // Close encounters of the costumed kind
            $CurTake = 1;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "SciFiLevel";
            exec("scriptsAndAssets/client/ui/BejeweledMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/BejeweledMinigame.cs");
            %this.curMinigame = BejeweledMinigame;
      case 11:
            // Tune the piano
            $CurTake = 1;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "MusicalLevel";
            exec("scriptsAndAssets/client/ui/SimonMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/SimonMinigame.cs");
            %this.curMinigame = SimonMinigame;   
      case 12:
            // Tone deaf talent
            $CurTake = 4;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "MusicalLevel";
            exec("scriptsAndAssets/client/ui/SimonMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/SimonMinigame.cs");
            %this.curMinigame = SimonMinigame;   
      case 13:
            // Howdown Showdown
            $CurTake = 2;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "WesternLevel";
            exec("scriptsAndAssets/client/ui/SimonMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/SimonMinigame.cs");
            %this.curMinigame = SimonMinigame;   
      case 14:
            // Rainforest rundown
            $CurTake = 3;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "DinosaurLevel";
            exec("scriptsAndAssets/client/ui/MazeMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/MazeMinigame.cs");
            %this.curMinigame = MazeMinigame;
      case 15:
            // Foggy first aid
            $CurTake = 4;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "MonsterLevel";
            exec("scriptsAndAssets/client/ui/MazeMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/MazeMinigame.cs");
            %this.curMinigame = MazeMinigame;
      case 16:
            // Punch paparazzi
            $CurTake = 1;
            %this.isPlayingMinigame = true;
            %this.currentLevel = "MonsterLevel";
            exec("scriptsAndAssets/client/ui/PunchMinigame.gui");
            exec("scriptsAndAssets/client/scripts/minigame/PunchMinigame.cs");
            %this.curMinigame = PunchMinigame;
      default:
         MinigameCircles.delete();
         MinigameParticleFx.delete();
         WinText.delete();
         HintNumber.delete();
         Minigame.delete();
         return;
   }
   
   $CurSceneName = %this.currentLevel;//%this.curMinigame;
   
   if(isObject(%this.curMinigame))
   {
      sfxPlay(AudioClapperBoardMoving);
      
      %path = "scriptsAndAssets/data/ui/clapperboard/clapper.jpg";
      PMClapper.setDML(%path);       
      PMClapper.play(1);
      PMClapper.setVisible(true);
      
      %path = "scriptsAndAssets/data/ui/clapperboard/minigame/" @ %this.currentLevel @ "_take" @ $CurTake @ ".jpg";
      PMBoard.setDML(%path);           
      PMBoard.play(1);
      PMBoard.setVisible(true);
   }
}

function PMClapper::onStoppedAtEnd(%this)
{
   sfxPlay(AudioClapperBoardClose);
   PMClapperStart.setVisible(true);
   PlayerMinigameGui.SetVisible(false);
}

function PMClapper::onStoppedAtStart(%this)
{
   PMClapper.setVisible(false);
   PMBoard.setVisible(false);
   
   PlayMinigameDlgCenter.setVisible(false);
   PlayMinigameDlg.curMinigame.start();
}

function playMinigameDlg::onClapperStart(%this)
{
   sfxPlay(AudioButtonPress); //Button Press Sound   
   PMClapperStart.setVisible(false);
   
   %this.curMinigame.setVisible(false);
   PlayMinigameDlg.add(%this.curMinigame);
   PlayMinigameDlg.bringToFront(%this.curMinigame);
   
   PlayMinigameDlgCenter.pushToBack(MinigameCircles);
   PlayMinigameDlgCenter.pushToBack(MinigameParticleFx);
   PlayMinigameDlgCenter.pushToBack(WinText);
   PlayMinigameDlgCenter.pushToBack(HintNumber);
   PlayMinigameDlgCenter.pushToBack(PMClapper);
   PlayMinigameDlgCenter.pushToBack(PMBoard);
   PlayMinigameDlgCenter.pushToBack(PMClapperStart);   
   
   %this.curMinigame.setVisible(true);      
   
   scheduleObjLCA(%this, "HO", 250, "execMinigame", 0);
}

function playMinigameDlg::execMinigame(%this)
{   
   sfxPlay(AudioClapperBoardMoving);
   PMClapper.playRev(1); 
   PMBoard.playRev(1);
}

function playMinigameDlg::quitMinigame(%this)
{
   lockMouse(false);
   Canvas.showCursor();   
   
   if(isObject(PlayMinigameDlgCenter))
      PlayMinigameDlgCenter.setVisible(true);
   if(isObject(PlayerMinigameGui))
      PlayerMinigameGui.setVisible(true);
   
   if(isObject(Minigame) && !%this.isPlayingMinigame)
      MiniGame.playClapperBoardScoreIn();
   else
   if(isObject(%this.curMinigame))
   {
      %this.isPlayingMinigame = false;
      PlayMinigameDlgCenter.remove(WinText);
      PlayMinigameDlgCenter.remove(HintNumber);
      WinText.delete();
      HintNumber.delete();
        
      PlayMinigameDlg.remove(%this.curMinigame);
      %this.curMinigame.delete();
   }
   // Play menu music
   sfxPlay(MusicMainMenu);  
   
   %this.update();
}
