
var cur_pos = 0;
var menu_num = 7;

var icon_pics_fcs =
[
  "/usr/local/png/vt_f_vlink.png",
  "/usr/local/png/vt_f_pl_TV.png",
  "/usr/local/png/vt_f_slideshow.png",
  "/usr/local/png/vt_f_photos.png",
  "/usr/local/png/vt_f_movies.png",
  "/usr/local/png/vt_f_vcast.png",
  "/usr/local/png/vt_f_m_server.png",
]
var icon_pics_nml =
[
  "/usr/local/png/vt_a_vlink.png",
  "/usr/local/png/vt_a_pl_TV.png",
  "/usr/local/png/vt_a_slideshow.png",
  "/usr/local/png/vt_a_photos.png",
  "/usr/local/png/vt_a_movies.png",
  "/usr/local/png/vt_a_vcast.png",
  "/usr/local/png/vt_a_m_server.png",
]

var icon_rgs = 
[
  "/usr/local/anim/menu_obj0.rgs",
  "/usr/local/anim/menu_obj1.rgs",
  "/usr/local/anim/menu_obj2.rgs",
  "/usr/local/anim/menu_obj3.rgs",
  "/usr/local/anim/menu_obj4.rgs",
  "/usr/local/anim/menu_obj5.rgs",
  "/usr/local/anim/menu_obj6.rgs",
];

var menu_str = 
[
  "VIERA Link Control",
  "Pause Live TV",
  "Slideshow",
  "Photos",
  "Movies",
  "VIERA CAST",
  "Media Server",
]

var zoom_in  = [374, 344, 314, 284, 254, 224, 194];
var zoom_out = [194, 374, 344, 314, 284, 254, 224];
var name_x = [-755, -507, -260, 0, 265, 510, 755];
var left_limit = -945;
var right_limit = 945;

var scenario3 = new gscenario ();
scenario3.init ();

var goto_appli = function (key, pos) {
  scenario1.finish ();
  focus_first_item = function (){};
  anim_cursor_move = function (){};
  s.key_hook = [];

  disappear_menutext ();
  scenario3.finish ();
  scenario3.set_anim_translate (floor, [0, -1200, -400], [0, -1500, -400], 0, 5);
  for (var i=0; i<menu_num; i++) {
    if (i != pos)
      scenario3.set_anim_translate (rgs_icon_obj[i], [0, 0, 0], [0, -400, 0], 0, 5);
  }
  scenario3.set_anim_translate (rgs_icon_obj[pos], [0, 0, 0], [0, -400, 0], 5, 10);
  scenario3.set_anim_translate (cursor, [0, 0, 0], [0, -400, 0], 5, 10);
  scenario3.set_anim_frame (frame, 487, 506, 5, 21);
  scenario3.run (function () {
    launch_apl (key, pos);
  })
};

var launch_apl = function (key, pos) {
    if (pos == 0) {
	write_back_bytes ([0, 0, 0]);
    } else if (pos == 1) {
	write_back_bytes ([0, 1, 0]);
    } else if (pos == 2) {
	write_back_bytes ([0, 2, 18]);
    } else if (pos == 3) {
	write_back_bytes ([0, 2, 16]);
    } else if (pos == 4) {
	write_back_bytes ([0, 2, 17]);
    } else if (pos == 5) {
	write_back_bytes ([0, 3, 6]);
    } else if (pos == 6) {
	write_back_bytes ([0, 4, 7]);
    }
};

var end_vtools = function (no) {
  scenario1.finish ();
  focus_first_item = function (){};
  anim_cursor_move = function (){};
  s.key_hook = [];

  disappear_menutext ();
  scenario3.finish ();
  scenario3.set_anim_translate (floor, [0, -1200, -400], [0, -1500, -400], 0, 5);
  for (var i=0; i<menu_num; i++) {
    if (i != cur_pos)
      scenario3.set_anim_translate (rgs_icon_obj[i], [0, 0, 0], [0, -400, 0], 0, 5);
  }
  scenario3.set_anim_translate (rgs_icon_obj[cur_pos], [0, 0, 0], [0, -400, 0], 5, 10);
  scenario3.set_anim_translate (cursor, [0, 0, 0], [0, -400, 0], 5, 10);
  scenario3.set_anim_frame (frame, 487, 506, 5, 21);
  scenario3.run (function () {
    if (cur_pos == [0]) {
      write_back_bytes ([2, 0, no]);
    } else if (cur_pos == [1]) {
      write_back_bytes ([2, 1]);
    }
  })
};

var exit_vtool = function (key) {
   write_back_bytes ([2, 10, key]);
};

var test_func = function () {
  console.log (cur_pos);
};
