// Set up triggering of camera borders
function SceneGui::initCameraLightBehavior(%this)
{
   // Reset camera lights and borders
   CamLight1.Visible = false;
   CamLight2.Visible = false;
   CamLight3.Visible = false;
   CamLight4.Visible = false;
   
   switch$(MissionInfo.firstCamera)
   {
      case "Camera1": %this.curCam = 1; CamLight1.Visible = true;
      case "Camera2": %this.curCam = 2; CamLight2.Visible = true;
      case "Camera3": %this.curCam = 3; CamLight3.Visible = true;
      case "Camera4": %this.curCam = 4; CamLight4.Visible = true;
      default: %this.curCam = 1; CamLight1.Visible = true;
   }
   
   %this.camBorderCur = -1;
  
   BorderCam1.Visible = false;
   BorderCam2.Visible = false;
   BorderCam3.Visible = false;
   BorderCam4.Visible = false;
   
//   loadCameraLightXML();
   
   %this.borderPulseTime = 500;
}

// Parse XML file looking for camera border behavior tags
function SceneGui::loadCameraLightXML(%this)
{
   %path = "./scriptsAndAssets/data/ui/camera" @ $CurSceneName @ "_take" @ $CurTake @ ".xml";   
   
   %pXml = new SimXMLDocument();
   // Load and parse XML file.
   if(!%pXml.loadFile(%path))
   {
      echo("Failed to load " @ %path);
      return;
   }
   
   // Push the first child element named "director" onto 
   // the XML document stack.
   if(!%pXml.pushFirstChildElement("camera"))
   {
      echo("Failed to load camera tag.");
      return;
   }

   if(!%pXml.pushFirstChildElement("trigger"))
      return;

   while(true)
   {
      // Read camera border triggering attributes      
      %camNumber = %pXml.attributeS32("number");
      %camTime = %pXml.attributeF32("at");
      
      scheduleObjLCA(%this, "HO", %camTime*1000, "triggerCamBorder", 1, %camNumber);
      
      // Go to next animation tag
      if(!%pXml.nextSiblingElement("trigger"))
         break;
   }
   
   %pXml.popElement();
   
   %pXml.delete();   
}

function SceneGui::triggerCamBorder(%this, %camNumber)
{
   BorderCam1.Visible = false;
   BorderCam2.Visible = false;
   BorderCam3.Visible = false;
   BorderCam4.Visible = false;
      
   if(isEventPending(%this.triggerCamEventID))
   {
      cancelScheduleLCA(%this.triggerCamEventID);
      %obj = ("BorderCam"@%this.camBorderCur);
      %obj.setAlpha(0);
      %obj.Visible = false;
   }
   
   if(%camNumber < 1 || %camNumber > 4)
   {
      %this.camBorderCur = -1;
      return;
   }   
   
//   if(("CamLight"@%camNumber).Visible $= false)
//   {
      %this.camBorderCur = %camNumber;
      
      %obj = ("BorderCam"@%camNumber);
      %obj.setAlpha(0);
      %obj.Visible = true;
      %obj.animateAlpha(1, 0, %this.borderPulseTime, "0 0");
      
      %this.triggerCamEventID = scheduleObjLCA(%this, "HO", %this.borderPulseTime, "onBorderPulse", 0);
//   }
//   else
//      %this.camBorderCur = -1;
}

function SceneGui::onBorderPulse(%this)
{
   %obj = ("BorderCam"@%this.camBorderCur);
   
   if(%obj.alpha > 0.5)
      %obj.animateAlpha(0, 0, %this.borderPulseTime, "0 0");
   else
      %obj.animateAlpha(1, 0, %this.borderPulseTime, "0 0");
   
   %this.triggerCamEventID = scheduleObjLCA(%this, "HO", %this.borderPulseTime, "onBorderPulse", 0);
}
/*
function BorderCam1::onAnimationStopped(%this)
{
   if(SceneGui.camBorderCur $= 1)
   {
      if(Minigame.isRunning)
         BorderCam1.setVisible(false);
      else
         BorderCam1.setVisible(true);
         
      if(BorderCam1.alpha $= 1)
         BorderCam1.animateAlpha(0, 0, SceneGui.borderPulseTime, "0 0");
      else
         BorderCam1.animateAlpha(1, 0, SceneGui.borderPulseTime, "0 0");
  }
  else
  {
     BorderCam1.setAlpha(0);
     BorderCam1.setVisible(false);
  }
}

function BorderCam2::onAnimationStopped(%this)
{
   if(SceneGui.camBorderCur $= 2)
   {
      if(Minigame.isRunning)
         BorderCam2.setVisible(false);
      else
         BorderCam2.setVisible(true);
      
      if(BorderCam2.alpha $= 1)
         BorderCam2.animateAlpha(0, 0, SceneGui.borderPulseTime, "0 0");
      else
         BorderCam2.animateAlpha(1, 0, SceneGui.borderPulseTime, "0 0");
  }
  else
  {
     BorderCam2.setAlpha(0);
     BorderCam2.setVisible(false);
  }
}

function BorderCam3::onAnimationStopped(%this)
{
   if(SceneGui.camBorderCur $= 3)
   {
      if(Minigame.isRunning)
         BorderCam3.setVisible(false);
      else
         BorderCam3.setVisible(true);
      
      if(BorderCam3.alpha $= 1)
         BorderCam3.animateAlpha(0, 0, SceneGui.borderPulseTime, "0 0");
      else
         BorderCam3.animateAlpha(1, 0, SceneGui.borderPulseTime, "0 0");
  }
  else
  {
     BorderCam3.setAlpha(0);
     BorderCam3.setVisible(false);
  }
}

function BorderCam4::onAnimationStopped(%this)
{
   if(SceneGui.camBorderCur $= 4)
   {
      if(Minigame.isRunning)
         BorderCam4.setVisible(false);
      else
         BorderCam4.setVisible(true);
      
      if(BorderCam4.alpha $= 1)
         BorderCam4.animateAlpha(0, 0, SceneGui.borderPulseTime, "0 0");
      else
         BorderCam4.animateAlpha(1, 0, SceneGui.borderPulseTime, "0 0");
  }
  else
  {
     BorderCam4.setAlpha(0);
     BorderCam4.setVisible(false);
  }
}*/