
Intro = {}

function Intro:playUrnCrashAnim()

  local objs = {     
    "animobj_intro_urn_a_piece_a",
    "animobj_intro_urn_a_piece_b",
    "animobj_intro_urn_a_piece_c",
    "animobj_intro_urn_a_piece_d",
    "animobj_intro_urn_a_piece_e",
    "animobj_intro_urn_a_piece_f",
    "animobj_intro_urn_a_piece_g",
    "animobj_intro_urn_a_piece_h",
    "animobj_intro_urn_a_piece_i",
    "animobj_intro_urn_a_piece_j",
    "animobj_intro_urn_b_piece_a",
    "animobj_intro_urn_b_piece_b",
    "animobj_intro_urn_b_piece_c",
    "animobj_intro_urn_b_piece_d",
    "animobj_intro_urn_b_piece_e",
    "animobj_intro_urn_b_piece_f",
    "animobj_intro_urn_b_piece_g",
    "animobj_intro_urn_b_piece_h",
    "animobj_intro_urn_b_piece_i",
    "animobj_intro_urn_b_piece_j",
    "animobj_intro_urn_g",
    "animobj_intro_urn_f",
    "animobj_intro_urn_e",
    "animobj_intro_urn_d",
    "animobj_intro_urn_c_piece_a",
    "animobj_intro_urn_c_piece_b",
    "animobj_intro_urn_c_piece_c",
    "animobj_intro_urn_c_piece_d",
    "animobj_intro_urn_c_piece_e",
  }

  animobj_intro_eye:playAnimation("bouncing_eye")
  animobj_intro_heart:playAnimation("flying_heart")
  animobj_intro_intestines_a:playAnimation("flying_intestines")
  animobj_intro_intestines_b:playAnimation("flying_intestines")

  for key,value in ipairs(objs) do
    local obj = GameEntityMgr:getInteractor(value)
    obj:playAnimation("urn_crash")
  end
end

function Intro:hideUrnParts()

  local objs = {     
    "animobj_intro_urn_a_piece_a",
    "animobj_intro_urn_a_piece_b",
    "animobj_intro_urn_a_piece_c",
    "animobj_intro_urn_a_piece_d",
    "animobj_intro_urn_a_piece_e",
    "animobj_intro_urn_a_piece_f",
    "animobj_intro_urn_a_piece_g",
    "animobj_intro_urn_a_piece_h",
    "animobj_intro_urn_a_piece_i",
    "animobj_intro_urn_a_piece_j",
    "animobj_intro_urn_b_piece_a",
    "animobj_intro_urn_b_piece_b",
    "animobj_intro_urn_b_piece_c",
    "animobj_intro_urn_b_piece_d",
    "animobj_intro_urn_b_piece_e",
    "animobj_intro_urn_b_piece_f",
    "animobj_intro_urn_b_piece_g",
    "animobj_intro_urn_b_piece_h",
    "animobj_intro_urn_b_piece_i",
    "animobj_intro_urn_b_piece_j",
    "animobj_intro_urn_g",
    "animobj_intro_urn_f",
    "animobj_intro_urn_e",
    "animobj_intro_urn_d",
    "animobj_intro_urn_c_piece_a",
    "animobj_intro_urn_c_piece_b",
    "animobj_intro_urn_c_piece_c",
    "animobj_intro_urn_c_piece_d",
    "animobj_intro_urn_c_piece_e",
  }

  for key,value in ipairs(objs) do
    local obj = GameEntityMgr:getInteractor(value)
    obj:setVisible(false)
    obj:setIgnored(true)
  end
end


function Intro:showUrnParts()

  local objs = {     
    "animobj_intro_urn_a_piece_a",
    "animobj_intro_urn_a_piece_b",
    "animobj_intro_urn_a_piece_c",
    "animobj_intro_urn_a_piece_d",
    "animobj_intro_urn_a_piece_e",
    "animobj_intro_urn_a_piece_f",
    "animobj_intro_urn_a_piece_g",
    "animobj_intro_urn_a_piece_h",
    "animobj_intro_urn_a_piece_i",
    "animobj_intro_urn_a_piece_j",
    "animobj_intro_urn_b_piece_a",
    "animobj_intro_urn_b_piece_b",
    "animobj_intro_urn_b_piece_c",
    "animobj_intro_urn_b_piece_d",
    "animobj_intro_urn_b_piece_e",
    "animobj_intro_urn_b_piece_f",
    "animobj_intro_urn_b_piece_g",
    "animobj_intro_urn_b_piece_h",
    "animobj_intro_urn_b_piece_i",
    "animobj_intro_urn_b_piece_j",
    "animobj_intro_urn_g",
    "animobj_intro_urn_f",
    "animobj_intro_urn_e",
    "animobj_intro_urn_d",
    "animobj_intro_urn_c_piece_a",
    "animobj_intro_urn_c_piece_b",
    "animobj_intro_urn_c_piece_c",
    "animobj_intro_urn_c_piece_d",
    "animobj_intro_urn_c_piece_e",
  }

  for key,value in ipairs(objs) do
    local obj = GameEntityMgr:getInteractor(value)
    obj:setVisible(true)
    obj:setIgnored(false)
  end
end



function Intro:activate()
   char_girlie:setConfiguration("cfg_intro_char_girlie")
   CameraMgr:activateCamera("cam_intro_desert")
   api:cutscene("Intro");
   api:subscribeCutsceneFinished("Intro","Intro:onCutsceneFinished")
end

function Intro:onCutsceneFinished()

   --local extro = GUIWindowMgr:createOverlay2D("ankh_intro_img1")
   --local extro = GUIWindowMgr:getOverlay2D("ankh_chapter_overlay")
   
   --local overlay = GUIWindowMgr:create
   --local extro = GUIWindowMgr:getGUIWindow("Ankh/Chapter1")
   --local extro = GUIWindowMgr:getGUIWindow("Ankh/DemoEnd")
   --extro:setVisible(true)
   --extro:setAlpha(0.0)
   --GameStateMgr:fadeOut(1.0)
   --extro:animateAlpha(0.0,1.0,1.0)
   --Ankh:hideMouseCursor()
   --api:callDelayed("Demo:setAlphaFull",1.1)
   --Ankh:mdisconnect()
   QuestHelper:setCurrentChapter(0)
   TimedEventMgr:createTimedEvent("QuestHelper:showChapterText(\"\",\"\")",2)
   TimedEventMgr:createTimedEvent("Intro:startEscapeFromHome",4.0)
   -- TL last minute fix
   MouseIface:setInputBlocked(true)
   MouseIface:hideCursor()
end

function Intro:startEscapeFromHome()
   LocationMgr:activateLocation("home")
   EscapeFromHome:activate()
end

function Intro:fadeOutChapter1()
   --local extro = GUIWindowMgr:getGUIWindow("ankh_chapter_overlay")
   --local extro = GUIWindowMgr:getGUIWindow("Ankh/Chapter1")
   --local extro = GUIWindowMgr:getGUIWindow("Ankh/DemoEnd")
   --extro:setVisible(true)
   --extro:setAlpha(1.0)
   --extro:animateAlpha(1.0,0.0,2.0)
   --TimedEventMgr:createTimedEvent("GUIWindowMgr:getGUIWindow(\"ankh_chapter_overlay\"):setVisible(false)",2.0)
end

--items = {}
--items["item_flute"] = "thara"
--print items["item_flute"] --> "thara"

--for key,value in ipairs items do
--   key == "item_flute"
--   value == "thara"
--end

