#include <lib/std.mi>

Global Group thisGroup;
Global Layer seekLayer, volLayer;
Global Map m_map;
Global Timer m_timer;
Global Button BButton;

System.onScriptLoaded() {
  thisGroup = getScriptGroup();
  volLayer = thisGroup.getObject("Layer 20");
  seekLayer = thisGroup.getObject("Layer 21");

  m_map = new map;
  m_map.loadmap("player.seekmap");

  m_timer = new timer;
  m_timer.setDelay(200);
  m_timer.start();

  BButton = thisGroup.getObject("BAT BUTTON");

  System.onVolumeChanged(getVolume());
}

System.onSeek(int newpos) {
  if (newpos <= 0) return;
  int len = getPlayItemLength();
  if(len <= 0) return;
  int devby = len/255;
  if(devby <= 0) return;
  seekLayer.setRegionFromMap(m_map,newpos/devby,1);
}

m_timer.onTimer() {
  System.onSeek(getPosition());
}

System.onVolumeChanged(int newvol) {
  volLayer.setRegionFromMap(m_map,newvol,1);
}

BButton.onLeftButtonUp(int x, int y) {
  navigateurl("http://kidswb.warnerbros.com/web/stuff/stuff_display.jsp?id=BTM");
}