Advertisement
Guest User

Modified LastFm_bio, from Marc2003 (Wsh panel mod 1.4.2.)

a guest
Aug 6th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 139.29 KB | None | 0 0
  1.  
  2. var VERSION = "7.2013-08-01.01";
  3.  
  4. var DT_LEFT = 0x00000000;
  5. var DT_CENTER = 0x00000001;
  6. var DT_RIGHT = 0x00000002;
  7. var DT_VCENTER = 0x00000004;
  8. var DT_WORDBREAK = 0x00000010;
  9. var DT_CALCRECT = 0x00000400;
  10. var DT_NOPREFIX = 0x00000800;
  11. var DT_END_ELLIPSIS = 0x00008000;
  12.  
  13. var MF_GRAYED = 0x00000001;
  14. var MF_STRING = 0x00000000;
  15.  
  16. var IDC_ARROW = 32512;
  17. var IDC_HAND = 32649;
  18.  
  19. var ONE_DAY = 86400000;
  20. var ONE_WEEK = 604800000;
  21.  
  22. String.prototype.addCommas = function() {
  23.     var v = this;
  24.     var n = "";
  25.     while(v.length > 3) {
  26.         n = "," + v.substring(v.length - 3) + n;
  27.         v = v.substring(0, v.length - 3);
  28.     }
  29.     return(v + n);
  30. }
  31.  
  32. String.prototype.trim = function() {
  33.     return this.replace(/^\s+|\s+$/g,"");
  34. }
  35.  
  36. String.prototype.ucfirst = function() {
  37.     return this.charAt(0).toUpperCase() + this.substr(1);
  38. }
  39.  
  40. function RGB(r, g, b) {
  41.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  42. }
  43.  
  44. function RGBA(r, g, b, a) {
  45.     return ((a << 24) | (r << 16) | (g << 8) | (b));
  46. }
  47.  
  48. function on_colors_changed() {
  49.     p.colors_changed();
  50. }
  51.  
  52. function on_font_changed() {
  53.     p.font_changed();
  54. }
  55.  
  56. function on_selection_changed() {
  57.     p.item_focus_change();
  58. }
  59.  
  60. function on_playlist_switch() {
  61.     p.item_focus_change();
  62. }
  63.  
  64. function on_playback_new_track() {
  65.     p.item_focus_change();
  66. }
  67.  
  68. function on_playback_dynamic_info_track() {
  69.     p.item_focus_change();
  70. }
  71.  
  72. function on_playback_stop() {
  73.     p.item_focus_change();
  74. }
  75.  
  76. function on_item_focus_change() {
  77.     p.item_focus_change();
  78. }
  79.  
  80. function on_mouse_leave() {
  81.     if (typeof b == "object") b.leave();
  82.     if (typeof r == "object") r.leave();
  83.     if (typeof li == "object") li.leave();
  84.     if (typeof s == "object") s.leave();
  85. }
  86.  
  87. function on_mouse_rbtn_up(x, y) {
  88.     p.rbtn_up(x, y);
  89.     return true;
  90. }
  91.  
  92. function on_notify_data(name, data) {
  93.     if (name == "lastfm" && data == "update" && typeof l == "object") l.notify_data(name, data);
  94.     if (name == "autoplaylists" && data == "update" && typeof li == "object" && li.mode == "autoplaylists") li.update();
  95.     if (name == "images" && data == "update" && typeof im == "object") im.update();
  96.     if (name == "love" && typeof ps == "object") l.post(fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(data) == 1 ? "track.unlove" : "track.love", data);
  97. }
  98.  
  99. function panel(name, features) {
  100.     this.item_focus_change = function() {
  101.         switch(this.selection_mode) {
  102.             case 0:
  103.                 this.metadb = fb.GetSelection();
  104.                 break;
  105.             case 1:
  106.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  107.                 break;
  108.             case 2:
  109.                 this.metadb = fb.GetFocusItem();
  110.                 break;
  111.         }
  112.         if (this.metadb && typeof on_metadb_changed == "function") on_metadb_changed();
  113.     }
  114.    
  115.     this.colors_changed = function() {
  116.         if (this.dui) {
  117.             this.textcolour = window.GetColorDUI(0);
  118.             this.textcolour_hl = window.GetColorDUI(2);
  119.             this.backcolour = window.GetColorDUI(1);
  120.         } else {
  121.             this.textcolour = window.GetColorCUI(0);
  122.             this.textcolour_hl = window.GetColorCUI(0);
  123.             //this.backcolour = window.GetColorCUI(3);
  124.         }
  125.         window.Repaint();
  126.     }
  127.    
  128.     this.font_changed = function() {
  129.         this.font = this.dui ? window.GetFontDUI(0) : window.GetFontCUI(0);
  130.         try {
  131.             this.font_name = this.font.Name;
  132.         } catch(e) {
  133.             this.console("Unable to use your default font. Using Segoe UI instead.");
  134.             this.font_name = "segoe ui";
  135.         }
  136.         //this.title_font = gdi.Font(this.font_name, 12, 3);
  137.         this.normal_font = gdi.Font("segoe ui", 12, 1);
  138.         //this.fixed_font = gdi.Font("segoe ui", 9, 3);
  139.         //this.list_font = gdi.Font(this.font_name, this.list_font_size);
  140.         this.row_height = this.normal_font.Height + 0;
  141.         if (typeof t == "object") t.size();
  142.         window.Repaint();
  143.     }
  144.    
  145.     this.size = function() {
  146.         this.w = window.Width;
  147.         this.h = window.Height;
  148.     }
  149.    
  150.     this.move = function(x, y) {
  151.         this.mx = x;
  152.         this.my = y;
  153.     }
  154.    
  155.     this.rbtn_up = function(x, y) {
  156.         var _menu = window.CreatePopupMenu();
  157.         var _custom_background = window.CreatePopupMenu();
  158.         var _metadb = window.CreatePopupMenu();
  159.         var _cover = window.CreatePopupMenu();
  160.         var _font = window.CreatePopupMenu();
  161.         var _sub1 = window.CreatePopupMenu();
  162.         var _sub2 = window.CreatePopupMenu();
  163.         var _sub3 = window.CreatePopupMenu();
  164.         var _sub4 = window.CreatePopupMenu();
  165.         var _sub5 = window.CreatePopupMenu();
  166.         var idx;
  167.         switch(true) {
  168.             case this.check_feature("spectrogram") && s.trace(x, y):
  169.                 _menu.AppendMenuItem(MF_STRING, 1804, "SoX options...");
  170.                 _menu.AppendMenuSeparator();
  171.                 _menu.AppendMenuItem(MF_STRING, 1805, "Marker colour...");
  172.                 _menu.AppendMenuSeparator();
  173.                 _menu.AppendMenuItem(MF_STRING, 1803, "Only analyse tracks in library");
  174.                 _menu.CheckMenuItem(1803, s.library);
  175.                 _menu.AppendMenuSeparator();
  176.                 _sub1.AppendMenuItem(MF_STRING, 1800, "Clear all");
  177.                 _sub1.AppendMenuItem(MF_STRING, 1801, "Clear older than 1 day");
  178.                 _sub1.AppendMenuItem(MF_STRING, 1802, "Clear older than 1 week");
  179.                 _sub1.AppendMenuSeparator();
  180.                 _sub1.AppendMenuItem(MF_GRAYED, 1803, "In use: " + (this.fso.GetFolder(spectrogram_cache).size / 1048576).toFixed(2) + "MB");
  181.                 _sub1.AppendTo(_menu, MF_STRING, "Cached images");
  182.                 _menu.AppendMenuSeparator();
  183.                 break;
  184.             case typeof a == "object" && a.trace(x, y):
  185.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  186.                 _menu.AppendMenuSeparator();
  187.                 _menu.AppendMenuItem(MF_STRING, 2, "Front");
  188.                 _menu.AppendMenuItem(MF_STRING, 3, "Back");
  189.                 _menu.AppendMenuItem(MF_STRING, 4, "Disc");
  190.                 _menu.AppendMenuItem(MF_STRING, 5, "Icon");
  191.                 _menu.AppendMenuItem(MF_STRING, 6, "Artist");
  192.                 _menu.CheckMenuRadioItem(2, 6, a.id + 2);
  193.                 _menu.AppendMenuSeparator();
  194.                 _menu.AppendMenuItem(MF_STRING, 15, "Crop (focus on centre)");
  195.                 _menu.AppendMenuItem(MF_STRING, 16, "Crop (focus on top)");
  196.                 _menu.AppendMenuItem(MF_STRING, 17, "Centre");
  197.                 _menu.AppendMenuItem(MF_STRING, 18, "Stretch");
  198.                 _menu.CheckMenuRadioItem(15, 18, a.type == "crop" ? 15 : a.type == "crop top" ? 16 : a.type == "centre" ? 17 : 18);
  199.                 _menu.AppendMenuSeparator();
  200.                 break;
  201.             case typeof c == "object" && (!this.check_feature("now_playing") || np_cd) && c.trace(x, y):
  202.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  203.                 _menu.AppendMenuSeparator();
  204.                 _menu.AppendMenuItem(MF_STRING, 11, "Gloss effect");
  205.                 _menu.CheckMenuItem(11, c.gloss);
  206.                 _menu.AppendMenuItem(MF_STRING, 12, "Shadow effect");
  207.                 _menu.CheckMenuItem(12, c.shadow);
  208.                 _menu.AppendMenuSeparator();
  209.                 break;
  210.             case this.check_feature("simple_tag") && t.trace(x, y):
  211.                 _menu.AppendMenuItem(MF_STRING, 1700, "Custom title...");
  212.                 _menu.AppendMenuItem(MF_STRING, 1701, "Custom tag...");
  213.                 _menu.AppendMenuSeparator();
  214.                 _menu.AppendMenuItem(MF_STRING, 1702, "Centre text");
  215.                 _menu.CheckMenuItem(1702, t.centre);
  216.                 _menu.AppendMenuSeparator();
  217.                 break;
  218.             case this.check_feature("simple_text") && t.trace(x, y):
  219.                 _menu.AppendMenuItem(MF_STRING, 1700, "Custom title...");
  220.                 _menu.AppendMenuItem(MF_STRING, 200, "Custom path...");
  221.                 _menu.AppendMenuSeparator();
  222.                 _menu.AppendMenuItem(MF_STRING, 201, "Fixed width font");
  223.                 _menu.CheckMenuItem(201, t.fixed);
  224.                 _menu.AppendMenuSeparator();
  225.                 break;
  226.             case this.check_feature("lastfm_album") && t.trace(x, y):
  227.                 _menu.AppendMenuItem(MF_STRING, 53, "Last.fm auto-correct");
  228.                 _menu.CheckMenuItem(53, l.auto_correct);
  229.                 break;
  230.             case this.check_feature("lastfm_wiki") && (!this.check_feature("now_playing") || np_bio) && t.trace(x, y):
  231.                 _menu.AppendMenuItem(MF_STRING, 25, "Last.fm");
  232.                 _menu.AppendMenuItem(MF_STRING, 26, "Wikipedia");
  233.                 _menu.CheckMenuRadioItem(25, 26, t.source == "last.fm" ? 25 : 26);
  234.                 //_menu.AppendMenuSeparator();
  235.                 break;
  236.             case this.check_feature("echonest") && li.trace(x, y):
  237.                 for (i = 0; i < li.echonest_modes.length; i++) {
  238.                     _menu.AppendMenuItem(MF_STRING, i + 500, li.echonest_modes[i].ucfirst());
  239.                 }
  240.                 _menu.CheckMenuRadioItem(500, 502, li.echonest_mode + 500);
  241.                 _menu.AppendMenuSeparator();
  242.                 _menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
  243.                 _menu.CheckMenuItem(28, li.show_timestamp);
  244.                 _menu.AppendMenuSeparator();
  245.                 break;
  246.             case this.check_feature("autoplaylists") && li.trace(x, y):
  247.                 _menu.AppendMenuItem(MF_STRING, 600, "Change title...");
  248.                 _menu.AppendMenuSeparator();
  249.                 for (i = 1; i < 9; i++) {
  250.                     _sub1.AppendMenuItem(MF_STRING, i + 600, i);
  251.                 }
  252.                 _sub1.AppendTo(_menu, MF_STRING, "Save slot");
  253.                 _sub1.CheckMenuRadioItem(601, 608, li.autoplaylists_slot + 600);
  254.                 _menu.AppendMenuSeparator();
  255.                 _sub2.AppendMenuItem(MF_STRING, 610, "run query");
  256.                 _sub2.AppendMenuItem(MF_STRING, 611, "do nothing");
  257.                 _sub2.CheckMenuRadioItem(610, 611, li.autoplaylists_success ? 610 : 611);
  258.                 _sub2.AppendTo(_menu, MF_STRING, "On successful creation/edit");
  259.                 for (i = 0; i < li.autoplaylists_deleted_items.length; i++) {
  260.                     var temp = li.autoplaylists_deleted_items[i].split("¬");
  261.                     _sub3.AppendMenuItem(MF_STRING, i + 620, temp[0]);
  262.                 }
  263.                 if (li.autoplaylists_deleted_items.length > 0) _sub3.AppendTo(_menu, MF_STRING, "Restore");
  264.                 _menu.AppendMenuSeparator();
  265.                 _menu.AppendMenuItem(MF_STRING, 650, "Replace exisiting playlists with the same name");
  266.                 _menu.CheckMenuItem(650, li.autoplaylists_remove_duplicates);
  267.                 _menu.AppendMenuSeparator();
  268.                 break;
  269.             case this.check_feature("discogs") && li.trace(x, y):
  270.                 _menu.AppendMenuItem(MF_STRING, 29, "Show exact artist matches only");
  271.                 _menu.CheckMenuItem(29, li.discogs_match);
  272.                 _menu.AppendMenuSeparator();
  273.                 _menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
  274.                 _menu.CheckMenuItem(28, li.show_timestamp);
  275.                 _menu.AppendMenuSeparator();
  276.                 break;
  277.             case this.check_feature("musicbrainz") && li.trace(x, y):
  278.                 _menu.AppendMenuItem(MF_STRING, 700, "Releases");
  279.                 _menu.AppendMenuItem(MF_STRING, 701, "Links");
  280.                 _menu.CheckMenuRadioItem(700, 701, li.musicbrainz_mode == "releases" ? 700 : 701);
  281.                 _menu.AppendMenuSeparator();
  282.                 if (li.musicbrainz_mode == "releases") {
  283.                     _menu.AppendMenuItem(MF_STRING, 703, "Include albums");
  284.                     _menu.CheckMenuItem(703, li.musicbrainz_album);
  285.                     _menu.AppendMenuItem(MF_STRING, 704, "Include EPs");
  286.                     _menu.CheckMenuItem(704, li.musicbrainz_ep);
  287.                     _menu.AppendMenuItem(MF_STRING, 705, "Include singles");
  288.                     _menu.CheckMenuItem(705, li.musicbrainz_single);
  289.                     _menu.AppendMenuSeparator();
  290.                     _menu.AppendMenuItem(MF_STRING, 702, "Include 'Live' releases");
  291.                     _menu.CheckMenuItem(702, li.musicbrainz_live);
  292.                     _menu.AppendMenuSeparator();
  293.                     _menu.AppendMenuItem(MF_STRING, 706, "Show release type");
  294.                     _menu.CheckMenuItem(706, li.musicbrainz_show_release_type);
  295.                     _menu.AppendMenuSeparator();
  296.                 }
  297.                 _menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
  298.                 _menu.CheckMenuItem(28, li.show_timestamp);
  299.                 _menu.AppendMenuSeparator();
  300.                 break;
  301.             case this.check_feature("lastfm") && li.trace(x, y):
  302.                 for (i = 0; i < li.lastfm_modes.length; i++) {
  303.                     _menu.AppendMenuItem(MF_STRING, 801 + i, li.lastfm_modes[i].ucfirst());
  304.                 }
  305.                 _menu.CheckMenuRadioItem(801, 805, li.lastfm_mode + 801);
  306.                 _menu.AppendMenuSeparator();
  307.                 if (li.lastfm_mode == 0) {
  308.                     if (li.lastfm_button == "spotify") {
  309.                         _menu.AppendMenuItem(MF_STRING, 810, "Pause playback when launching Spotify");
  310.                         _menu.CheckMenuItem(810, li.lastfm_pause);
  311.                         _menu.AppendMenuSeparator();
  312.                     }
  313.                     _sub1.AppendMenuItem(MF_STRING, 811, "Spotify");
  314.                     _sub1.AppendMenuItem(MF_STRING, 812, "Autoplaylist");
  315.                     _sub1.CheckMenuRadioItem(811, 812, li.lastfm_button == "spotify" ? 811 : 812);
  316.                     _sub1.AppendTo(_menu, MF_STRING, "Buttons");
  317.                     _menu.AppendMenuSeparator();
  318.                 }
  319.                 _menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
  320.                 _menu.CheckMenuItem(28, li.show_timestamp);
  321.                 _menu.AppendMenuSeparator();
  322.                 _menu.AppendMenuItem(MF_STRING, 51, "Last.fm auto-correct");
  323.                 _menu.CheckMenuItem(51, l.auto_correct);
  324.                 _menu.AppendMenuSeparator();
  325.                 break;
  326.             case this.check_feature("lastfm_charts") && li.trace(x, y):
  327.                 _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 1000, "Refresh");
  328.                 _menu.AppendMenuSeparator();
  329.                 for (i = 0; i < li.lastfm_charts_modes.length; i++) {
  330.                     _menu.AppendMenuItem(MF_STRING, i + 1001, li.lastfm_charts_modes[i].ucfirst());
  331.                 }
  332.                 _menu.CheckMenuRadioItem(1001, 1003, li.lastfm_charts_mode + 1001);
  333.                 _menu.AppendMenuSeparator();
  334.                 for (i = 0; i < li.lastfm_charts_periods_display.length; i++) {
  335.                     _menu.AppendMenuItem(MF_STRING, i + 1004, li.lastfm_charts_periods_display[i].ucfirst());
  336.                 }
  337.                 _menu.CheckMenuRadioItem(1004, 1009, li.lastfm_charts_period + 1004);
  338.                 _menu.AppendMenuSeparator();
  339.                 _menu.AppendMenuItem(MF_STRING, 1010, "Bar colour...");
  340.                 _menu.AppendMenuSeparator();
  341.                 _menu.AppendMenuItem(MF_STRING, 28, "Show timestamp");
  342.                 _menu.CheckMenuItem(28, li.show_timestamp);
  343.                 _menu.AppendMenuSeparator();
  344.                 break;
  345.             case typeof ps == "object" && b.buttons.ps.trace(x, y):
  346.                 _sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && !ps.loved_working && !ps.playcount_working && l.username.length > 0 ? 0x00000000 | MF_STRING : MF_GRAYED, 1100, "loved tracks and playcount");
  347.                 _sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && !ps.loved_working && !ps.playcount_working && l.username.length > 0 ? MF_STRING : MF_GRAYED, 1109, "loved tracks only");
  348.                 _sub1.AppendMenuSeparator();
  349.                 _sub1.AppendMenuItem(utils.CheckComponent("foo_customdb", true) && this.fso.FileExists(ps.sql_file) ? MF_STRING : MF_GRAYED, 1101, "from file");
  350.                 _sub1.AppendMenuSeparator();
  351.                 _sub1.AppendMenuItem(MF_STRING, 1102, "Show console");
  352.                 _sub1.CheckMenuItem(1102, ps.show_console);
  353.                 _sub1.AppendTo(_menu, MF_STRING, "Library import");
  354.                 _menu.AppendMenuSeparator();
  355.                 _sub2.AppendMenuItem(MF_STRING, 1103, "Only update tracks in library");
  356.                 _sub2.CheckMenuItem(1103, ps.library);
  357.                 _sub2.AppendMenuItem(MF_STRING, 52, "Last.fm auto-correct");
  358.                 _sub2.CheckMenuItem(52, l.auto_correct);
  359.                 _sub2.AppendTo(_menu, MF_STRING, "Auto-updates");
  360.                 _menu.AppendMenuSeparator();
  361.                 _sub3.AppendMenuItem(MF_STRING, 1104, "Off");
  362.                 _sub3.AppendMenuItem(MF_STRING, 1105, "On");
  363.                 _sub3.CheckMenuRadioItem(1104, 1105, ps.auto_love ? 1105 : 1104);
  364.                 _sub3.AppendMenuSeparator();
  365.                 _sub3.AppendMenuItem(ps.auto_love ? MF_STRING : MF_GRAYED, 1106, "Condition");
  366.                 _sub3.AppendTo(_menu, MF_STRING, "Automatically love tracks");
  367.                 _menu.AppendMenuSeparator();
  368.                 _sub4.AppendMenuItem(MF_STRING, 1107, "tango");
  369.                 _sub4.AppendMenuItem(MF_STRING, 1108, "silk");
  370.                 _sub4.CheckMenuRadioItem(1107, 1108, ps.icon == "tango" ? 1107 : 1108);
  371.                 _sub4.AppendTo(_menu, MF_STRING, "Icon");
  372.                 _menu.AppendMenuSeparator();
  373.                 break;
  374.             case typeof th == "object":
  375.             case typeof im == "object" && im.trace(x, y):
  376.                 if (im.mode == "last.fm") {
  377.                     _menu.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 450, "Download artist art from Last.fm");
  378.                     _menu.AppendMenuSeparator();
  379.                     _sub1.AppendMenuItem(MF_STRING, 451, "Off");
  380.                     _sub1.AppendMenuItem(MF_STRING, 452, "Library tracks only");
  381.                     _sub1.AppendMenuItem(MF_STRING, 453, "All tracks");
  382.                     _sub1.CheckMenuRadioItem(451, 453, im.auto_download == "off" ? 451 : im.auto_download == "library" ? 452 : 453);
  383.                     _sub1.AppendTo(_menu, MF_STRING, "Automatic download");
  384.                     _sub2.AppendMenuItem(MF_STRING, 461, "1");
  385.                     _sub2.AppendMenuItem(MF_STRING, 463, "3");
  386.                     _sub2.AppendMenuItem(MF_STRING, 465, "5");
  387.                     _sub2.AppendMenuItem(MF_STRING, 470, "10");
  388.                     _sub2.AppendMenuItem(MF_STRING, 480, "20");
  389.                     _sub2.CheckMenuRadioItem(461, 480, im.limit + 460);
  390.                     _sub2.AppendTo(_menu, MF_STRING, "Limit");
  391.                 } else {
  392.                     _menu.AppendMenuItem(MF_STRING, 442, "Set custom folder...");
  393.                 }
  394.                 _menu.AppendMenuSeparator();
  395.                 _menu.AppendMenuItem(MF_STRING, 403, "Re-scan folder");
  396.                 _menu.AppendMenuSeparator();
  397.                 _sub3.AppendMenuItem(MF_STRING, 440, "Last.fm artist art");
  398.                 _sub3.AppendMenuItem(MF_STRING, 441, "Custom folder");
  399.                 _sub3.CheckMenuRadioItem(440, 441, im.mode == "last.fm" ? 440 : 441);
  400.                 _sub3.AppendTo(_menu, MF_STRING, "Image source");
  401.                 _menu.AppendMenuSeparator();
  402.                 _sub4.AppendMenuItem(MF_STRING, 410, "Off");
  403.                 _sub4.AppendMenuItem(MF_STRING, 415, "5 seconds");
  404.                 _sub4.AppendMenuItem(MF_STRING, 420, "10 seconds");
  405.                 _sub4.AppendMenuItem(MF_STRING, 430, "20 seconds");
  406.                 _sub4.CheckMenuRadioItem(410, 430, im.cycle + 410);
  407.                 _sub4.AppendTo(_menu, MF_STRING, "Cycle");
  408.                 _menu.AppendMenuSeparator();
  409.                 if (typeof th == "object") {
  410.                     if (!this.check_feature("now_playing")) _sub5.AppendMenuItem(MF_STRING, 1200, "Grid");
  411.                     _sub5.AppendMenuItem(MF_STRING, 1201, "Left");
  412.                     _sub5.AppendMenuItem(MF_STRING, 1202, "Right");
  413.                     _sub5.AppendMenuItem(MF_STRING, 1203, "Top");
  414.                     _sub5.AppendMenuItem(MF_STRING, 1204, "Bottom");
  415.                     _sub5.AppendMenuItem(MF_STRING, 1205, "Off");
  416.                     _sub5.CheckMenuRadioItem(1200, 1205, th.mode == "grid" ? 1200 : th.mode == "left" ? 1201 : th.mode == "right" ? 1202 : th.mode == "top" ? 1203 : th.mode == "bottom" ? 1204 : 1205);
  417.                     if (th.mode != "off") {
  418.                         _sub5.AppendMenuSeparator();
  419.                         _sub5.AppendMenuItem(MF_STRING, 1275, "75px");
  420.                         _sub5.AppendMenuItem(MF_STRING, 1300, "100px");
  421.                         _sub5.AppendMenuItem(MF_STRING, 1350, "150px");
  422.                         _sub5.AppendMenuItem(MF_STRING, 1400, "200px");
  423.                         _sub5.AppendMenuItem(MF_STRING, 1450, "250px");
  424.                         _sub5.AppendMenuItem(MF_STRING, 1500, "300px");
  425.                         _sub5.CheckMenuRadioItem(1275, 1500, th.px + 1200);
  426.                     }
  427.                     _sub5.AppendTo(_menu, MF_STRING, "Thumbs");
  428.                     _menu.AppendMenuSeparator();
  429.                 }
  430.                 if (im.trace(x, y) && im.images.length > 0 && (!this.check_feature("thumbs") || th.mode != "grid")) {
  431.                     _menu.AppendMenuItem(MF_STRING, 400, "Open containing folder");
  432.                     _menu.AppendMenuItem(MF_STRING, 401, "Open image");
  433.                     _menu.AppendMenuItem(MF_STRING, 402, "Delete image");
  434.                     _menu.AppendMenuSeparator();
  435.                     _menu.AppendMenuItem(MF_STRING, 404, "Crop (focus on centre)");
  436.                     _menu.AppendMenuItem(MF_STRING, 405, "Crop (focus on top)");
  437.                     _menu.AppendMenuItem(MF_STRING, 406, "Centre");
  438.                     _menu.AppendMenuItem(MF_STRING, 407, "Stretch");
  439.                     _menu.CheckMenuRadioItem(404, 407, im.type == "crop" ? 404 : im.type == "crop top" ? 405 : im.type == "centre" ? 406 : 407);
  440.                     _menu.AppendMenuSeparator();
  441.                 }
  442.                 break;
  443.         }
  444.         if ((typeof a == "object" && a.trace(x, y)) || (typeof c == "object" && c.trace(x, y))) {
  445.             _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 21, "Google images (launches browser)");
  446.             _cover.AppendMenuItem(this.metadb ? MF_STRING : MF_GRAYED, 22, "Album Art Downloader");
  447.             _cover.AppendMenuSeparator();
  448.             _cover.AppendMenuItem(MF_STRING, 23, "Help");
  449.             _cover.AppendTo(_menu, MF_STRING, "Cover search");
  450.             //_menu.AppendMenuSeparator();
  451.         }
  452.         if (typeof t == "object" && t.trace(x, y)) {
  453.             //_font.AppendMenuItem(MF_STRING, 30, 12);
  454.             //_font.AppendMenuItem(MF_STRING, 31, 14);
  455.             //_font.AppendMenuItem(MF_STRING, 32, 16);
  456.            
  457.            
  458.             //_menu.AppendMenuSeparator();
  459.         }
  460.         if (this.check_feature("now_playing")) {
  461.             _menu.AppendMenuItem(MF_STRING, 44, "Top style");
  462.             _menu.AppendMenuItem(MF_STRING, 45, "Bottom style");
  463.             _menu.CheckMenuRadioItem(44, 45, np_track_top ? 44 : 45);
  464.             _menu.AppendMenuSeparator();
  465.             _menu.AppendMenuItem(MF_STRING, 41, "Show CD cover");
  466.             _menu.CheckMenuItem(41, np_cd);
  467.             _menu.AppendMenuItem(MF_STRING, 42, "Show track info");
  468.             _menu.CheckMenuItem(42, np_track);
  469.             _menu.AppendMenuItem(MF_STRING, 46, "Show rating");
  470.             _menu.CheckMenuItem(46, np_rating);
  471.             _menu.AppendMenuItem(MF_STRING, 40, "Show web links");
  472.             _menu.CheckMenuItem(40, np_buttons);
  473.             _menu.AppendMenuItem(MF_STRING, 43, "Show biography");
  474.             _menu.CheckMenuItem(43, np_bio);
  475.             _menu.AppendMenuSeparator();
  476.         }
  477.         if (this.check_feature("custom_background")) {
  478.             if (!this.dui) _custom_background.AppendMenuItem(MF_STRING, 100, "None");
  479.             _custom_background.AppendMenuItem(MF_STRING, 101, this.dui ? "Use default UI setting" : "Use columns UI setting");
  480.             _custom_background.AppendMenuItem(MF_STRING, 102, "Splitter");
  481.             _custom_background.AppendMenuItem(MF_STRING, 104, "Pattern");
  482.             _custom_background.AppendMenuItem(MF_STRING, 103, "Custom");
  483.             _custom_background.AppendMenuSeparator();
  484.             _custom_background.AppendMenuItem(this.background_mode == 3 ? MF_STRING : MF_GRAYED, 105, "Set custom colour...");
  485.             _custom_background.CheckMenuRadioItem(101, 104, this.background_mode + 100);
  486.             _custom_background.AppendTo(_menu, MF_STRING, "Background");
  487.             _menu.AppendMenuSeparator();
  488.         }
  489.         if (typeof l == "object") {
  490.             _menu.AppendMenuItem(MF_STRING, 1900, "Last.fm username...");
  491.             if (typeof ps == "object") _menu.AppendMenuItem(l.username.length > 0 ? MF_STRING : MF_GRAYED, 1901, "Last.fm password...");
  492.             _menu.AppendMenuSeparator();
  493.         }
  494.         if (this.check_feature("metadb")) {
  495.             _metadb.AppendMenuItem(MF_STRING, 900, "Use display preferences");
  496.             _metadb.AppendMenuItem(MF_STRING, 901, "Prefer now playing");
  497.             _metadb.AppendMenuItem(MF_STRING, 902, "Follow selected track");
  498.             _metadb.CheckMenuRadioItem(900, 903, this.selection_mode + 900);
  499.             //_metadb.AppendTo(_menu, MF_STRING, "Selection mode");
  500.             _menu.AppendMenuSeparator();
  501.         }
  502.         if (this.check_feature("remap")) {
  503.             _menu.AppendMenuItem(MF_STRING, 7, "Artist field remapping...");
  504.             //_menu.AppendMenuSeparator();
  505.         }
  506.         //_menu.AppendMenuItem(MF_STRING, 20, "Update script");
  507.         //_menu.AppendMenuSeparator();
  508.        
  509.        
  510.         //_menu.AppendTo(_menu, MF_STRING, "Font size");
  511.  
  512.             //_menu.AppendMenuItem(MF_STRING, 30, 12);
  513.             //_menu.AppendMenuItem(MF_STRING, 31, 14);
  514.             //_menu.AppendMenuItem(MF_STRING, 32, 16);
  515.  
  516. _menu.CheckMenuRadioItem(30, 33, this.normal_font_size == 12 ? 30 : this.normal_font_size == 14 ? 31 : 32);
  517.        
  518.        
  519.        
  520.         if (utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 9, "Properties");
  521.         //_menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  522.         idx = _menu.TrackPopupMenu(x, y);
  523.         switch(idx) {
  524.             case 1:
  525.                 on_item_focus_change();
  526.                 break;
  527.             case 2:
  528.             case 3:
  529.             case 4:
  530.             case 5:
  531.             case 6:
  532.                 a.id = idx - 2;
  533.                 window.SetProperty("artreader_id", a.id);
  534.                 on_item_focus_change();
  535.                 break;
  536.             case 7:
  537.                 this.artist_tf = this.InputBox("The default is %artist%\n\nYou can use the full foobar2000 title formatting syntax here.", "Artist field remapping", this.artist_tf);
  538.                 if (this.artist_tf == "") this.artist_tf = "%artist%";
  539.                 window.SetProperty("artist_tf", this.artist_tf);
  540.                 on_item_focus_change();
  541.                 break;
  542.             case 9:
  543.                 window.ShowProperties();
  544.                 break;
  545.             case 10:
  546.                 window.ShowConfigure();
  547.                 break;
  548.             case 11:
  549.                 c.gloss = !c.gloss;
  550.                 window.SetProperty("cd_gloss", c.gloss);
  551.                 window.Repaint();
  552.                 break;
  553.             case 12:
  554.                 c.shadow = !c.shadow;
  555.                 window.SetProperty("cd_shadow", c.shadow);
  556.                 window.Repaint();
  557.                 break;
  558.             case 15:
  559.             case 16:
  560.             case 17:
  561.             case 18:
  562.                 a.type = idx == 15 ? "crop" : idx == 16 ? "crop top" : idx == 17 ? "centre" : "stretch";
  563.                 window.SetProperty("artreader_image_type", a.type);
  564.                 window.RepaintRect(a.x, a.y, a.w, a.h);
  565.                 break;
  566.             case 20:
  567.                 this.update_script();
  568.                 break;
  569.             case 21:
  570.                 this.browser("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(this.eval("%album artist%[ %album%]")));
  571.                 break;
  572.             case 22:
  573.                 this.aad();
  574.                 break;
  575.             case 23:
  576.                 fb.ShowPopupMessage("You can get Album Art Downloader here:\n\nhttp://www.hydrogenaudio.org/forums/index.php?showtopic=57392", this.name);
  577.                 break;
  578.             case 25:
  579.             case 26:
  580.                 t.source = idx == 25 ? "last.fm" : "wikipedia";
  581.                 window.SetProperty("biography_source", t.source);
  582.                 t.artist = "";
  583.                 on_item_focus_change();
  584.                 break;
  585.             case 28:
  586.                 li.show_timestamp = !li.show_timestamp;
  587.                 window.SetProperty("show_timestamp", li.show_timestamp);
  588.                 window.RepaintRect(li.x, li.y, li.w, li.h);
  589.                 break;
  590.             case 29:
  591.                 li.discogs_match = !li.discogs_match;
  592.                 window.SetProperty("discogs_match", li.discogs_match);
  593.                 li.artist = "";
  594.                 on_item_focus_change();
  595.                 break;
  596.             case 30:
  597.             case 31:
  598.             case 32:
  599.                 this.normal_font_size = idx == 30 ? 12 : idx == 31 ? 14 : 16;
  600.                 window.SetProperty("normal_font_size", this.normal_font_size);
  601.                 this.font_changed();
  602.                 break;
  603.             case 40:
  604.                 np_buttons = !np_buttons;
  605.                 window.SetProperty("np_buttons", np_buttons);
  606.                 on_size();
  607.                 window.Repaint();
  608.                 break;
  609.             case 41:
  610.                 np_cd = !np_cd;
  611.                 window.SetProperty("np_cd", np_cd);
  612.                 window.Repaint();
  613.                 break;
  614.             case 42:
  615.                 np_track = !np_track;
  616.                 window.SetProperty("np_track", np_track);
  617.                 on_size();
  618.                 window.Repaint();
  619.                 break;
  620.             case 43:
  621.                 np_bio = !np_bio;
  622.                 window.SetProperty("np_bio", np_bio);
  623.                 window.Repaint();
  624.                 break;
  625.             case 44:
  626.             case 45:
  627.                 np_track_top = idx == 44 ? true : false;
  628.                 window.SetProperty("np_track_top", np_track_top);
  629.                 on_size();
  630.                 window.Repaint();
  631.                 break;
  632.             case 46:
  633.                 np_rating = !np_rating;
  634.                 window.SetProperty("np_rating", np_rating);
  635.                 on_size();
  636.                 window.Repaint();
  637.                 break;
  638.             case 51:
  639.             case 52:
  640.             case 53:
  641.                 l.auto_correct = !l.auto_correct;
  642.                 window.SetProperty("lastfm_auto_correct", l.auto_correct);
  643.                 if (this.metadb) {
  644.                     if (idx == 51) li.get();
  645.                     if (idx == 53) t.get();
  646.                 }
  647.                 break;
  648.             case 100:
  649.             case 101:
  650.             case 102:
  651.             case 103:
  652.             case 104:
  653.                 this.background_mode = idx - 100;
  654.                 window.SetProperty("background_mode", this.background_mode);
  655.                 window.Repaint();
  656.                 break;
  657.             case 105:
  658.                 this.background_custom_colour = this.InputBox("Enter a custom colour for the background. Uses RGB. Example usage:\n\n234-211-74", this.name, this.background_custom_colour);
  659.                 window.SetProperty("background_custom_colour", this.background_custom_colour);
  660.                 window.Repaint();
  661.                 break;
  662.             case 200:
  663.                 t.filename_tf = this.InputBox("Use title formatting to specify a path to your text file. eg: $directory_path(%path%)\\info.txt\n\nIf you prefer, you can specify just the path to a folder and the first txt or log file will be used.", this.name, t.filename_tf);
  664.                 window.SetProperty("text_filename_tf", t.filename_tf);
  665.                 on_item_focus_change();
  666.                 break;
  667.             case 201:
  668.                 t.fixed = !t.fixed;
  669.                 window.SetProperty("text_fixed_font", t.fixed);
  670.                 t.calc();
  671.                 window.RepaintRect(t.x, t.y, t.w, t.h);
  672.                 break;
  673.             case 400:
  674.                 this.run("explorer /select,\"" + im.files[im.index] + "\"");
  675.                 break;
  676.             case 401:
  677.                 this.run("\"" + im.files[im.index] + "\"");
  678.                 break;
  679.             case 402:
  680.                 im.delete_image();
  681.                 break;
  682.             case 403:
  683.                 im.update();
  684.                 break;
  685.             case 404:
  686.             case 405:
  687.             case 406:
  688.             case 407:
  689.                 im.type = idx == 404 ? "crop" : idx == 405 ? "crop top" : idx == 406 ? "centre" : "stretch";
  690.                 window.SetProperty("image_type", im.type);
  691.                 window.Repaint();
  692.                 break;
  693.             case 410:
  694.             case 415:
  695.             case 420:
  696.             case 430:
  697.                 im.cycle = idx - 410;
  698.                 window.SetProperty("image_cycle", im.cycle);
  699.                 break;
  700.             case 440:
  701.             case 441:
  702.                 im.mode = idx == 440 ? "last.fm" : "custom";
  703.                 window.SetProperty("image_mode", im.mode);
  704.                 im.artist = "";
  705.                 im.folder = "";
  706.                 on_item_focus_change();
  707.                 break;
  708.             case 442:
  709.                 im.custom_folder_tf = this.InputBox("Enter title formatting or an absolute path to a folder. You can specify multiple folders using | as a separator.", this.name, im.custom_folder_tf);
  710.                 if (im.custom_folder_tf == "") im.custom_folder_tf = "$directory_path(%path%)";
  711.                 window.SetProperty("image_custom_folder_tf", im.custom_folder_tf);
  712.                 im.folder = "";
  713.                 on_item_focus_change();
  714.                 break;
  715.             case 450:
  716.                 im.download();
  717.                 break;
  718.             case 451:
  719.             case 452:
  720.             case 453:
  721.                 im.auto_download = idx == 451 ? "off" : idx == 452 ? "library" : "all";
  722.                 window.SetProperty("image_auto_download", im.auto_download);
  723.                 break;
  724.             case 461:
  725.             case 463:
  726.             case 465:
  727.             case 470:
  728.             case 480:
  729.                 im.limit = idx - 460;
  730.                 window.SetProperty("image_limit", im.limit);
  731.                 break;
  732.             case 490:
  733.             case 491:
  734.             case 492:
  735.             case 493:
  736.                 im.type = idx == 490 ? "crop" : idx == 491 ? "crop top" : idx == 492 ? "centre" : "stretch";
  737.                 window.SetProperty("image_type", im.type);
  738.                 window.RepaintRect(im.x, im.y, im.w, im.h);
  739.                 break;
  740.             case 500:
  741.             case 501:
  742.             case 502:
  743.                 li.echonest_mode = idx - 500;
  744.                 window.SetProperty("echonest_mode", li.echonest_mode);
  745.                 li.artist = "";
  746.                 on_item_focus_change();
  747.                 break;
  748.             case 600:
  749.                 li.autoplaylists_title = this.InputBox("Enter a new title", this.name, li.autoplaylists_title);
  750.                 if (li.autoplaylists_title == "") li.autoplaylists_title = "Autoplaylists";
  751.                 window.SetProperty("autoplaylists_title", li.autoplaylists_title);
  752.                 window.Repaint();
  753.                 break;
  754.             case 601:
  755.             case 602:
  756.             case 603:
  757.             case 604:
  758.             case 605:
  759.             case 606:
  760.             case 607:
  761.             case 608:
  762.                 li.autoplaylists_slot = idx - 600;
  763.                 window.SetProperty("autoplaylists_slot", li.autoplaylists_slot);
  764.                 li.filename = this.settings_folder + "autoplaylists" + li.autoplaylists_slot;
  765.                 li.offset = 0;
  766.                 li.update();
  767.                 break;
  768.             case 610:
  769.             case 611:
  770.                 li.autoplaylists_success = idx == 610 ? true : false;
  771.                 window.SetProperty("autoplaylists_success", li.autoplaylists_success);
  772.                 break;
  773.             case 620:
  774.             case 621:
  775.             case 622:
  776.             case 623:
  777.             case 624:
  778.             case 625:
  779.             case 626:
  780.             case 627:
  781.                 li.data.push(li.autoplaylists_deleted_items[idx - 620]);
  782.                 if (li.data.length > li.rows) li.offset = li.data.length - li.rows;
  783.                 li.autoplaylists_deleted_items.splice(idx - 620, 1);
  784.                 this.save(li.data.join("\n"), li.filename);
  785.                 window.NotifyOthers("autoplaylists", "update");
  786.                 li.update();
  787.                 break;
  788.             case 650:
  789.                 li.autoplaylists_remove_duplicates = !li.autoplaylists_remove_duplicates
  790.                 window.SetProperty("autoplaylists_remove_duplicates", li.autoplaylists_remove_duplicates);
  791.                 break;
  792.             case 700:
  793.             case 701:
  794.                 li.musicbrainz_mode = idx == 700 ? "releases" : "URLs";
  795.                 window.SetProperty("musicbrainz_mode", li.musicbrainz_mode);
  796.                 li.artist = "";
  797.                 on_item_focus_change();
  798.                 break;
  799.             case 702:
  800.                 li.musicbrainz_live = !li.musicbrainz_live;
  801.                 window.SetProperty("musicbrainz_live", li.musicbrainz_live);
  802.                 li.artist = "";
  803.                 on_item_focus_change();
  804.                 break;
  805.             case 703:
  806.                 li.musicbrainz_album = !li.musicbrainz_album;
  807.                 window.SetProperty("musicbrainz_album", li.musicbrainz_album);
  808.                 li.artist = "";
  809.                 on_item_focus_change();
  810.                 break;
  811.             case 704:
  812.                 li.musicbrainz_ep = !li.musicbrainz_ep;
  813.                 window.SetProperty("musicbrainz_ep", li.musicbrainz_ep);
  814.                 li.artist = "";
  815.                 on_item_focus_change();
  816.                 break;
  817.             case 705:
  818.                 li.musicbrainz_single= !li.musicbrainz_single;
  819.                 window.SetProperty("musicbrainz_single", li.musicbrainz_single);
  820.                 li.artist = "";
  821.                 on_item_focus_change();
  822.                 break;
  823.             case 706:
  824.                 li.musicbrainz_show_release_type = !li.musicbrainz_show_release_type;
  825.                 window.SetProperty("musicbrainz_show_release_type", li.musicbrainz_show_release_type);
  826.                 window.RepaintRect(li.x, li.y, li.w, li.h);
  827.                 break;
  828.             case 801:
  829.             case 802:
  830.             case 803:
  831.             case 804:
  832.             case 805:
  833.                 li.lastfm_mode = idx - 801;
  834.                 window.SetProperty("lastfm_mode", li.lastfm_mode);
  835.                 li.artist = "";
  836.                 on_item_focus_change();
  837.                 break;
  838.             case 810:
  839.                 li.lastfm_pause = !li.lastfm_pause;
  840.                 window.SetProperty("lastfm_pause", li.lastfm_pause);
  841.                 break;
  842.             case 811:
  843.             case 812:
  844.                 li.lastfm_button = idx == 811 ? "spotify" : "auto";
  845.                 window.SetProperty("lastfm_button", li.lastfm_button);
  846.                 window.RepaintRect(li.x, li.y, li.w, li.h);
  847.                 break;
  848.             case 900:
  849.             case 901:
  850.             case 902:
  851.                 this.selection_mode = idx - 900;
  852.                 window.SetProperty("selection_mode", this.selection_mode);
  853.                 on_item_focus_change();
  854.                 break;
  855.             case 1000:
  856.                 li.get();
  857.                 break;
  858.             case 1001:
  859.             case 1002:
  860.             case 1003:
  861.                 li.lastfm_charts_mode = idx - 1001;
  862.                 window.SetProperty("lastfm_charts_mode", li.lastfm_charts_mode);
  863.                 li.update();
  864.                 break;
  865.             case 1004:
  866.             case 1005:
  867.             case 1006:
  868.             case 1007:
  869.             case 1008:
  870.             case 1009:
  871.                 li.lastfm_charts_period = idx - 1004;
  872.                 window.SetProperty("lastfm_charts_period", li.lastfm_charts_period);
  873.                 li.update();
  874.                 break;
  875.             case 1010:
  876.                 li.lastfm_charts_bar_colour = this.InputBox("Enter a custom colour for the bars. Uses RGB. Example usage:\n\n234-211-74", this.name, li.lastfm_charts_bar_colour);
  877.                 window.SetProperty("lastfm_charts_bar_colour", li.lastfm_charts_bar_colour);
  878.                 window.Repaint();
  879.                 break;
  880.             case 1100:
  881.             case 1109:
  882.                 ps.full_import = idx == 1100 ? true : false;
  883.                 ps.start_import();
  884.                 break;
  885.             case 1101:
  886.                 ps.finish_import();
  887.                 break;
  888.             case 1102:
  889.                 ps.show_console = !ps.show_console;
  890.                 window.SetProperty("playcount_sync_show_console", ps.show_console);
  891.                 break;
  892.             case 1103:
  893.                 ps.library = !ps.library;
  894.                 window.SetProperty("playcount_sync_library", ps.library);
  895.                 break;
  896.             case 1104:
  897.             case 1105:
  898.                 ps.auto_love = idx == 1104 ? false : true;
  899.                 window.SetProperty("playcount_sync_auto_love", ps.auto_love);
  900.                 break;
  901.             case 1106:
  902.                 ps.auto_love_tf = this.InputBox("The result of the title formatting set here must equal 1 for a track to be automatically loved.\n\nExample:\n\n$ifequal(%rating%,5,1,0)", this.name, ps.auto_love_tf);
  903.                 window.SetProperty("playcount_sync_auto_love_tf", ps.auto_love_tf);
  904.                 break;
  905.             case 1107:
  906.             case 1108:
  907.                 ps.icon = idx == 1107 ? "tango" : "silk";
  908.                 window.SetProperty("playcount_sync_icon", ps.icon);
  909.                 b.update();
  910.                 break;
  911.             case 1200:
  912.             case 1201:
  913.             case 1202:
  914.             case 1203:
  915.             case 1204:
  916.             case 1205:
  917.                 th.mode = idx == 1200 ? "grid" : idx == 1201 ? "left" : idx == 1202 ? "right" : idx == 1203 ? "top" : idx == 1204 ? "bottom" : "off";
  918.                 window.SetProperty("thumbs_mode", th.mode);
  919.                 th.nc = true;
  920.                 on_size();
  921.                 window.Repaint();
  922.                 break;
  923.             case 1275:
  924.             case 1300:
  925.             case 1350:
  926.             case 1400:
  927.             case 1450:
  928.             case 1500:
  929.                 th.px = idx - 1200;
  930.                 window.SetProperty("thumbs_px", th.px);
  931.                 th.nc = true;
  932.                 on_size();
  933.                 window.Repaint();
  934.                 break;
  935.             case 1700:
  936.                 t.title = this.InputBox("You can use full title formatting here.", this.name, t.title);
  937.                 window.SetProperty("text_title", t.title);
  938.                 window.Repaint();
  939.                 break;
  940.             case 1701:
  941.                 t.tag = this.InputBox("Enter a custom tag.", this.name, t.tag);
  942.                 window.SetProperty("text_tag", t.tag);
  943.                 t.filename = "";
  944.                 on_item_focus_change();
  945.                 break;
  946.             case 1702:
  947.                 t.centre = !t.centre;
  948.                 window.SetProperty("text_centre", t.centre);
  949.                 window.RepaintRect(t.x, t.y, t.w, t.h);
  950.                 break;
  951.             case 1800:
  952.             case 1801:
  953.             case 1802:
  954.                 var period = idx == 1800 ? 0 : idx == 1801 ? ONE_DAY : ONE_WEEK;
  955.                 s.clear_images(period);
  956.                 break;
  957.             case 1803:
  958.                 s.library = !s.library;
  959.                 window.SetProperty("seekbar_library", s.library);
  960.                 break;
  961.             case 1804:
  962.                 s.sox_params = this.InputBox("All SoX spectrogram options should work here.\n\n-r, -d and -o are already configured so do not use those. Check sox.pdf for everything else.", this.name, s.sox_params);
  963.                 window.SetProperty("sox_params", s.sox_params);
  964.                 if (fb.IsPlaying) s.playback_new_track();
  965.                 break;
  966.             case 1805:
  967.                 s.marker = this.InputBox("Enter a custom colour for the marker. Uses RGB. Example usage:\n\n234-211-74", this.name, s.marker);
  968.                 window.SetProperty("seekbar_marker", s.marker);
  969.                 break;
  970.             case 1900:
  971.                 l.update_username();
  972.                 break;
  973.             case 1901:
  974.                 l.update_password();
  975.                 break;
  976.         }
  977.         _menu.Dispose();
  978.         _custom_background.Dispose();
  979.         _metadb.Dispose();
  980.         _cover.Dispose();
  981.         _font.Dispose();
  982.         _sub1.Dispose();
  983.         _sub2.Dispose();
  984.         _sub3.Dispose();
  985.         _sub4.Dispose();
  986.         _sub5.Dispose();
  987.     }
  988.    
  989.     this.features_init = function() {
  990.         for (i = 0; i < this.features.length; i++) {
  991.             switch(this.features[i]) {
  992.                 case "custom_background":
  993.                     this.background_mode = window.GetProperty("background_mode", 1);
  994.                     this.background_custom_colour = window.GetProperty("background_custom_colour", "0-0-0");
  995.                     break;
  996.                 case "metadb":
  997.                     this.selection_mode = window.GetProperty("selection_mode", 0);
  998.                     this.metadb = fb.GetFocusItem();
  999.                     break;
  1000.                 case "themes":
  1001.                     this.themed_seekbar = window.CreateThemeManager("Progress");
  1002.                     this.themed_header = window.CreateThemeManager("Header");
  1003.                     this.themed_header.SetPartAndStateId(1, 1);
  1004.                     this.themed_button = window.CreateThemeManager("Button");
  1005.                     break;
  1006.                 case "remap":
  1007.                     this.artist_tf = window.GetProperty("artist_tf", "%artist%");
  1008.                     break;
  1009.             }
  1010.         }
  1011.     }
  1012.    
  1013.     this.eval = function(tf) {
  1014.         if (!this.metadb || tf == "") return "";
  1015.         if (fb.IsPlaying && this.metadb.RawPath.indexOf("file://") != 0) {
  1016.             return fb.TitleFormat(tf).Eval();
  1017.         } else {
  1018.             return fb.TitleFormat(tf).EvalWithMetadb(this.metadb);
  1019.         }
  1020.     }
  1021.    
  1022.     this.open = function(filename) {
  1023.         return utils.ReadTextFile(filename);
  1024.     }
  1025.    
  1026.     this.save = function(t, f) {
  1027.         try {
  1028.             var ts = this.fso.OpenTextFile(f, 2, true, -1);
  1029.             ts.WriteLine(t);
  1030.             ts.Close();
  1031.             return true;
  1032.         } catch(e) {
  1033.             return false;
  1034.         }
  1035.     }
  1036.    
  1037.     this.console = function(message) {
  1038.         fb.trace(this.name + ": " + message);
  1039.     }
  1040.    
  1041.     this.strip_tags = function(value) {
  1042.         try {
  1043.             this.doc.open();
  1044.             var div = this.doc.createElement("div");
  1045.             div.innerHTML = value.replace(/\n/g, "<br>");
  1046.             return div.innerText.trim();
  1047.         } catch(e) {
  1048.             return "Error reading content.";
  1049.         }
  1050.     }
  1051.    
  1052.     this.InputBox = function(prompt, title, value) {
  1053.         prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  1054.         title = title.replace(/"/g, '" + Chr(34) + "');
  1055.         value = value.replace(/"/g, '" + Chr(34) + "');
  1056.         var temp_value = this.vb.eval('InputBox' + '("' + prompt + '", "' + title + '", "' + value + '")');
  1057.         return typeof temp_value == "undefined" ? value : temp_value.trim();
  1058.     }
  1059.    
  1060.     this.MsgBox = function(prompt, buttons, title) {
  1061.         prompt = prompt.replace(/"/g, '" + Chr(34) + "').replace(/\n/g, '" + Chr(13) + "');
  1062.         title = title.replace(/"/g, '" + Chr(34) + "');
  1063.         return this.vb.eval('MsgBox' + '("' + prompt + '", "' + buttons + '", "' + title + '")');
  1064.     }
  1065.    
  1066.     this.check_feature = function(f) {
  1067.         for (i = 0; i < this.features.length; i++) {
  1068.             if (this.features[i] == f) return true;
  1069.         }
  1070.         return false;
  1071.     }
  1072.    
  1073.     this.browser = function(command) {
  1074.         if (!this.run(command)) this.MsgBox("Unable to launch your default browser.", 0, this.name);
  1075.     }
  1076.    
  1077.     this.run = function(command) {
  1078.         try {
  1079.             this.WshShell.Run(command);
  1080.             return true;
  1081.         } catch(e) {
  1082.             return false;
  1083.         }
  1084.     }
  1085.    
  1086.     this.aad = function() {
  1087.         var aad_path = window.GetProperty("aad_path", "");
  1088.         if (!this.fso.FileExists(aad_path)) {
  1089.             var folder = this.app.BrowseForFolder(0, "Locate Album Art Downloader", 0x00000200);
  1090.             var file = folder ? folder.items().item().path + "\\AlbumArt.exe" : "";
  1091.             if (this.fso.FileExists(file)) {
  1092.                 aad_path = file;
  1093.                 window.SetProperty("aad_path", file);
  1094.             }
  1095.         }
  1096.         if (this.fso.FileExists(aad_path)) {
  1097.             var album_artist = "/ar \"" + this.eval("[%album artist%]") + "\"";
  1098.             var album = " /al \"" + this.eval("[%album%]") + "\"";
  1099.             this.run("\"" + aad_path + "\"" + album_artist + album);
  1100.         }
  1101.     }
  1102.    
  1103.     this.tt = function(t) {
  1104.         if (this.tooltip.Text == t) return;
  1105.         this.tooltip.Text = t;
  1106.         this.tooltip.Activate();
  1107.     }
  1108.    
  1109.     this.ttd = function() {
  1110.         this.tooltip.Text = "";
  1111.         this.tooltip.Deactivate();
  1112.     }
  1113.    
  1114.     this.splitRGB = function(value) {
  1115.         var temp_col = value.split("-");
  1116.         return RGB(temp_col[0], temp_col[1], temp_col[2]);
  1117.     }
  1118.    
  1119.     this.draw_background = function(gr) {
  1120.         if (this.check_feature("custom_background")) {
  1121.             var col;
  1122.             switch(this.background_mode) {
  1123.                 case 0:
  1124.                     col = null;
  1125.                     break;
  1126.                 case 1:
  1127.                     col = this.backcolour;
  1128.                     break;
  1129.                 case 2:
  1130.                     col = utils.GetSysColor(15);
  1131.                     break;
  1132.                 case 3:
  1133.                     col = this.splitRGB(this.background_custom_colour);
  1134.                     break;
  1135.                 case 4:
  1136.                     col = null;
  1137.                     var spacing = 3;
  1138.                     var line_thickness = 1;
  1139.                     var bg = RGB(65, 65, 65);
  1140.                     var colour = RGB(92, 92, 92);
  1141.                     gr.FillSolidRect(0, 0, this.w, this.h, bg);
  1142.                     for (i = 0; i < Math.ceil(this.w / spacing); i++) {
  1143.                         gr.DrawLine(i * spacing, 0, i * spacing, this.h, line_thickness, colour);
  1144.                     }
  1145.                     for (i = 0; i < Math.ceil(this.h / spacing); i++) {
  1146.                         gr.DrawLine(0, i * spacing, this.w, i * spacing, line_thickness, colour);
  1147.                     }
  1148.                     break;
  1149.             }
  1150.             if (col) gr.FillSolidRect(0, 0, this.w, this.h, col);
  1151.         } else {
  1152.             gr.FillSolidRect(0, 0, this.w, this.h, this.backcolour);
  1153.         }
  1154.     }
  1155.    
  1156.     this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
  1157.         if (!img) return;
  1158.         gr.SetInterpolationMode(7);
  1159.         switch(type) {
  1160.             case "crop":
  1161.             case "crop top":
  1162.                 var sr = img.Width / img.Height;
  1163.                 var dr = width / height;
  1164.                 if (sr < dr) {
  1165.                     var r = img.Width / width;
  1166.                     var ch = height * r;
  1167.                     var sy = Math.round((img.Height - ch) / (type == "crop top" ? 4 : 2));
  1168.                     var cw = img.Width;
  1169.                     var sx = 0;
  1170.                 } else {
  1171.                     var r = img.Height / height;
  1172.                     var cw = width * r;
  1173.                     var sx = Math.round((img.Width - cw) / 2);
  1174.                     var ch = img.Height;
  1175.                     var sy = 0;
  1176.                 }
  1177.                 gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
  1178.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  1179.                 break;
  1180.             case "stretch":
  1181.                 gr.DrawImage(img, pos_x, pos_y, width, height, 0, 0, img.Width, img.Height, 0, alpha || 255);
  1182.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  1183.                 break;
  1184.             case "centre":
  1185.             default:
  1186.                 var s = Math.min(width / img.Width, height / img.Height);
  1187.                 var nw = Math.round(img.Width * s);
  1188.                 var nh = Math.round(img.Height * s);
  1189.                 pos_x += Math.round((width - nw) / 2);
  1190.                 pos_y += Math.round((height - nh) / 2);
  1191.                 gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.Width, img.Height, 0, alpha || 255);
  1192.                 if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
  1193.                 break;
  1194.         }
  1195.     }
  1196.    
  1197.     this.header = function(gr, text) {
  1198.         this.left_text(gr, text, this.title_font, this.textcolour_hl, 6, 6, this.w - 77, 24);
  1199.         gr.DrawLine(6, 29, this.w - 6, 29, 1, this.textcolour_hl);
  1200.     }
  1201.    
  1202.     this.centre_text = function(gr, text, font, colour, x, y, w, h) {
  1203.         gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  1204.     }
  1205.    
  1206.     this.left_text = function(gr, text, font, colour, x, y, w, h) {
  1207.         gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  1208.     }
  1209.    
  1210.     this.right_text = function(gr, text, font, colour, x, y, w, h) {
  1211.         gr.GdiDrawText(text, font, colour, x, y, w, h, DT_VCENTER | DT_RIGHT | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
  1212.     }
  1213.    
  1214.     this.format_time = function(t) {
  1215.         var h = Math.floor(t / 3600);
  1216.         var m = Math.floor((t -= h * 3600) / 60);
  1217.         var s = Math.floor(t -= m * 60);
  1218.         return((h > 0 ? h + ":" + (m < 10 ? "0" + m : m) : m) + ":" + (s < 10 ? "0" + s : s));
  1219.     }
  1220.    
  1221.     this.check_version = function() {
  1222.         //not used any more but will leave intact so old scripts don't crash.
  1223.         return;
  1224.     }
  1225.    
  1226.     this.update_script = function() {
  1227.         this.xmlhttp.open("GET", this.common_url, true);
  1228.         this.xmlhttp.send();
  1229.         this.xmlhttp.onreadystatechange = function() {
  1230.             if (p.xmlhttp.readyState == 4) {
  1231.                 switch(p.xmlhttp.status) {
  1232.                     case 200:
  1233.                         var text = p.xmlhttp.responsetext;
  1234.                         switch (true) {
  1235.                             case text.indexOf("function panel") == -1:
  1236.                                 p.MsgBox("Unexpected server error. Not updating.", 0, p.name);
  1237.                                 break;
  1238.                             case text.indexOf('var VERSION = "' + VERSION) == 0:
  1239.                                 p.MsgBox("Already using latest version.", 0, p.name);
  1240.                                 break;
  1241.                             default:
  1242.                                 if (p.save(text, p.common_filename)) {
  1243.                                     if (p.MsgBox("Download successful. Restart foobar2000 now?", 4, p.name) == 6) fb.RunMainMenuCommand("File/Restart");
  1244.                                 } else {
  1245.                                     p.MsgBox("Unexpected error. Not updating.", 0, p.name);
  1246.                                 }
  1247.                                 break;
  1248.                         }
  1249.                         break;
  1250.                     case 404:
  1251.                         fb.ShowPopupMessage("The script reports that the update file has not been found. It could be a temporary problem with dropbox but if this error persists then it is most likely due to support stopping for this version. Check the hydrogenaudio thread or the full zip for updates.\n\nhttp://www.hydrogenaudio.org/forums/index.php?showtopic=77883\n" + p.root_url + "samples.zip", p.name);
  1252.                         break;
  1253.                     default:
  1254.                         p.console(p.xmlhttp.responsetext || "HTTP error: " + p.xmlhttp.status);
  1255.                         break;
  1256.                 }
  1257.             }
  1258.         }
  1259.     }
  1260.    
  1261.     this.json = function(text) {
  1262.         try {
  1263.             var data = JSON.parse(text);
  1264.             return data;
  1265.         } catch(e) {
  1266.             this.console("JSON.parse error.");
  1267.             return false;
  1268.         }
  1269.     }
  1270.    
  1271.     this.json_reverse_sort = function(data, prop) {
  1272.         data = data.sort(function(a, b) {
  1273.             if (!a[prop] || b[prop] > a[prop]) return 1;
  1274.             if (!b[prop] || b[prop] < a[prop]) return -1;
  1275.             return 0;
  1276.         });
  1277.         return data;
  1278.     }
  1279.    
  1280.     this.name = name;
  1281.     this.features = features;
  1282.     this.dui = window.InstanceType;
  1283.     this.script_path = fb.ProfilePath + "marc2003\\";
  1284.     this.images_path = this.script_path + "images\\";
  1285.     this.root_url = "https://dl.dropboxusercontent.com/u/22801321/wsh/"
  1286.     this.common_url = this.root_url + "marc2003/common7.js";
  1287.     this.common_filename = this.script_path + "common7.js";
  1288.     this.tooltip = window.CreateTooltip();
  1289.     this.w = 0;
  1290.     this.h = 0;
  1291.     this.mx = 0;
  1292.     this.my = 0;
  1293.     this.metadb = fb.GetFocusItem();
  1294.     this.app = new ActiveXObject("Shell.Application");
  1295.     this.WshShell = new ActiveXObject("WScript.Shell");
  1296.     this.fso = new ActiveXObject("Scripting.FileSystemObject");
  1297.     this.doc = new ActiveXObject("htmlfile");
  1298.     this.vb = new ActiveXObject("ScriptControl");
  1299.     this.vb.Language = "VBScript";
  1300.     this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1301.     this.settings_folder = fb.ProfilePath + "wsh_settings\\";
  1302.     if (!this.fso.FolderExists(this.settings_folder)) this.fso.CreateFolder(this.settings_folder);
  1303.     this.data_folder = fb.ProfilePath + "wsh_lastfm\\";
  1304.     if (!this.fso.FolderExists(this.data_folder)) this.fso.CreateFolder(this.data_folder);
  1305.     this.artist = "";
  1306.     this.artist_tf = "%artist%";
  1307.     this.normal_font_size = window.GetProperty("normal_font_size", 12);
  1308.     this.list_font_size = 11;
  1309.     this.up_img = gdi.Image(this.images_path + "up.png");
  1310.     this.down_img = gdi.Image(this.images_path + "down.png");
  1311.     this.features_init();
  1312.     this.colors_changed();
  1313.     this.font_changed();
  1314. }
  1315.  
  1316. function artreader(x, y, w, h) {
  1317.     this.draw = function(gr) {
  1318.         if (!this.img) return;
  1319.         p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
  1320.     }
  1321.    
  1322.     this.metadb_changed = function() {
  1323.         if (!p.metadb) return;
  1324.         this.img && this.img.Dispose();
  1325.         this.path = "";
  1326.         this.img = utils.GetAlbumArtV2(p.metadb, this.id);
  1327.         window.RepaintRect(this.x, this.y, this.w, this.h);
  1328.         utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
  1329.     }
  1330.    
  1331.     this.get_album_art_done = function(ip) {
  1332.         this.path = ip;
  1333.     }
  1334.    
  1335.     this.trace = function(x, y) {
  1336.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  1337.     }
  1338.    
  1339.     this.wheel = function(step) {
  1340.         if (!this.trace(p.mx, p.my)) return false;
  1341.         this.id -= step;
  1342.         if (this.id < 0) this.id = 4;
  1343.         if (this.id > 4) this.id = 0;
  1344.         window.SetProperty("artreader_id", this.id);
  1345.         this.metadb_changed();
  1346.         return true;
  1347.     }
  1348.    
  1349.     this.move = function(x, y) {
  1350.         if (this.trace(x, y)) {
  1351.             if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  1352.             return true;
  1353.         } else {
  1354.             p.ttd();
  1355.             return false;
  1356.         }
  1357.     }
  1358.    
  1359.     this.lbtn_dblclk = function(x, y) {
  1360.         if (!this.trace(x, y)) return false;
  1361.         if (this.img) p.run("explorer /select,\"" + this.path + "\"");
  1362.         return true;
  1363.     }
  1364.    
  1365.     this.x = x;
  1366.     this.y = y;
  1367.     this.w = w;
  1368.     this.h = h;
  1369.     this.id = window.GetProperty("artreader_id", 0);
  1370.     this.img = null;
  1371.     this.path = null;
  1372.     this.type = window.GetProperty("artreader_image_type", "crop");
  1373. }
  1374.  
  1375. function buttons() {
  1376.     this.draw = function(gr) {
  1377.         for (i in this.buttons) {
  1378.             this.buttons[i].draw(gr);
  1379.         }
  1380.     }
  1381.    
  1382.     this.move = function(x, y) {
  1383.         this.tmp_btn = null;
  1384.         for (i in this.buttons) {
  1385.             if (this.buttons[i].trace(x, y)) this.tmp_btn = i;
  1386.         }
  1387.         if (this.btn == this.tmp_btn) return this.btn;
  1388.         if (this.tmp_btn) this.buttons[this.tmp_btn].state("hover");
  1389.         if (this.btn) this.buttons[this.btn].state("normal");
  1390.         this.btn = this.tmp_btn;
  1391.         return this.btn;
  1392.     }
  1393.    
  1394.     this.lbtn_up = function(x, y) {
  1395.         if (!this.btn) return false;
  1396.         this.buttons[this.btn].lbtn_up(x, y);
  1397.         return true;
  1398.     }
  1399.    
  1400.     this.leave = function() {
  1401.         if (this.btn) this.buttons[this.btn].state("normal");
  1402.         this.btn = null;
  1403.     }
  1404.    
  1405.     this.buttons = [];
  1406.     this.btn = null;
  1407. }
  1408.  
  1409. function button(x, y, w, h, img_src, func, tiptext, themed) {
  1410.     this.draw = function (gr) {
  1411.         if (this.themed) {
  1412.             p.themed_button.SetPartAndStateId(1, this.id);
  1413.             p.themed_button.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
  1414.             this.img && p.draw_image(gr, this.img, this.x + Math.round((this.w - this.img.Width) / 2), this.y + Math.round((this.h - this.img.Height) / 2), this.img.Width, this.img.Height, "centre");
  1415.         } else {
  1416.             this.img && p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "centre");
  1417.         }
  1418.     }
  1419.    
  1420.     this.trace = function(x, y) {
  1421.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  1422.     }
  1423.    
  1424.     this.lbtn_up = function () {
  1425.         this.func && this.func(x, y);
  1426.     }
  1427.    
  1428.     this.state = function(s) {
  1429.         if (s == "hover") {
  1430.             this.img = this.img_hover;
  1431.             this.id = 2;
  1432.             p.tt(this.tiptext);
  1433.         } else {
  1434.             this.img = this.img_normal;
  1435.             this.id = 0;
  1436.             p.ttd();
  1437.         }
  1438.         window.RepaintRect(this.x, this.y, this.w, this.h);
  1439.     }
  1440.    
  1441.     this.x = x;
  1442.     this.y = y;
  1443.     this.w = w;
  1444.     this.h = h;
  1445.     this.func = func;
  1446.     this.tiptext = tiptext;
  1447.     this.themed = themed;
  1448.     this.id = 0;
  1449.     this.img_normal = gdi.Image(p.images_path + img_src.normal);
  1450.     this.img_hover = img_src.hover ? gdi.Image(p.images_path + img_src.hover) : this.img_normal;
  1451.     this.img = this.img_normal;
  1452. }
  1453.  
  1454. function cd(x, y, w, h) {
  1455.     this.draw = function(gr) {
  1456.         if (this.shadow) p.draw_image(gr, this.shadow_img, this.x, this.y, this.w, this.h, "centre");
  1457.         p.draw_image(gr, this.case_img, this.x, this.y, this.w, this.h, "centre");
  1458.         if (this.img) {
  1459.             this.ratio = Math.min(this.w / this.case_img.Width, this.h / this.case_img.Height);
  1460.             this.nw = 488 * this.ratio;
  1461.             this.nh = 476 * this.ratio;
  1462.             this.nx = Math.round((this.w - (452 * this.ratio)) / 2);
  1463.             this.ny = Math.round((this.h - this.nh) / 2);
  1464.             p.draw_image(gr, this.img, this.nx + this.x, this.ny + this.y, this.nw, this.nh, "crop top");
  1465.         }
  1466.         p.draw_image(gr, this.semi_img, this.x, this.y, this.w, this.h, "centre");
  1467.         if (this.gloss) p.draw_image(gr, this.gloss_img, this.x, this.y, this.w, this.h, "centre");
  1468.     }
  1469.    
  1470.     this.metadb_changed = function() {
  1471.         if (!p.metadb) return;
  1472.         this.img && this.img.Dispose();
  1473.         this.path = "";
  1474.         this.img = utils.GetAlbumArtV2(p.metadb, 0);
  1475.         window.Repaint();
  1476.         utils.GetAlbumArtAsync(window.ID, p.metadb, 0);
  1477.     }
  1478.    
  1479.     this.get_album_art_done = function(ip) {;
  1480.         this.path = ip;
  1481.     }
  1482.    
  1483.     this.trace = function(x, y) {
  1484.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  1485.     }
  1486.    
  1487.     this.move = function(x, y) {
  1488.         if (this.trace(x, y)) {
  1489.             if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  1490.             return true;
  1491.         } else {
  1492.             p.ttd();
  1493.             return false;
  1494.         }
  1495.     }
  1496.    
  1497.     this.lbtn_dblclk = function(x, y) {
  1498.         if (!this.trace(x, y)) return false;
  1499.         if (this.img) p.run("explorer /select,\"" + this.path + "\"");
  1500.         return true;
  1501.     }
  1502.    
  1503.     this.x = x;
  1504.     this.y = y;
  1505.     this.w = w;
  1506.     this.h = h;
  1507.     this.shadow_img = gdi.Image(p.images_path + "shadow.png");
  1508.     this.case_img = gdi.Image(p.images_path + "case.png");
  1509.     this.semi_img = gdi.Image(p.images_path + "semi.png");
  1510.     this.gloss_img = gdi.Image(p.images_path + "gloss.png");
  1511.     this.gloss = window.GetProperty("cd_gloss", true);
  1512.     this.shadow = window.GetProperty("cd_shadow", true);
  1513.     this.img = null;
  1514.     this.path = null;
  1515. }
  1516.  
  1517. function images(x, y, w, h) {
  1518.     this.playback_time = function(time) {
  1519.         if (this.mode == "last.fm" && time == 1 && this.files.length == 0 && p.metadb.RawPath == fb.GetNowPlaying().RawPath && ((this.auto_download == "library" && fb.IsMetadbInMediaLibrary(p.metadb)) || this.auto_download == "all")) this.download();
  1520.         if (this.cycle > 0 && this.images.length > 1 && time % this.cycle == 0) {
  1521.             this.index++;
  1522.             if (this.index == this.images.length) this.index = 0;
  1523.             window.RepaintRect(this.x, this.y, this.w, this.h);
  1524.         }
  1525.     }
  1526.    
  1527.     this.draw = function (gr) {
  1528.         if (this.images.length == 0) return;
  1529.         p.draw_image(gr, this.images[this.index], this.x, this.y, this.w, this.h, this.type);
  1530.     }
  1531.    
  1532.     this.metadb_changed = function() {
  1533.         if (!p.metadb) return false;
  1534.         switch(this.mode) {
  1535.             case "last.fm":
  1536.                 p.artist = p.eval(p.artist_tf);
  1537.                 if (this.artist == p.artist) return false;
  1538.                 this.artist = p.artist;
  1539.                 this.folder = p.data_folder + p.eval("$crc32(" + p.artist_tf + ")");
  1540.                 if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
  1541.                 break;
  1542.             case "custom":
  1543.                 this.temp_folder = p.eval(this.custom_folder_tf);
  1544.                 if (this.temp_folder == this.folder) return false;
  1545.                 this.folder = this.temp_folder;
  1546.                 break;
  1547.         }
  1548.         this.update();
  1549.         return true;
  1550.     }
  1551.    
  1552.     this.trace = function(x, y) {
  1553.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  1554.     }
  1555.    
  1556.     this.wheel = function(step) {
  1557.         if (!p.metadb || this.images.length < 2 || !this.trace(p.mx, p.my) || (typeof th == "object" && th.mode == "grid" && !th.overlay)) return false;
  1558.         this.index -= step;
  1559.         if (this.index < 0) this.index = this.images.length - 1;
  1560.         if (this.index >= this.images.length) this.index = 0;
  1561.         window.RepaintRect(this.x, this.y, this.w, this.h);
  1562.         return true;
  1563.     }
  1564.    
  1565.     this.lbtn_dblclk = function(x, y) {
  1566.         if (!this.trace(x, y)) return false;
  1567.         p.run("\"" + this.files[this.index] + "\"");
  1568.         return true;
  1569.     }
  1570.    
  1571.     this.download = function() {
  1572.         window.Repaint();
  1573.         if (p.artist == "" || p.artist == "?") return;
  1574.         p.WshShell.Run('"' + p.script_path + 'art.exe" "' + p.artist + '" "' + this.folder + '" ' + this.limit, 0, true);
  1575.         this.update();
  1576.         window.NotifyOthers("images", "update");
  1577.     }
  1578.    
  1579.     this.update = function() {
  1580.         this.index = 0;
  1581.         for (i = 0; i < this.images.length; i++) {
  1582.             try { this.images[i].Dispose(); } catch(e) {}
  1583.         }
  1584.         this.folders = this.folder.split("|");
  1585.         this.files = [];
  1586.         for (i = 0; i < this.folders.length; i++) {
  1587.             if (p.fso.FolderExists(this.folders[i])) this.files = this.files.concat(utils.Glob(this.folders[i] + "\\*.jpg").toArray(), utils.Glob(this.folders[i] + "\\*.jpeg").toArray(), utils.Glob(this.folders[i] + "\\*.png").toArray(), utils.Glob(this.folders[i] + "\\*.gif").toArray());
  1588.         }
  1589.         this.images = [];
  1590.         for (i = 0; i < this.files.length; i++) {
  1591.             this.images[i] = gdi.Image(this.files[i]);
  1592.         }
  1593.         if (typeof th == "object") {
  1594.             th.nc = true;
  1595.             th.calc();
  1596.         }
  1597.         window.Repaint();
  1598.     }
  1599.    
  1600.     this.delete_image = function() {
  1601.         p.app.Namespace(10).MoveHere(this.files[this.index]);
  1602.         this.update();
  1603.     }
  1604.    
  1605.     this.x = x;
  1606.     this.y = y;
  1607.     this.w = w;
  1608.     this.h = h;
  1609.     this.files = [];
  1610.     this.images = [];
  1611.     this.index = 0;
  1612.     this.artist = "";
  1613.     this.folder = "";
  1614.     this.limit = window.GetProperty("image_limit", 5);
  1615.     this.cycle = window.GetProperty("image_cycle", 0);
  1616.     this.mode = window.GetProperty("image_mode", "last.fm");
  1617.     this.type = window.GetProperty("image_type", "crop top");
  1618.     this.auto_download = window.GetProperty("image_auto_download", "all");
  1619.     this.custom_folder_tf = window.GetProperty("image_custom_folder_tf", "$directory_path(%path%)");
  1620. }
  1621.  
  1622. function lastfm() {
  1623.     this.notify_data = function(name, data) {
  1624.         if (name == "lastfm" && data == "update") {
  1625.             this.username = p.open(this.username_file).trim();
  1626.             this.sk = p.open(this.sk_file).trim();
  1627.             if (p.check_feature("lastfm_charts")) li.update();
  1628.             if (typeof ps == "object") {
  1629.                 ps.loved_working = false;
  1630.                 ps.playcount_working = false;
  1631.                 b.update();
  1632.                 on_item_focus_change();
  1633.             }
  1634.             if (p.check_feature("lastfm")) {
  1635.                 li.artist = "";
  1636.                 on_item_focus_change();
  1637.             }
  1638.             if (p.check_feature("lastfm_album")) {
  1639.                 t.artist = "";
  1640.                 t.album = "";
  1641.                 on_item_focus_change();
  1642.             }
  1643.             window.Repaint();
  1644.         }
  1645.     }
  1646.    
  1647.     this.post = function(method, metadb) {
  1648.         switch(method) {
  1649.             case "auth.getMobileSession":
  1650.                 var func = function() {
  1651.                     var json_data = p.json(l.xmlhttp.responsetext);
  1652.                     if (!json_data) return;
  1653.                     if (json_data.error) {
  1654.                         p.MsgBox(json_data.message, 0, p.name);
  1655.                     } else if (json_data.session) {
  1656.                         p.save(json_data.session.key, l.sk_file);
  1657.                         window.NotifyOthers("lastfm", "update");
  1658.                         l.notify_data("lastfm", "update");
  1659.                     }
  1660.                 }
  1661.                
  1662.                 this.authToken = hex_md5(this.username + hex_md5(this.password));
  1663.                 this.api_sig = hex_md5("api_key" + this.api_key + "authToken" + this.authToken + "method" + method + "username" + this.username + this.secret);
  1664.                 this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&authToken=" + this.authToken + "&username=" + this.username;
  1665.                 break;
  1666.             case "track.love":
  1667.             case "track.unlove":
  1668.                 var func = function() {
  1669.                     var json_data = p.json(l.xmlhttp.responsetext);
  1670.                     if (!json_data) return;
  1671.                     if (json_data.error) {
  1672.                         p.console(json_data.message);
  1673.                     } else if (json_data.status && json_data.status == "ok") {
  1674.                         p.console("Track " + (method == "track.love" ? "loved successfully." : "unloved successfully."));
  1675.                         fb.RunContextCommandWithMetadb("Customdb Love " + (method == "track.love" ? 1 : 0), metadb, 8);
  1676.                     }
  1677.                 }
  1678.                
  1679.                 if (!metadb || this.username.length == 0 || this.sk.length != 32) return;
  1680.                 this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(metadb);
  1681.                 this.track = fb.TitleFormat("%title%").EvalWithMetadb(metadb);
  1682.                 if (this.artist == "" || this.artist == "?" || this.track == "?") return;
  1683.                 p.console("Attempting to " + (method == "track.love" ? "love \"" : "unlove \"") + this.track + "\" by \"" + this.artist + "\"");
  1684.                 p.console("Contacting Last.fm....");
  1685.                 this.api_sig = hex_md5("api_key" + this.api_key + "artist" + this.artist + "method" + method + "sk" + this.sk + "track" + this.track + this.secret);
  1686.                 this.data = "method=" + method + "&api_key=" + this.api_key + "&api_sig=" + this.api_sig + "&format=json&sk=" + this.sk + "&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track);
  1687.                 break;
  1688.             default:
  1689.                 return;
  1690.         }
  1691.        
  1692.         this.xmlhttp.open("POST", "https://ws.audioscrobbler.com/2.0/", true);
  1693.         this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  1694.         this.xmlhttp.setRequestHeader("User-Agent", this.user_agent);
  1695.         this.xmlhttp.send(this.data);
  1696.         this.xmlhttp.onreadystatechange = function() {
  1697.             if (l.xmlhttp.readyState == 4) {
  1698.                 if (l.xmlhttp.status == 200) {
  1699.                     func();
  1700.                 } else {
  1701.                     p.console(l.xmlhttp.responsetext || "HTTP error: " + l.xmlhttp.status);
  1702.                 }
  1703.             }
  1704.         }
  1705.     }
  1706.    
  1707.     this.update_username = function() {
  1708.         var old_username = this.username;
  1709.         this.username = p.InputBox("Enter your Last.fm username.", p.name, this.username);
  1710.         if (this.username.length > 0 && this.username != old_username) p.save("", this.sk_file);
  1711.         p.save(this.username, this.username_file);
  1712.         window.NotifyOthers("lastfm", "update");
  1713.         this.notify_data("lastfm", "update");
  1714.     }
  1715.    
  1716.     this.update_password = function() {
  1717.         this.password = p.InputBox("Enter your Last.fm password\n\nThis is only required to love/unlove tracks.", p.name, "");
  1718.         if (this.password.length > 0) {
  1719.             this.sk = "";
  1720.             p.save(this.sk, this.sk_file);
  1721.             window.NotifyOthers("lastfm", "update");
  1722.             this.notify_data("lastfm", "update");
  1723.             this.post("auth.getMobileSession");
  1724.         }
  1725.     }
  1726.    
  1727.     this.get_url = function() {
  1728.         return "http://ws.audioscrobbler.com/2.0/?format=json&api_key=" + this.api_key + "&user=" + this.username + "&username=" + this.username + "&s=" + Math.random();
  1729.     }
  1730.    
  1731.     this.username_error = "Use the right click menu to set your Last.fm username.";
  1732.     this.password_error = "Use the right click menu to set your Last.fm password.";
  1733.     this.url = "http://www.last.fm/";
  1734.     this.api_key = "56d9e050cc2d6b36102c8b4a5fe6152d";
  1735.     this.secret = "9f1f4346ce3ba206390074ff8cb4c6ce";
  1736.     this.user_agent = "foobar2000_wsh_panel_mod_scripts";
  1737.     this.username_file = p.settings_folder + "username";
  1738.     this.username = p.open(this.username_file).trim();
  1739.     this.sk_file = p.settings_folder + "sk";
  1740.     this.sk = p.open(this.sk_file).trim();
  1741.     this.auto_correct = window.GetProperty("lastfm_auto_correct", true);
  1742.     this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1743. }
  1744.  
  1745. function list(x, y, w, h) {
  1746.     this.size = function() {
  1747.         this.row_height = this.mode == "echonest" ? 90 : 20;
  1748.         this.rows = Math.floor((this.h - (this.mode == "echonest" ? 50 : 30)) / this.row_height);
  1749.         this.index = 0;
  1750.         this.offset = 0;
  1751.         switch(true) {
  1752.             case this.mode == "lastfm_charts":
  1753.                 this.text_width = Math.round(this.w / 3);
  1754.                 this.lastfm_charts_bar_x = this.text_width + 30;
  1755.                 break;
  1756.             case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases":
  1757.                 this.text_width = this.w - 120;
  1758.                 break;
  1759.             default:
  1760.                 this.text_width = this.w - 50;
  1761.                 break;
  1762.         }
  1763.         this.but_x = this.x + Math.round((this.w - 15) / 2);
  1764.         this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "li.offset > 0", function() { li.wheel(1); });
  1765.         this.down_btn = new sb(this.but_x, this.y + this.h - 15, 15, 15, p.down_img, "li.offset < li.items - li.rows", function() { li.wheel(-1); });
  1766.     }
  1767.    
  1768.     this.draw = function(gr) {
  1769.         switch(this.mode) {
  1770.             case "discogs":
  1771.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1772.                     p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, 20);
  1773.                     p.right_text(gr, this.dates[i + this.offset], p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, 20);
  1774.                 }
  1775.                 break;
  1776.             case "lastfm_charts":
  1777.                 var max_bar_width = (this.w - this.lastfm_charts_bar_x - 40) / this.playcounts[0];
  1778.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1779.                     p.right_text(gr, this.ranks[i + this.offset] + ".", p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), 17, 20);
  1780.                     var bar_width = max_bar_width * this.playcounts[i + this.offset];
  1781.                     var bar_colour = p.splitRGB(this.lastfm_charts_bar_colour);
  1782.                     gr.FillSolidRect(this.lastfm_charts_bar_x + this.x, this.y + 16 + (i * this.row_height), bar_width, 18, bar_colour);
  1783.                     p.left_text(gr, this.playcounts[i + this.offset].addCommas(), p.list_font, p.textcolour, this.x + 5 + this.lastfm_charts_bar_x + bar_width, this.y + 15 + (i * this.row_height), 50, 20);
  1784.                     p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, 20);
  1785.                 }
  1786.                 break;
  1787.             case "lastfm":
  1788.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1789.                     if (this.lastfm_mode == 0) p.draw_image(gr, this.lastfm_button == "spotify" ? this.lastfm_spotify_img : this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1790.                     if (this.lastfm_mode == 1 || this.lastfm_mode == 3 || this.lastfm_mode == 4) p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1791.                     p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, 20);
  1792.                 }
  1793.                 break;
  1794.             case "musicbrainz":
  1795.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1796.                     if (this.musicbrainz_mode == "URLs") p.draw_image(gr, this.musicbrainz_images[this.images[i + this.offset]], this.x, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1797.                     if (this.musicbrainz_mode == "releases") {
  1798.                         p.draw_image(gr, this.autoplaylist_img, this.x, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1799.                         if (this.musicbrainz_show_release_type) p.right_text(gr, this.release_types[i + this.offset], p.list_font, p.textcolour, this.x, this.y + 15 + (i * this.row_height), this.w - 30, 20);
  1800.                         p.right_text(gr, this.dates[i + this.offset], p.list_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, 20);
  1801.                     }
  1802.                     p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x + this.text_x, this.y + 15 + (i * this.row_height), this.text_width, 20);
  1803.                 }
  1804.                 break;
  1805.             case "autoplaylists":
  1806.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1807.                     p.left_text(gr, this.names[i + this.offset], p.list_font, p.textcolour, this.x, this.y + 15 + (i * this.row_height), this.text_width, 20);
  1808.                     if (!this.autoplaylists_editing && this.autoplaylists_hover && this.index == i + this.offset) {
  1809.                         p.draw_image(gr, this.autoplaylists_edit_img, this.x + this.w - 40, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1810.                         p.draw_image(gr, this.autoplaylists_del_img, this.x + this.w - 20, this.y + 16 + (i * this.row_height), 16, 16, "centre");
  1811.                     }
  1812.                 }
  1813.                 break;
  1814.             case "echonest":
  1815.                 for (i = 0; i < Math.min(this.items, this.rows); i++) {
  1816.                     p.left_text(gr, this.names[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w - 110, 24);
  1817.                     p.right_text(gr, this.dates[i + this.offset], p.title_font, p.textcolour_hl, this.x, this.y + 15 + (i * this.row_height), this.w, 24);
  1818.                     gr.GdiDrawText(this.summaries[i + this.offset], p.normal_font, p.textcolour, this.x, this.y + 37 + (i * this.row_height), this.w, p.normal_font.Height * Math.floor(64 / p.normal_font.Height), DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  1819.                 }
  1820.                 break;
  1821.         }
  1822.         this.up_btn.draw(gr);
  1823.         this.down_btn.draw(gr);
  1824.         if (this.show_timestamp) p.left_text(gr, this.date, p.list_font, p.textcolour_hl, this.x, this.y + this.h - 15, this.w, 15);
  1825.     }
  1826.    
  1827.     this.metadb_changed = function() {
  1828.         p.artist = p.eval(p.artist_tf);
  1829.         if (this.artist == p.artist) return false;
  1830.         this.artist = p.artist;
  1831.         this.folder = p.data_folder + p.eval("$crc32(" + p.artist_tf + ")");
  1832.         if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
  1833.         this.update();
  1834.         return true;
  1835.     }
  1836.    
  1837.     this.trace = function(x, y) {
  1838.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  1839.     }
  1840.    
  1841.     this.wheel = function(step) {
  1842.         if (!this.trace(p.mx, p.my)) return false;
  1843.         if (this.items > this.rows) {
  1844.             this.offset -= step * (this.mode == "echonest" ? 1 : 3);
  1845.             if (this.offset < 0) this.offset = 0;
  1846.             if (this.rows + this.offset > this.items) this.offset = this.items - this.rows;
  1847.             window.RepaintRect(this.x, this.y, this.w, this.h);
  1848.         }
  1849.         return true;
  1850.     }
  1851.    
  1852.     this.move = function(x, y) {
  1853.         this.index = Math.floor((y - this.y - 15) / this.row_height) + this.offset;
  1854.         this.in_range = this.index >= this.offset && this.index < this.offset + Math.min(this.rows, this.items);
  1855.         switch(true) {
  1856.             case !this.trace(x, y):
  1857.                 window.SetCursor(IDC_ARROW);
  1858.                 p.ttd();
  1859.                 return false;
  1860.             case this.mode == "autoplaylists" && this.autoplaylists_editing:
  1861.             case this.mode == "lastfm" && l.username.length == 0:
  1862.             case !this.in_range:
  1863.                 window.SetCursor(IDC_ARROW);
  1864.                 this.leave();
  1865.                 break;
  1866.             case this.up_btn.trace(x, y):
  1867.             case this.down_btn.trace(x, y):
  1868.                 window.SetCursor(IDC_HAND);
  1869.                 break;
  1870.             case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
  1871.             case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
  1872.                 window.SetCursor(IDC_HAND);
  1873.                 switch(true) {
  1874.                     case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
  1875.                         p.tt('spotify:search:"' + this.names[this.index].replace(/\s+/g,"+") + '"');
  1876.                         break;
  1877.                     default:
  1878.                         p.tt("Autoplaylist: " + this.queries[this.index]);
  1879.                         break;
  1880.                 }
  1881.                 break;
  1882.             case this.mode == "autoplaylists":
  1883.                 switch(true) {
  1884.                     case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
  1885.                         window.SetCursor(IDC_HAND);
  1886.                         p.tt('Run "' + this.names[this.index] + '"');
  1887.                         break;
  1888.                     case x > this.x + this.w - 40 && x < this.x + this.w - 20:
  1889.                         window.SetCursor(IDC_HAND);
  1890.                         p.tt('Edit "' + this.names[this.index] + '"');
  1891.                         break;
  1892.                     case x > this.x + this.w - 20 && x < this.x + this.w:
  1893.                         window.SetCursor(IDC_HAND);
  1894.                         p.tt('Delete "' + this.names[this.index] + '"');
  1895.                         break;
  1896.                     default:
  1897.                         window.SetCursor(IDC_ARROW);
  1898.                         this.leave();
  1899.                         break;
  1900.                 }
  1901.                 this.autoplaylists_hover = true;
  1902.                 window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
  1903.                 break;
  1904.             case this.mode == "echonest":
  1905.             case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
  1906.                 window.SetCursor(IDC_HAND);
  1907.                 p.tt(this.urls[this.index]);
  1908.                 break;
  1909.             default:
  1910.                 window.SetCursor(IDC_ARROW);
  1911.                 p.ttd();
  1912.                 break;
  1913.         }
  1914.         return true;
  1915.     }
  1916.    
  1917.     this.lbtn_up = function(x, y) {
  1918.         if (!this.trace(x, y)) return false;
  1919.         switch(true) {
  1920.             case this.mode == "autoplaylists" && this.autoplaylists_editing:
  1921.             case this.mode == "lastfm" && l.username.length == 0:
  1922.             case !this.in_range:
  1923.             case this.up_btn.lbtn_up(x, y):
  1924.             case this.down_btn.lbtn_up(x, y):
  1925.                 break;
  1926.             case this.mode == "musicbrainz" && this.musicbrainz_mode == "releases" && x > this.x && x < this.x + 20:
  1927.             case this.mode == "lastfm" && this.text_x == 20 && x > this.x && x < this.x + 20:
  1928.                 switch(true) {
  1929.                     case this.lastfm_mode == 0 && this.lastfm_button == "spotify":
  1930.                         if (p.run('spotify:search:"' + this.names[this.index].replace(/\s+/g,"+") + '"')) {
  1931.                             if (fb.IsPlaying && !fb.IsPaused && this.lastfm_pause) fb.Pause();
  1932.                         } else {
  1933.                             p.MsgBox("Unable to launch Spotify.", 0, p.name);
  1934.                         }
  1935.                         break;
  1936.                     default:
  1937.                         fb.CreateAutoPlaylist(fb.PlaylistCount, this.names[this.index], this.queries[this.index]);
  1938.                         fb.ActivePlaylist = fb.PlaylistCount - 1;
  1939.                         break;
  1940.                 }
  1941.                 break;
  1942.             case this.mode == "autoplaylists":
  1943.                 switch(true) {
  1944.                     case x > this.x && x < this.x + Math.min(this.names_widths[this.index], this.text_width):
  1945.                         this.autoplaylists_run(this.names[this.index], this.queries[this.index], this.sorts[this.index], this.forced[this.index]);
  1946.                         break;
  1947.                     case x > this.x + this.w - 40 && x < this.x + this.w - 20:
  1948.                         this.autoplaylists_edit(x, y);
  1949.                         break;
  1950.                     case x > this.x + this.w - 20 && x < this.x + this.w:
  1951.                         this.autoplaylists_delete();
  1952.                         break
  1953.                 }
  1954.                 break;
  1955.             case this.mode == "echonest":
  1956.             case x > this.x + this.text_x && x < this.x + this.text_x + Math.min(this.names_widths[this.index], this.text_width):
  1957.                 p.browser(this.urls[this.index]);
  1958.                 break;
  1959.         }
  1960.         return true;
  1961.     }
  1962.    
  1963.     this.leave = function() {
  1964.         p.ttd();
  1965.         if (this.mode != "autoplaylists") return;
  1966.         this.autoplaylists_hover = false;
  1967.         window.RepaintRect(this.x, this.y, this.w, this.h);
  1968.     }
  1969.    
  1970.     this.update = function() {
  1971.         this.items = 0;
  1972.         this.offset = 0;
  1973.         this.index = 0;
  1974.         this.names = [];
  1975.         this.names_widths = [];
  1976.         this.urls = [];
  1977.         this.dates = [];
  1978.         this.queries = [];
  1979.         this.ranks = [];
  1980.         this.playcounts = [];
  1981.         this.sorts = [];
  1982.         this.summaries = [];
  1983.         this.release_types = [];
  1984.         this.images = [];
  1985.         this.forced = [];
  1986.         this.data = [];
  1987.         this.file = null;
  1988.         this.date = "";
  1989.         var temp_bmp = gdi.CreateImage(1, 1);
  1990.         var temp_gr = temp_bmp.GetGraphics();
  1991.         switch(this.mode) {
  1992.             case "autoplaylists":
  1993.                 this.text = p.open(this.filename);
  1994.                 this.data = this.text.split(/\r?\n/g);
  1995.                 this.items = this.data.length;
  1996.                 for (i = 0; i < this.items; i++) {
  1997.                     var temp = this.data[i].split("¬");
  1998.                     this.names[i] = temp[0];
  1999.                     this.queries[i] = temp[1];
  2000.                     this.sorts[i] = temp[2];
  2001.                     this.forced[i] = temp[3];
  2002.                     this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2003.                 }
  2004.                 break;
  2005.             case "lastfm":
  2006.                 this.text_x = 20;
  2007.                 this.filename = this.folder + "\\" + this.lastfm_methods[this.lastfm_mode] + ".json";
  2008.                 if (p.fso.fileExists(this.filename)) {
  2009.                     this.file = p.fso.Getfile(this.filename);
  2010.                     this.json_text = p.open(this.filename);
  2011.                     this.json_data = p.json(this.json_text);
  2012.                     if (this.json_data) {
  2013.                         switch(true) {
  2014.                             case this.json_data.error > 0:
  2015.                                 p.console(this.json_data.message);
  2016.                                 break;
  2017.                             case this.lastfm_mode == 0 && this.json_data.similarartists && typeof this.json_data.similarartists.artist == "object":
  2018.                                 this.data = this.json_data.similarartists.artist;
  2019.                                 break;
  2020.                             case this.lastfm_mode == 1 && this.json_data.toptags && typeof this.json_data.toptags.tag == "object":
  2021.                                 this.data = this.json_data.toptags.tag;
  2022.                                 break;
  2023.                             case this.lastfm_mode == 2 && this.json_data.topfans && typeof this.json_data.topfans.user == "object":
  2024.                                 this.text_x = 0;
  2025.                                 this.data = this.json_data.topfans.user;
  2026.                                 break;
  2027.                             case this.lastfm_mode == 3 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
  2028.                                 this.data = this.json_data.topalbums.album;
  2029.                                 break;
  2030.                             case this.lastfm_mode == 4 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
  2031.                                 this.data = this.json_data.toptracks.track;
  2032.                                 break;
  2033.                         }
  2034.                         this.items = this.data.length;
  2035.                         for (i = 0; i < this.items; i++) {
  2036.                             this.names[i] = this.data[i].name;
  2037.                             this.urls[i] = this.data[i].url;
  2038.                             this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2039.                             if (this.lastfm_mode == 0) this.queries[i] = "artist HAS " + this.names[i];
  2040.                             if (this.lastfm_mode == 1) this.queries[i] = "genre HAS " + this.names[i];
  2041.                             if (this.lastfm_mode == 3) this.queries[i] = "album HAS " + this.names[i] + " OR title HAS " + this.names[i];
  2042.                             if (this.lastfm_mode == 4) this.queries[i] = "title HAS " + this.names[i];
  2043.                         }
  2044.                     }
  2045.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
  2046.                 } else {
  2047.                     this.get();
  2048.                 }
  2049.                 break;
  2050.             case "lastfm_charts":
  2051.                 this.filename = this.folder + "\\" + l.username + "_" + this.lastfm_charts_modes[this.lastfm_charts_mode] + "_" + this.lastfm_charts_periods[this.lastfm_charts_period] + ".json";
  2052.                 if (p.fso.fileExists(this.filename)) {
  2053.                     this.file = p.fso.Getfile(this.filename);
  2054.                     this.json_text = p.open(this.filename);
  2055.                     this.json_data = p.json(this.json_text);
  2056.                     if (this.json_data) {
  2057.                         switch(true) {
  2058.                             case this.json_data.error > 0:
  2059.                                 p.console(this.json_data.message);
  2060.                                 break;
  2061.                             case this.lastfm_charts_mode == 0 && this.json_data.topartists && typeof this.json_data.topartists.artist == "object":
  2062.                                 this.data = this.json_data.topartists.artist;
  2063.                                 break;
  2064.                             case this.lastfm_charts_mode == 1 && this.json_data.topalbums && typeof this.json_data.topalbums.album == "object":
  2065.                                 this.data = this.json_data.topalbums.album;
  2066.                                 break;
  2067.                             case this.lastfm_charts_mode == 2 && this.json_data.toptracks && typeof this.json_data.toptracks.track == "object":
  2068.                                 this.data = this.json_data.toptracks.track;
  2069.                                 break;
  2070.                         }
  2071.                         this.items = this.data.length;
  2072.                         for (i = 0; i < this.items; i++) {
  2073.                             this.names[i] = this.lastfm_charts_mode != 0 ? this.data[i].artist.name + " - " + this.data[i].name : this.data[i].name;
  2074.                             this.ranks[i] = (i > 0 && this.data[i].playcount == this.data[i - 1].playcount) ? this.ranks[i - 1] : this.data[i]["@attr"].rank;
  2075.                             this.urls[i] = this.data[i].url;
  2076.                             this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2077.                             this.playcounts[i] = this.data[i].playcount;
  2078.                         }
  2079.                     }
  2080.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
  2081.                 } else {
  2082.                     this.get();
  2083.                 }
  2084.                 break;
  2085.             case "discogs":
  2086.                 this.filename = this.folder + "\\discogs.json";
  2087.                 if (p.fso.fileExists(this.filename)) {
  2088.                     this.file = p.fso.Getfile(this.filename);
  2089.                     this.json_text = p.open(this.filename);
  2090.                     this.json_data = p.json(this.json_text);
  2091.                     if (this.json_data && this.json_data.results) {
  2092.                         this.data = p.json_reverse_sort(this.json_data.results, "year");
  2093.                         var swap_artist = fb.TitleFormat("$swapprefix($lower(" + p.artist + ")) - ").Eval(true);
  2094.                         for (i = 0; i < this.data.length; i++) {
  2095.                             var temp_artist = this.data[i].title.replace(/\s{2,}/g,' ');
  2096.                             if (this.discogs_match && temp_artist.toLowerCase().indexOf(swap_artist) != 0) continue;
  2097.                             this.dates.push(this.data[i].year || "");
  2098.                             this.urls.push("http://www.discogs.com" + this.data[i].uri);
  2099.                             this.names.push(temp_artist);
  2100.                             this.names_widths.push(temp_gr.CalcTextWidth(temp_artist, p.list_font));
  2101.                         }
  2102.                         this.items = this.names.length;
  2103.                     }
  2104.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_WEEK) this.get();
  2105.                 } else {
  2106.                     this.get();
  2107.                 }
  2108.                 break;
  2109.             case "musicbrainz":
  2110.                 this.filename = this.folder + "\\musicbrainz_" + this.musicbrainz_mode + ".json";
  2111.                 if (p.fso.fileExists(this.filename)) {
  2112.                     this.file = p.fso.Getfile(this.filename);
  2113.                     this.json_text = p.open(this.filename);
  2114.                     this.json_data = p.json(this.json_text);
  2115.                     if (this.json_data) {
  2116.                         switch(this.musicbrainz_mode) {
  2117.                             case "releases":
  2118.                                 this.data = this.json_data["release-groups"] || [];
  2119.                                 this.data = p.json_reverse_sort(this.data, "first-release-date");
  2120.                                 for (i = 0; i < this.data.length; i++) {
  2121.                                     switch(true) {
  2122.                                         case !this.musicbrainz_live && this.data[i]["secondary-types"].join("").toLowerCase().indexOf("live") > -1:
  2123.                                             break;
  2124.                                         case this.musicbrainz_single && this.data[i]["primary-type"] == "Single":
  2125.                                         case this.musicbrainz_ep && this.data[i]["primary-type"] == "EP":
  2126.                                         case this.musicbrainz_album && this.data[i]["primary-type"] == "Album":
  2127.                                             var name = this.data[i].title;
  2128.                                             this.dates.push(this.data[i]["first-release-date"].substring(0,4));
  2129.                                             this.names.push(name);
  2130.                                             this.urls.push("http://musicbrainz.org/release-group/" + this.data[i].id);
  2131.                                             this.release_types.push(this.data[i]["primary-type"]);
  2132.                                             this.names_widths.push(temp_gr.CalcTextWidth(name, p.list_font));
  2133.                                             this.queries.push("album HAS " + name + " OR title HAS " + name);
  2134.                                             break;
  2135.                                     }
  2136.                                 }
  2137.                                 this.items = this.names.length;
  2138.                                 break;
  2139.                             case "URLs":
  2140.                                 this.data = this.json_data.relations || [];
  2141.                                 this.items = this.data.length;
  2142.                                 for (i = 0; i < this.items; i++) {
  2143.                                     this.urls[i] = this.data[i].url.resource;
  2144.                                     this.images[i] = "";
  2145.                                     if (this.data[i].type == "official homepage") {
  2146.                                         this.images[i] = "home";
  2147.                                     } else {
  2148.                                         for (name in this.musicbrainz_images) {
  2149.                                             if (this.urls[i].indexOf(name) > -1) {
  2150.                                                 this.images[i] = name;
  2151.                                                 break;
  2152.                                             }
  2153.                                         }
  2154.                                         if (this.images[i].length == 0) this.images[i] = "external";
  2155.                                     }
  2156.                                     this.names[i] = decodeURIComponent(this.urls[i]);
  2157.                                     this.names_widths[i] = temp_gr.CalcTextWidth(this.names[i], p.list_font);
  2158.                                 }
  2159.                                 break;
  2160.                         }
  2161.                     }
  2162.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_WEEK) this.get();
  2163.                 } else {
  2164.                     this.get();
  2165.                 }
  2166.                 break;
  2167.             case "echonest":
  2168.                 this.filename = this.folder + "\\echonest_" + this.echonest_modes[this.echonest_mode] + ".json";
  2169.                 if (p.fso.fileExists(this.filename)) {
  2170.                     this.file = p.fso.Getfile(this.filename);
  2171.                     this.json_text = p.open(this.filename);
  2172.                     this.json_data = p.json(this.json_text);
  2173.                     if (this.json_data && this.json_data.response && this.json_data.response.status) {
  2174.                         if (this.json_data.response.status.code == 0) {
  2175.                             this.data = this.json_data.response[this.echonest_modes[this.echonest_mode]] || [];
  2176.                             this.items = this.data.length;
  2177.                             for (i = 0; i < this.items; i++) {
  2178.                                 this.names[i] = p.strip_tags(this.data[i].name);
  2179.                                 this.urls[i] = (this.data[i].url || "").replace(/\\/g,"");
  2180.                                 this.temp_date = (this.data[i].date_posted || this.data[i].date_reviewed || this.data[i].date_found || "").substring(0, 10);
  2181.                                 this.dates[i] = this.temp_date.substring(8,10) + "-" + this.temp_date.substring(5,7) + "-" + this.temp_date.substring(0,4);
  2182.                                 this.summaries[i] = p.strip_tags(this.data[i].summary);
  2183.                             }
  2184.                         } else {
  2185.                             p.console(this.json_data.response.status.message);
  2186.                         }
  2187.                     }
  2188.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_DAY) this.get();
  2189.                 } else {
  2190.                     this.get();
  2191.                 }
  2192.                 break;
  2193.         }
  2194.         temp_bmp.ReleaseGraphics(temp_gr);
  2195.         temp_bmp.Dispose();
  2196.         temp_gr = null;
  2197.         temp_bmp = null;
  2198.         if (this.file) {
  2199.             var temp_date = new Date(this.file.DateLastModified);
  2200.             this.date = "Updated: " + temp_date.toLocaleTimeString() + ", " + temp_date.toLocaleDateString();
  2201.         }
  2202.         window.Repaint();
  2203.     }
  2204.    
  2205.     this.get = function() {
  2206.         var fn = this.filename;
  2207.         var func = function() {
  2208.             if (!p.save(li.xmlhttp.responsetext, fn)) return;
  2209.             li.update();
  2210.         }
  2211.         var url = "";
  2212.         var user_agent = "";
  2213.         switch(this.mode) {
  2214.             case "discogs":
  2215.                 if (this.artist == "" || this.artist == "?") return;
  2216.                 url = "http://api.discogs.com/database/search?per_page=100&type=master&artist=" + encodeURIComponent(this.artist);
  2217.                 user_agent = "foobar2000_wsh_panel_mod_discogs +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
  2218.                 break;
  2219.             case "lastfm_charts":
  2220.                 if (l.username.length == 0) return(p.console(l.username_error));
  2221.                 url = l.get_url() + "&method=user." + this.lastfm_charts_methods[this.lastfm_charts_mode] + "&period=" + this.lastfm_charts_periods[this.lastfm_charts_period];
  2222.                 user_agent = l.user_agent;
  2223.                 break;
  2224.             case "lastfm":
  2225.                 if (this.artist == "" || this.artist == "?") return;
  2226.                 if (l.username.length == 0) return(p.console(l.username_error));
  2227.                 url = l.get_url() + "&method=" + this.lastfm_methods[this.lastfm_mode] + "&artist=" + encodeURIComponent(this.artist) + "&autocorrect=" + (l.auto_correct ? 1 : 0);
  2228.                 user_agent = l.user_agent;
  2229.                 break;
  2230.             case "musicbrainz":
  2231.                 user_agent = "foobar2000_wsh_panel_mod_musicbrainz +http://www.hydrogenaudio.org/forums/index.php?showuser=19379";
  2232.                 var fn1 = this.folder + "\\MUSICBRAINZ_ARTISTID.txt";
  2233.                 this.musicbrainz_id = p.eval("$if3(%musicbrainz_artistid%,%musicbrainz artist id%,)");
  2234.                 if (this.musicbrainz_id.length == 0) this.musicbrainz_id = p.open(fn1);
  2235.                 if (this.musicbrainz_id.length == 0) {
  2236.                     if (this.artist == "" || this.artist == "?") return;
  2237.                     url = "http://search.musicbrainz.org/ws/2/artist/?query=artist:" + encodeURIComponent(this.artist.toLowerCase()) + "&fmt=json";
  2238.                     var func = function() {
  2239.                         var json_data = p.json(li.xmlhttp.responsetext);
  2240.                         if (!json_data) return;
  2241.                         var artists = json_data["artist-list"].artist || [];
  2242.                         for (i = 0; i < artists.length; i++) {
  2243.                             if (li.artist.toLowerCase() == artists[i].name.toLowerCase()) {
  2244.                                 if (!p.save(artists[i].id, fn1)) return;
  2245.                                 li.get();
  2246.                                 break;
  2247.                             }
  2248.                         }
  2249.                     }
  2250.                 } else {
  2251.                     if (this.musicbrainz_mode == "releases") url = "http://www.musicbrainz.org/ws/2/release-group?artist=" + this.musicbrainz_id + "&limit=100&offset=0&fmt=json";
  2252.                     else url = "http://www.musicbrainz.org/ws/2/artist/" + this.musicbrainz_id + "?inc=url-rels&fmt=json";
  2253.                 }
  2254.                 break;
  2255.             case "echonest":
  2256.                 if (this.artist == "" || this.artist == "?") return;
  2257.                 url = "http://developer.echonest.com/api/v4/artist/" + this.echonest_modes[this.echonest_mode] + "/?name=" + encodeURIComponent(this.artist) + "&api_key=EKWS4ESQLKN3G2ZWV";
  2258.                 break;
  2259.         }
  2260.         if (url.length == 0) return;
  2261.         this.xmlhttp.open("GET", url, true);
  2262.         if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
  2263.         this.xmlhttp.send();
  2264.         this.xmlhttp.onreadystatechange = function() {
  2265.             if (li.xmlhttp.readyState == 4) {
  2266.                 if (li.xmlhttp.status == 200) {
  2267.                     func();
  2268.                 } else {
  2269.                     p.console(li.xmlhttp.responsetext || "HTTP error: " + li.xmlhttp.status);
  2270.                 }
  2271.             }
  2272.         }
  2273.     }
  2274.    
  2275.     this.init = function() {
  2276.         switch(true) {
  2277.             case p.check_feature("discogs"):
  2278.                 this.mode = "discogs";
  2279.                 this.discogs_match = window.GetProperty("discogs_match", false);
  2280.                 break;
  2281.             case p.check_feature("lastfm_charts"):
  2282.                 this.mode = "lastfm_charts";
  2283.                 this.text_x = 20;
  2284.                 this.lastfm_charts_modes = ["artist", "album", "track"];
  2285.                 this.lastfm_charts_mode = window.GetProperty("lastfm_charts_mode", 0);
  2286.                 this.lastfm_charts_methods = ["getTopArtists", "getTopAlbums", "getTopTracks"];
  2287.                 this.lastfm_charts_periods_display = ["overall", "last 7 days", "1 month", "3 month", "6 month", "12 month"];
  2288.                 this.lastfm_charts_periods = ["overall", "7day", "1month", "3month", "6month", "12month"];
  2289.                 this.lastfm_charts_period = window.GetProperty("lastfm_charts_period", 0);
  2290.                 this.lastfm_charts_bar_colour = window.GetProperty("lastfm_charts_bar_colour", "72-127-221");
  2291.                 this.folder = p.data_folder + "charts";
  2292.                 if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
  2293.                 break;
  2294.             case p.check_feature("lastfm"):
  2295.                 this.mode = "lastfm";
  2296.                 this.lastfm_methods = ["artist.getSimilar", "artist.getTopTags", "artist.getTopFans", "artist.getTopAlbums", "artist.getTopTracks"];
  2297.                 this.lastfm_modes = ["similar artists", "top tags", "top fans", "top albums", "top tracks"];
  2298.                 this.lastfm_mode = window.GetProperty("lastfm_mode", 0);
  2299.                 this.lastfm_button = window.GetProperty("lastfm_button", "spotify");
  2300.                 this.lastfm_pause = window.GetProperty("lastfm_pause", true);
  2301.                 this.lastfm_spotify_img = gdi.Image(p.images_path + "spotify.png");
  2302.                 break;
  2303.             case p.check_feature("musicbrainz"):
  2304.                 this.mode = "musicbrainz";
  2305.                 this.text_x = 20;
  2306.                 this.musicbrainz_images = {
  2307.                     "viaf.org": gdi.Image(p.images_path + "viaf_small.png"),
  2308.                     "allmusic.com": gdi.Image(p.images_path + "allmusic_small.png"),
  2309.                     "external": gdi.Image(p.images_path + "external_small.png"),
  2310.                     "bbc.co.uk": gdi.Image(p.images_path + "bbc_small.png"),
  2311.                     "facebook.com": gdi.Image(p.images_path + "facebook_small.png"),
  2312.                     "home": gdi.Image(p.images_path + "home_small.png"),
  2313.                     "last.fm": gdi.Image(p.images_path + "lastfm_small.png"),
  2314.                     "twitter.com": gdi.Image(p.images_path + "twitter_small.png"),
  2315.                     "soundcloud.com": gdi.Image(p.images_path + "soundcloud_small.png"),
  2316.                     "wikipedia.org": gdi.Image(p.images_path + "wikipedia_small.png"),
  2317.                     "discogs.com": gdi.Image(p.images_path + "discogs_small.png"),
  2318.                     "myspace.com": gdi.Image(p.images_path + "myspace_small.png"),
  2319.                     "youtube.com": gdi.Image(p.images_path + "youtube_small.png"),
  2320.                     "imdb.com": gdi.Image(p.images_path + "imdb_small.png"),
  2321.                     "plus.google.com": gdi.Image(p.images_path + "google_plus_small.png"),
  2322.                     "lyrics.wikia.com": gdi.Image(p.images_path + "lyrics_wikia_small.png"),
  2323.                     "flickr.com": gdi.Image(p.images_path + "flickr_small.png"),
  2324.                     "vimeo.com": gdi.Image(p.images_path + "vimeo_small.png")
  2325.                 }
  2326.                 this.musicbrainz_mode = window.GetProperty("musicbrainz_mode", "releases");
  2327.                 this.musicbrainz_show_release_type = window.GetProperty("musicbrainz_show_release_type", true);
  2328.                 this.musicbrainz_live = window.GetProperty("musicbrainz_live", false);
  2329.                 this.musicbrainz_ep = window.GetProperty("musicbrainz_ep", true);
  2330.                 this.musicbrainz_single = window.GetProperty("musicbrainz_single", true);
  2331.                 this.musicbrainz_album = window.GetProperty("musicbrainz_album", true);
  2332.                 break;
  2333.             case p.check_feature("echonest"):
  2334.                 this.mode = "echonest";
  2335.                 this.echonest_modes = ["news", "reviews", "blogs"];
  2336.                 this.echonest_mode = window.GetProperty("echonest_mode", 0);
  2337.                 this.echonest_url = "http://the.echonest.com/";
  2338.                 break;
  2339.             case p.check_feature("autoplaylists"):
  2340.                 this.autoplaylists_add = function() {
  2341.                     if (this.autoplaylists_editing) return;
  2342.                     this.autoplaylists_editing = true;
  2343.                     var new_name = p.InputBox("Enter a name for your autoplaylist", p.name, "");
  2344.                     if (new_name == "") { this.autoplaylists_editing = false; return; }
  2345.                     var new_query = p.InputBox("Enter your autoplaylist query", p.name, "");
  2346.                     if (new_query == "") { this.autoplaylists_editing = false; return; }
  2347.                     var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, "");
  2348.                     var new_force = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
  2349.                     this.data.push(new_name + "¬" + new_query + "¬" + new_sort + "¬" + new_force);
  2350.                     if (this.data.length > this.rows) this.offset = this.data.length - this.rows;
  2351.                     p.save(this.data.join("\n"), this.filename);
  2352.                     if (this.autoplaylists_success) this.autoplaylists_run(new_name, new_query, new_sort, new_force);
  2353.                     window.NotifyOthers("autoplaylists", "update");
  2354.                     this.update();
  2355.                     this.autoplaylists_editing = false;
  2356.                 }
  2357.                
  2358.                 this.autoplaylists_run = function(n, q, s, f) {
  2359.                     if (this.autoplaylists_remove_duplicates) {
  2360.                         i = 0;
  2361.                         while(i < fb.PlaylistCount) {
  2362.                             if (fb.GetPlaylistName(i) == n) fb.RemovePlaylist(i);
  2363.                             else i++;
  2364.                         }
  2365.                     }
  2366.                     fb.CreateAutoPlaylist(fb.PlaylistCount, n, q, s, f == 6 ? true : false);
  2367.                     fb.ActivePlaylist = fb.PlaylistCount - 1;
  2368.                 }
  2369.                
  2370.                 this.autoplaylists_edit = function(x, y) {
  2371.                     var _menu = window.CreatePopupMenu();
  2372.                     var i = this.index;
  2373.                     _menu.AppendMenuItem(MF_STRING, 1, "Rename...");
  2374.                     _menu.AppendMenuItem(MF_STRING, 2, "Edit query...");
  2375.                     _menu.AppendMenuItem(MF_STRING, 3, "Edit sort pattern...");
  2376.                     _menu.AppendMenuItem(MF_STRING, 4, "Force Sort");
  2377.                     _menu.CheckMenuItem(4, this.forced[i] == 6 ? true : false);
  2378.                     this.autoplaylists_editing = true;
  2379.                     this.autoplaylists_hover = false;
  2380.                     window.RepaintRect(this.x + this.w - 40, this.y + 15, 40, Math.min(this.rows, this.items) * this.row_height);
  2381.                     idx = _menu.TrackPopupMenu(x, y);
  2382.                     switch(idx) {
  2383.                         case 0:
  2384.                             this.autoplaylists_editing = false;
  2385.                             _menu.Dispose();
  2386.                             return;
  2387.                         case 1:
  2388.                             var new_name = p.InputBox("Rename your autoplaylist", p.name, this.names[i]);
  2389.                             if (new_name != "") this.names[i] = new_name;
  2390.                             break;
  2391.                         case 2:
  2392.                             var new_query = p.InputBox("Enter your autoplaylist query", p.name, this.queries[i]);
  2393.                             if (new_query != "") this.queries[i] = new_query;
  2394.                             break;
  2395.                         case 3:
  2396.                             var new_sort = p.InputBox("Enter a sort pattern\n\n(optional)", p.name, this.sorts[i]);
  2397.                             this.sorts[i] = new_sort;
  2398.                             this.forced[i] = new_sort.length > 0 ? p.MsgBox("Force sort?", 4, p.name) : 7;
  2399.                             break;
  2400.                         case 4:
  2401.                             this.forced[i] = this.forced[i] == 6 ? 7 : 6;
  2402.                             break;
  2403.                     }
  2404.                     _menu.Dispose();
  2405.                     var temp = this.names[i] + "¬" + this.queries[i] + "¬" + this.sorts[i] + "¬" + this.forced[i];
  2406.                     if (this.data[i] != temp) {
  2407.                         this.data[i] = temp;
  2408.                         p.save(this.data.join("\n"), this.filename);
  2409.                         if (this.autoplaylists_success) this.autoplaylists_run(this.names[i], this.queries[i], this.sorts[i], this.forced[i]);
  2410.                         window.NotifyOthers("autoplaylists", "update");
  2411.                         this.update();
  2412.                     }
  2413.                     this.autoplaylists_editing = false;
  2414.                 }
  2415.                
  2416.                 this.autoplaylists_delete = function() {
  2417.                     if (this.offset > 1) this.offset--;
  2418.                     this.autoplaylists_deleted_items.unshift(this.data[this.index]);
  2419.                     this.data.splice(this.index, 1);
  2420.                     p.save(this.data.join("\n"), this.filename);
  2421.                     window.NotifyOthers("autoplaylists", "update");
  2422.                     this.update();
  2423.                 }
  2424.                
  2425.                 this.mode = "autoplaylists";
  2426.                 this.autoplaylists_del_img = gdi.Image(p.images_path + "cross.png");
  2427.                 this.autoplaylists_edit_img = gdi.Image(p.images_path + "edit.png");
  2428.                 this.autoplaylists_hover = false;
  2429.                 this.autoplaylists_editing = false;
  2430.                 this.autoplaylists_remove_duplicates = window.GetProperty("autoplaylists_remove_duplicates", true);
  2431.                 this.autoplaylists_success = window.GetProperty("autoplaylists_success", true);
  2432.                 this.autoplaylists_title = window.GetProperty("autoplaylists_title", "Autoplaylists");
  2433.                 this.autoplaylists_slot = window.GetProperty("autoplaylists_slot", 1);
  2434.                 this.filename = p.settings_folder + "autoplaylists" + this.autoplaylists_slot;
  2435.                 this.autoplaylists_deleted_items = [];
  2436.                 break;
  2437.         }
  2438.     }
  2439.    
  2440.     this.x = x;
  2441.     this.y = y;
  2442.     this.w = w;
  2443.     this.h = h;
  2444.     this.index = 0;
  2445.     this.offset = 0;
  2446.     this.items = 0;
  2447.     this.text = "";
  2448.     this.artist = "";
  2449.     this.url = "";
  2450.     this.text_x = 0;
  2451.     this.show_timestamp = window.GetProperty("show_timestamp", true);
  2452.     this.autoplaylist_img = gdi.Image(p.images_path + "search_small.png");
  2453.     this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  2454.     this.init();
  2455. }
  2456.  
  2457. function playcount_sync(x, y) {
  2458.     this.playback_time = function() {
  2459.         this.time_elapsed++;
  2460.         if (this.time_elapsed == 3 && this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0) {
  2461.             p.console("Automatically loving this track....");
  2462.             this.love_track();
  2463.         }
  2464.         if (this.time_elapsed == this.target_time) {
  2465.             if (!this.library || fb.IsMetadbInMediaLibrary(p.metadb)) this.sync_track();
  2466.             else p.console("Track not in library. Not updating");
  2467.         }
  2468.     }
  2469.    
  2470.     this.metadb_changed = function() {
  2471.         if (!p.metadb) return false;
  2472.         this.artist = fb.TitleFormat(p.artist_tf).EvalWithMetadb(p.metadb);
  2473.         this.track = fb.TitleFormat("%title%").EvalWithMetadb(p.metadb);
  2474.         this.old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(p.metadb) == 1 ? 1 : 0;
  2475.         this.old_userplaycount = fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb);
  2476.         this.method = this.old_userloved == 1 ? "track.unlove" : "track.love";
  2477.         this.tooltip = (this.old_userloved == 1 ? "Unlove" : "Love") + " \"" + this.track + "\" by \"" + this.artist + "\".";
  2478.         this.crc32 = fb.TitleFormat("$crc32($lower(%artist%%title%))").EvalWithMetadb(p.metadb);
  2479.         b.update();
  2480.         return true;
  2481.     }
  2482.    
  2483.     this.playback_new_track = function() {
  2484.         this.auto_love_count = 0;
  2485.         this.time_elapsed = 0;
  2486.         switch(true) {
  2487.             case fb.PlaybackLength == 0:
  2488.                 this.target_time = 240;
  2489.                 break;
  2490.             case fb.PlaybackLength >= 30:
  2491.                 this.target_time = Math.min(Math.floor(fb.PlaybackLength / 2), 240);
  2492.                 break;
  2493.             default:
  2494.                 this.target_time = 5;
  2495.                 break;
  2496.         }
  2497.         on_item_focus_change();
  2498.     }
  2499.    
  2500.     this.playback_edited = function() {
  2501.         if (this.auto_love && fb.TitleFormat(this.auto_love_tf).Eval() == 1 && this.old_userloved == 0 && this.auto_love_count == 0) {
  2502.             this.auto_love_count = 1;
  2503.             p.console("Automatically loving this track....");
  2504.             this.love_track();
  2505.         }
  2506.     }
  2507.    
  2508.     this.tf = function(value) {
  2509.         return(value.replace(/'/g, "''").replace(/,/g, "','").replace(/\//g, "'/'").replace(/\(/g, "'('").replace(/\)/g, "')'").replace(/\[/g, "'['").replace(/\]/g, "']'"));
  2510.     }
  2511.    
  2512.     this.love_track = function() {
  2513.         l.post(this.method, p.metadb);
  2514.     }
  2515.    
  2516.     this.sync_track = function() {
  2517.         switch(true) {
  2518.             case this.loved_working || this.playcount_working:
  2519.                 return;
  2520.             case !utils.CheckComponent("foo_customdb", true):
  2521.                 p.console("Not contacting Last.fm. foo_customdb is missing.");
  2522.                 return;
  2523.             default:
  2524.                 p.console("Contacting Last.fm....");
  2525.                 this.get(l.get_url() + "&method=track.getinfo&artist=" + encodeURIComponent(this.artist) + "&track=" + encodeURIComponent(this.track) + "&autocorrect=" + (l.auto_correct ? 1 : 0), function() {
  2526.                     ps.update_track();
  2527.                 });
  2528.         }
  2529.     }
  2530.    
  2531.     this.get = function(url, func) {
  2532.         if (l.username.length == 0) {
  2533.             this.loved_working = false;
  2534.             this.playcount_working = false;
  2535.             p.console(l.username_error);
  2536.             return;
  2537.         }
  2538.         this.xmlhttp.open("GET", url, true);
  2539.         this.xmlhttp.setRequestHeader('User-Agent', l.user_agent);
  2540.         this.xmlhttp.send();
  2541.         this.xmlhttp.onreadystatechange = function() {
  2542.             if (ps.xmlhttp.readyState == 4) {
  2543.                 if (ps.xmlhttp.status == 200) {
  2544.                     func();
  2545.                 } else {
  2546.                     p.console(ps.xmlhttp.responsetext || "HTTP error: " + ps.xmlhttp.status);
  2547.                 }
  2548.             }
  2549.         }
  2550.     }
  2551.    
  2552.     this.update_track = function() {
  2553.         this.json_data = p.json(ps.xmlhttp.responsetext);
  2554.         if (!this.json_data || this.json_data.error > 0 || !this.json_data.track) {
  2555.             p.console(ps.xmlhttp.responsetext);
  2556.             return;
  2557.         }
  2558.         this.userplaycount = this.json_data.track.userplaycount > 0 ? ++this.json_data.track.userplaycount : 1;
  2559.         this.userloved = this.json_data.track.userloved == 1 ? 1 : 0;
  2560.         if (fb.IsPlaying && this.time_elapsed >= this.target_time && fb.PlaybackLength > 29 && fb.PlaybackLength < 10800) {
  2561.             switch(true) {
  2562.                 case this.userplaycount < this.old_userplaycount:
  2563.                     p.console("Playcount returned from Last.fm is lower than current value. Not updating.");
  2564.                     break;
  2565.                 case this.old_userplaycount == this.userplaycount:
  2566.                     p.console("No changes found. Not updating.");
  2567.                     break;
  2568.                 default:
  2569.                     p.console("Last.fm responded ok. Attempting to update playcount...");
  2570.                     fb.RunContextCommandWithMetadb("Customdb Delete Playcount", p.metadb, 8);
  2571.                     if (this.old_userloved == 1) fb.RunContextCommandWithMetadb("Customdb Love 0", p.metadb, 8);
  2572.                     var attempt = 0;
  2573.                     while(fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) != this.userplaycount && attempt <= 3) {
  2574.                         var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + this.crc32 + '\\",\\"-1\\",\\"LASTFM_PLAYCOUNT_DB\\",\\"' + this.userplaycount + '\\")\";';
  2575.                         p.WshShell.Run(p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath + " " + query1, 0, true);
  2576.                         attempt++;
  2577.                     }
  2578.                     fb.RunContextCommandWithMetadb("Customdb Refresh", p.metadb, 8);
  2579.                     if (fb.TitleFormat("%LASTFM_PLAYCOUNT_DB%").EvalWithMetadb(p.metadb) == this.userplaycount) p.console("Playcount updated successfully.");
  2580.                     else p.console("Database error. Playcount not updated.");
  2581.                     break;
  2582.             }
  2583.         }
  2584.         if (this.old_userloved != this.userloved) fb.RunContextCommandWithMetadb("Customdb Love " + this.userloved, p.metadb, 8);
  2585.     }
  2586.    
  2587.     this.start_import = function() {
  2588.         if (this.show_console) fb.ShowConsole();
  2589.         this.loved_page_errors = 0;
  2590.         this.playcount_page_errors = 0;
  2591.         ps.pages = 0;
  2592.         this.r = 1;
  2593.         this.sql = "BEGIN TRANSACTION;\n";
  2594.         this.loved_working = true;
  2595.         this.sync_loved(1);
  2596.     }
  2597.    
  2598.     this.sync_loved = function(page) {
  2599.         if (!this.loved_working) return(p.console("Import aborted."));
  2600.         this.page = page;
  2601.         this.get(l.get_url() + "&method=user.getlovedtracks&limit=200&page=" + this.page, function() {
  2602.             ps.update_loved();
  2603.         });
  2604.     }
  2605.    
  2606.     this.update_loved = function() {
  2607.         this.json_data = p.json(ps.xmlhttp.responsetext);
  2608.         if (this.json_data && this.json_data.error > 0) {
  2609.             this.loved_working = false;
  2610.             p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
  2611.             return;
  2612.         }
  2613.         if (this.json_data && this.json_data.lovedtracks && this.json_data.lovedtracks.track) {
  2614.             if (this.page == 1) this.pages = this.json_data.lovedtracks["@attr"].totalPages;
  2615.             for (i = 0; i < this.json_data.lovedtracks.track.length; i++) {
  2616.                 var data = [];
  2617.                 data[0] = this.json_data.lovedtracks.track[i].artist.name;
  2618.                 data[1] = this.json_data.lovedtracks.track[i].name;
  2619.                 data[2] = 1;
  2620.                 if (data.length == 3) {
  2621.                     p.console(this.r + ": " + data[0] + " - " + data[1]);
  2622.                     var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
  2623.                     this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_LOVED_DB","' + data[2] + '");' + "\n";
  2624.                     this.r++;
  2625.                 }
  2626.             }
  2627.             p.console("Loved tracks: completed page " + this.page + " of " + this.pages);
  2628.         } else if (this.pages > 0) {
  2629.             this.loved_page_errors++;
  2630.         }
  2631.         if (this.page < this.pages) {
  2632.             this.page++;
  2633.             this.sync_loved(this.page);
  2634.         } else {
  2635.             this.loved_working = false;
  2636.             if (this.full_import) {
  2637.                 this.playcount_working = true;
  2638.                 this.pages = 0;
  2639.                 this.r = 1;
  2640.                 this.sync_playcount(1);
  2641.             } else {
  2642.                 try {
  2643.                     this.sql += "COMMIT;"
  2644.                     var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
  2645.                     ts.WriteLine(this.sql);
  2646.                     ts.Close();
  2647.                     this.finish_import();
  2648.                 } catch(e) {
  2649.                 }
  2650.                 if (this.loved_page_errors > 0) {
  2651.                     p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
  2652.                 } else {
  2653.                     p.console("There were no errors reported.");
  2654.                 }
  2655.             }
  2656.         }
  2657.     }
  2658.    
  2659.     this.sync_playcount = function(page) {
  2660.         if (this.playcount_working == false) return(p.console("Import aborted."));
  2661.         this.page = page;
  2662.         this.get(l.get_url() + "&method=library.gettracks&limit=100&page=" + this.page, function() {
  2663.             ps.update_playcount();
  2664.         });
  2665.     }
  2666.    
  2667.     this.update_playcount = function() {
  2668.         this.json_data = p.json(ps.xmlhttp.responsetext);
  2669.         if (this.json_data && this.json_data.error > 0) {
  2670.             this.playcount_working = false;
  2671.             p.MsgBox("There is a problem with the Last.fm web services. Please try again later.\n\n" + ps.xmlhttp.responsetext, 0, p.name);
  2672.             return;
  2673.         }
  2674.         if (this.json_data && this.json_data.tracks && this.json_data.tracks.track) {
  2675.             if (this.page == 1) this.pages = this.json_data.tracks["@attr"].totalPages
  2676.             for (i = 0; i < this.json_data.tracks.track.length; i++) {
  2677.                 var data = [];
  2678.                 data[0] = this.json_data.tracks.track[i].artist.name;
  2679.                 data[1] = this.json_data.tracks.track[i].name;
  2680.                 data[2] = this.json_data.tracks.track[i].playcount;
  2681.                 if (data[2] == 0) {
  2682.                     this.page = this.pages;
  2683.                     break;
  2684.                 }
  2685.                 if (data.length == 3) {
  2686.                     p.console(this.r + ": " + data[0] + " - " + data[1] + " " + data[2]);
  2687.                     var url = fb.TitleFormat("$crc32($lower(" + this.tf(data[0]) + this.tf(data[1]) + "))").Eval(true);
  2688.                     this.sql += 'INSERT OR REPLACE INTO quicktag(url,subsong,fieldname,value) VALUES("' + url + '","-1","LASTFM_PLAYCOUNT_DB","' + data[2] + '");' + "\n";
  2689.                     this.r++;
  2690.                 }
  2691.             }
  2692.             p.console("Playcount: completed page " + this.page + " of " + this.pages);
  2693.         } else if (this.pages > 0) {
  2694.             this.playcount_page_errors++;
  2695.         }
  2696.         if (this.page < this.pages) {
  2697.             this.page++;
  2698.             this.sync_playcount(this.page);
  2699.         } else {
  2700.             try {
  2701.                 this.sql += "COMMIT;"
  2702.                 var ts = p.fso.OpenTextFile(this.sql_file, 2, true, 0);
  2703.                 ts.WriteLine(this.sql);
  2704.                 ts.Close();
  2705.                 this.finish_import();
  2706.             } catch(e) {
  2707.             }
  2708.             this.playcount_working = false;
  2709.             if (this.loved_page_errors + this.playcount_page_errors > 0) {
  2710.                 p.console("Loved track page errors: " + this.loved_page_errors + " (200 records are lost for every page that fails.)");
  2711.                 p.console("Playcount page errors: " + this.playcount_page_errors + " (100 records are lost for every page that fails.)");
  2712.             } else {
  2713.                 p.console("There were no errors reported.");
  2714.             }
  2715.         }
  2716.     }
  2717.    
  2718.     this.finish_import = function() {
  2719.         try {
  2720.             var cmd_file = p.fso.GetFile(p.script_path + "lastfm_sql.cmd").ShortPath;
  2721.             var db_file = p.fso.GetFile(fb.ProfilePath + "customdb_sqlite.db").ShortPath;
  2722.             p.run(cmd_file + " " + p.fso.GetFile(p.script_path + "sqlite3.exe").ShortPath + " " + db_file + " " + p.fso.GetFile(this.sql_file).ShortPath);
  2723.         } catch(e) {
  2724.         }
  2725.     }
  2726.    
  2727.     this.update_button = function() {
  2728.         var exclamation = this.icon == "tango" ? "exclamation.png" : "exclamation_small.png";
  2729.         var love = this.icon == "tango" ? "love.png" : "love_small.png";
  2730.         var love_h = this.icon == "tango" ? "love_h.png" : "love_h_small.png";
  2731.         this.size = this.icon == "tango" ? 32 : 20;
  2732.         switch(true) {
  2733.             case l.username.length == 0:
  2734.                 this.n = exclamation;
  2735.                 this.h = exclamation;
  2736.                 this.tooltip = l.username_error;
  2737.                 this.func = null;
  2738.                 break;
  2739.             case l.sk.length != 32:
  2740.                 this.n = exclamation;
  2741.                 this.h = exclamation;
  2742.                 this.tooltip = l.password_error;
  2743.                 this.func = null;
  2744.                 break;
  2745.             case !p.metadb:
  2746.                 this.n = exclamation;
  2747.                 this.h = exclamation;
  2748.                 this.tooltip = "No selection";
  2749.                 this.func = null;
  2750.                 break;
  2751.             case !utils.CheckComponent("foo_customdb", true):
  2752.                 this.n = exclamation;
  2753.                 this.h = exclamation;
  2754.                 this.tooltip = "The foo_customdb component is not installed. Please refer to the readme.";
  2755.                 this.func = null;
  2756.                 break;
  2757.             default:
  2758.                 this.n = this.old_userloved == 1 ? love_h : love;
  2759.                 this.h = this.old_userloved == 1 ? love : love_h;
  2760.                 this.func = function() { ps.love_track(); }
  2761.                 break;
  2762.         }
  2763.     }
  2764.    
  2765.     this.x = x;
  2766.     this.y = y;
  2767.     this.loved_working = false;
  2768.     this.playcount_working = false;
  2769.     this.sql_file = p.data_folder + "lastfm.sql";
  2770.     this.page = 0;
  2771.     this.last_page = 0;
  2772.     this.auto_love = window.GetProperty("playcount_sync_auto_love", false);
  2773.     this.auto_love_tf = window.GetProperty("playcount_sync_auto_love_tf", "");
  2774.     this.icon = window.GetProperty("playcount_sync_icon", "tango");
  2775.     this.show_console = window.GetProperty("playcount_sync_show_console", true);
  2776.     this.library = window.GetProperty("playcount_sync_library", false);
  2777.     this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  2778.     window.SetInterval(function() {
  2779.         var temp = ps.page > 1 ? ps.page - 1 : 1;
  2780.         if (ps.loved_working && ps.page == ps.last_page) {
  2781.             ps.xmlhttp.abort();
  2782.             ps.sync_loved(temp);
  2783.         } else if (ps.playcount_working && ps.page == ps.last_page) {
  2784.             ps.xmlhttp.abort();
  2785.             ps.sync_playcount(temp);
  2786.         } else {
  2787.             ps.last_page = ps.page;
  2788.         }
  2789.     }, 15000);
  2790. }
  2791.  
  2792. function rating(x, y, bs) {
  2793.     this.draw = function(gr) {
  2794.         if (!p.metadb) return;
  2795.         for (i = 1; i < 6; i++) {
  2796.             this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.on_img;
  2797.             p.draw_image(gr, this.img, this.x + this.bs * (i - 1), this.y, this.bs, this.bs, "centre");
  2798.         }
  2799.     }
  2800.    
  2801.     this.metadb_changed = function() {
  2802.         if (!p.metadb) return false;
  2803.         this.hover = false;
  2804.         this.rating = p.eval("$if2(%rating%,0)");
  2805.         this.tiptext = p.eval(this.tiptext_tf);
  2806.         this.lrating = this.rating;
  2807.         window.RepaintRect(this.x, this.y, this.w, this.bs);
  2808.         return true;
  2809.     }
  2810.    
  2811.     this.trace = function(x, y) {
  2812.         return x > this.x - this.bs && x < this.x + (this.bs * 5) && y > this.y && y < this.y + this.bs;
  2813.     }
  2814.    
  2815.     this.move = function(x, y) {
  2816.         if (!this.trace(x, y)) {
  2817.             if (this.hover) this.leave();
  2818.             return false;
  2819.         }
  2820.         if (p.metadb) {
  2821.             if (x > this.x) p.tt(this.tiptext);
  2822.             this.hover = true;
  2823.             this.lrating = Math.ceil((x - this.x) / this.bs);
  2824.             window.RepaintRect(this.x, this.y, this.w, this.bs);
  2825.         }
  2826.         return true;
  2827.     }
  2828.    
  2829.     this.lbtn_up = function(x, y) {
  2830.         if (!this.trace(x, y)) return false;
  2831.         if (this.check) {
  2832.             if (this.lrating != this.rating && this.hover == 1) fb.RunContextCommandWithMetadb("Rating/" + (this.lrating == 0 ? "<not set>" : this.lrating), p.metadb, 8);
  2833.         } else {
  2834.             p.MsgBox(this.error_text, 0, p.name);
  2835.             p.browser("http://www.foobar2000.org/components/view/foo_playcount");
  2836.         }
  2837.         return true;
  2838.     }
  2839.    
  2840.     this.leave = function() {
  2841.         p.ttd();
  2842.         this.hover = false;
  2843.         window.RepaintRect(this.x, this.y, this.w, this.bs);
  2844.     }
  2845.    
  2846.     this.x = x;
  2847.     this.y = y;
  2848.     this.bs = bs;
  2849.     this.w = this.bs * 5;
  2850.     this.hover = false;
  2851.     this.rating = null;
  2852.     this.lrating = null;
  2853.     this.img = null;
  2854.     this.off_img = gdi.Image(p.images_path + "off.png");
  2855.     this.on_img = gdi.Image(p.images_path + "on.png");
  2856.     this.check = utils.CheckComponent("foo_playcount", true);
  2857.     this.error_text = "This script requires foo_playcount.";
  2858.     this.tiptext_tf = this.check ? 'Rate "%title%" by "%artist%"' : this.error_text;
  2859. }
  2860.  
  2861. function sb(x, y, w, h, img, isVisible, func) {
  2862.     this.x = x;
  2863.     this.y = y;
  2864.     this.w = w;
  2865.     this.h = h;
  2866.     this.img = img;
  2867.     this.isVisible = new Function("return (" + isVisible + ");");
  2868.     this.func = func;
  2869.    
  2870.     this.draw = function(gr) {
  2871.         if (this.isVisible()) p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "centre");
  2872.     }
  2873.    
  2874.     this.trace = function(x, y) {
  2875.         return(x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h && this.isVisible());
  2876.     }
  2877.    
  2878.     this.lbtn_up = function(x, y) {
  2879.         if (!this.trace(x, y)) return false;
  2880.         this.func && this.func(x, y);
  2881.         return true;
  2882.     }
  2883. }
  2884.  
  2885. function seekbar(x, y, w, h) {
  2886.     this.trace = function(x, y) {
  2887.         return (x > this.x && x < this.x + this.w && y > this.y - (this.drag ? 200 : 0) && y < this.y + this.h + (this.drag ? 200 : 0));
  2888.     }
  2889.    
  2890.     this.draw = function(gr) {
  2891.         p.draw_background(gr);
  2892.         switch(this.mode) {
  2893.             case "spectrogram":
  2894.                 if (this.working) {
  2895.                     p.draw_image(gr, this.hourglass_img, this.x, this.y + Math.round((this.h - 32) / 2), this.w, 32, "centre");
  2896.                 } else {
  2897.                     p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, "stretch");
  2898.                 }
  2899.                 if (fb.IsPlaying && fb.PlaybackLength > 0) {
  2900.                     this.calc_pos();
  2901.                     gr.FillSolidRect(this.x + this.pos - 2, this.y, 2, this.h, p.splitRGB(this.marker));
  2902.                 }
  2903.                 break;
  2904.             case "nyan_cat":
  2905.                 if (fb.IsPlaying && fb.PlaybackLength > 0) {
  2906.                     this.calc_pos();
  2907.                     for (i = 0; i < this.offsets.length; i++) {
  2908.                         gr.FillSolidRect(this.x - 48, this.y + this.offsets[i], this.pos + 2, this.heights[i], this.colours[i]);
  2909.                     }
  2910.                     p.draw_image(gr, this.cat_img[this.z], this.pos, this.y, 48, 30);
  2911.                 } else {
  2912.                     p.draw_image(gr, this.cat_img[0], 0, this.y, 48, 30);
  2913.                 }
  2914.                 break;
  2915.         }
  2916.     }
  2917.    
  2918.     this.playback_new_track = function() {
  2919.         if (this.mode != "spectrogram") return;
  2920.         var metadb = fb.GetNowPlaying();
  2921.         this.img && this.img.Dispose();
  2922.         this.img = null;
  2923.         try {
  2924.             this.png_filename = spectrogram_cache + "\\" + fb.TitleFormat("$crc32(%path%)").EvalWithMetadb(metadb) + this.sox_params + ".png";
  2925.             switch(true) {
  2926.                 case !metadb:
  2927.                 case metadb.RawPath.indexOf("file") != 0:
  2928.                     p.console("Skipping... Not a valid file type.");
  2929.                     break;
  2930.                 case fb.PlaybackLength == 0:
  2931.                     p.console("Skipping... Unknown length.");
  2932.                     break;
  2933.                 case fb.TitleFormat("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)").EvalWithMetadb(metadb) == "cue":
  2934.                     p.console("Skipping... Cannot support cuesheets.");
  2935.                     break;
  2936.                 case fb.TitleFormat("%subsong%").EvalWithMetadb(metadb) > 0:
  2937.                     p.console("Skipping... Cannot support tracks with chapters.");
  2938.                     break;
  2939.                 case this.library && !fb.IsMetadbInMediaLibrary(metadb):
  2940.                     p.console("Skipping... Track not in library.");
  2941.                     break;
  2942.                 case p.fso.FileExists(this.png_filename):
  2943.                     this.img = gdi.Image(this.png_filename);
  2944.                     break;
  2945.                 default:
  2946.                     this.working = true
  2947.                     window.Repaint();
  2948.                     var filename = metadb.Path;
  2949.                     var length = fb.TitleFormat("%length%").EvalWithMetadb(metadb);
  2950.                     var cmd = "cmd /c \"\"" + ffmpeg_exe + "\" -i \"" + filename + "\" -t " + length + " -f sox - | \"" + sox_exe + "\" -p -n " + this.sox_params + " -d " + length + " -r -o \"" + this.png_filename + "\"\"";
  2951.                     //p.console(cmd);
  2952.                     try { p.WshShell.Run(cmd, 0, true); } catch(e) {}
  2953.                     this.working = false;
  2954.                     this.img = gdi.Image(this.png_filename);
  2955.                     break;
  2956.             }
  2957.         } catch(e) {
  2958.             //p.console(e);
  2959.         }
  2960.         window.Repaint();
  2961.     }
  2962.    
  2963.     this.playback_stop = function() {
  2964.         window.Repaint();
  2965.     }
  2966.    
  2967.     this.playback_seek = function() {
  2968.         this.update();
  2969.     }
  2970.    
  2971.     this.move = function(x, y) {
  2972.         if (this.drag) this.update();
  2973.         if (this.trace(x, y)) {
  2974.             if (fb.IsPlaying && fb.PlaybackLength > 0) {
  2975.                 x -= this.x;
  2976.                 this.drag_seek = x < 0 ? 0 : x > this.w ? 1 : x / this.w;
  2977.                 if (x != this.old_x || y != this.old_y) {
  2978.                     p.tt(p.format_time(fb.PlaybackLength * this.drag_seek));
  2979.                     this.old_x = x;
  2980.                     this.old_y = y;
  2981.                 }
  2982.             }
  2983.             return true;
  2984.         } else {
  2985.             this.leave();
  2986.             return false;
  2987.         }
  2988.     }
  2989.    
  2990.     this.lbtn_down = function(x, y) {
  2991.         if (!this.trace(x, y)) return false;
  2992.         if (fb.IsPlaying && fb.PlaybackLength > 0) this.drag = true;
  2993.         return true;
  2994.     }
  2995.    
  2996.     this.lbtn_up = function(x, y) {
  2997.         if (!this.trace(x, y)) return false;
  2998.         if (this.drag) {
  2999.             this.drag = false;
  3000.             fb.PlaybackTime = fb.PlaybackLength * this.drag_seek;
  3001.         }
  3002.         return true;
  3003.     }
  3004.    
  3005.     this.leave = function() {
  3006.         this.drag = false;
  3007.         p.ttd();
  3008.     }
  3009.    
  3010.     this.update = function() {
  3011.         window.RepaintRect(0, this.y, p.w, this.h);
  3012.     }
  3013.    
  3014.     this.calc_pos = function() {
  3015.         this.pos = this.drag ? this.w * this.drag_seek : this.w * (fb.PlaybackTime / fb.PlaybackLength);
  3016.     }
  3017.    
  3018.     this.init = function() {
  3019.         switch(true) {
  3020.             case p.check_feature("spectrogram"):
  3021.                 this.clear_images = function(period) {
  3022.                     var now = Date.parse(Date());
  3023.                     images = utils.Glob(spectrogram_cache + "\\*.*").toArray();
  3024.                     for (i = 0; i < images.length; i++) {
  3025.                         if (this.png_filename == images[i]) continue;
  3026.                         var file = p.fso.Getfile(images[i]);
  3027.                         var file_date = Date.parse(file.DateLastModified);
  3028.                         if (now - file_date > period) {
  3029.                             try {
  3030.                                 p.fso.DeleteFile(images[i]);
  3031.                             } catch(e) {
  3032.                                 p.console("Could not delete " + images[i]);
  3033.                             }
  3034.                         }
  3035.                     }
  3036.                 }
  3037.                
  3038.                 this.mode = "spectrogram";
  3039.                 this.library = window.GetProperty("seekbar_library", false);
  3040.                 this.marker = window.GetProperty("seekbar_marker", "240-240-240");
  3041.                 this.sox_params = window.GetProperty("sox_params", "channels 1 spectrogram -Y 130").trim();
  3042.                 this.working = false;
  3043.                 this.img = false;
  3044.                 this.hourglass_img = gdi.Image(p.images_path + "hourglass.png");
  3045.                 if (!p.fso.FolderExists(spectrogram_cache)) p.fso.CreateFolder(spectrogram_cache);
  3046.                 if (fb.IsPlaying) {
  3047.                     window.SetTimeout(function() {
  3048.                         s.playback_new_track();
  3049.                     }, 100);
  3050.                 }
  3051.                 break;
  3052.             case p.check_feature("nyan_cat"):
  3053.                 this.mode = "nyan_cat";
  3054.                 this.cat_img = [gdi.Image(p.images_path + "\\seekbar cat.png"), gdi.Image(p.images_path + "\\seekbar cat 2.png")];
  3055.                 this.offsets = [2, 6, 10, 15, 20, 24];
  3056.                 this.heights = [4, 4, 5, 5, 4, 4];
  3057.                 this.colours = [RGB(255, 0, 0), RGB(255, 153, 0), RGB(255, 255, 0), RGB(51, 255, 0), RGB(0, 153, 255), RGB(102, 51, 255)];
  3058.                 break;
  3059.         }
  3060.     }
  3061.    
  3062.     this.x = x;
  3063.     this.y = y;
  3064.     this.w = w;
  3065.     this.h = h;
  3066.     this.z = 0;
  3067.     this.pos = 0;
  3068.     this.drag = false;
  3069.     this.drag_seek = 0;
  3070.     this.old_x = 0;
  3071.     this.old_y = 0;
  3072.     this.init();
  3073.     this.seekbar_timer = window.SetInterval(function() {
  3074.         s.z = s.z == 0 ? 1 : 0;
  3075.         if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
  3076.         s.update();
  3077.     }, 150);
  3078. }
  3079.  
  3080. function text(x, y, w, h) {
  3081.     this.size = function() {
  3082.         this.rows = Math.floor((this.h - 36) / p.row_height);
  3083.         this.but_x = this.x + Math.round((this.w - 15) / 2);
  3084.         this.up_btn = new sb(this.but_x, this.y, 15, 15, p.up_img, "t.offset > 0", function() { t.wheel(1); });
  3085.         this.down_btn = new sb(this.but_x, this.y + this.h - 15, 15, 15, p.down_img, "t.offset < t.text_rows - t.rows", function() { t.wheel(-1); });
  3086.         this.calc();
  3087.     }
  3088.    
  3089.     this.draw = function(gr, colour) {
  3090.         for (i = 0; i < Math.min(this.rows, this.text_rows); i++) {
  3091.             if (this.centre) p.centre_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
  3092.             else p.left_text(gr, this.text_array[i + this.offset], this.fixed ? p.fixed_font : p.normal_font, colour || p.textcolour, this.x, 18 + this.y + (i * p.row_height), this.w, p.row_height);
  3093.         }
  3094.         this.up_btn.draw(gr);
  3095.         this.down_btn.draw(gr);
  3096.     }
  3097.    
  3098.     this.metadb_changed = function() {
  3099.         if (!p.metadb) return false;
  3100.         switch(this.mode) {
  3101.             case "simple_tag":
  3102.                 this.temp_filename = p.metadb.Path;
  3103.                 if (this.filename == this.temp_filename) return false;
  3104.                 this.filename = this.temp_filename;
  3105.                 this.text = p.eval(this.tag);
  3106.                 break;
  3107.             case "simple_text":
  3108.                 this.temp_filename = p.eval(this.filename_tf);
  3109.                 if (this.filename == this.temp_filename) return false;
  3110.                 this.text = "";
  3111.                 this.filename = this.temp_filename;
  3112.                 if (p.fso.FolderExists(this.filename)) {
  3113.                     this.files = [];
  3114.                     this.files = this.files.concat(utils.Glob(this.filename + "\\*.txt").toArray(), utils.Glob(this.filename + "\\*.log").toArray());
  3115.                     this.files.sort();
  3116.                     this.text = p.open(this.files[0]);
  3117.                 } else {
  3118.                     this.filenames = this.filename.split("|");
  3119.                     for (i = 0; i < this.filenames.length; i++) {
  3120.                         if (p.fso.fileExists(this.filenames[i])) {
  3121.                             this.text = p.open(this.filenames[i]);
  3122.                             break;
  3123.                         }
  3124.                     }
  3125.                 }
  3126.                 this.text = this.text.replace(/\t/g, "    ");
  3127.                 break;
  3128.             case "lastfm_wiki":
  3129.                 p.artist = p.eval(p.artist_tf);
  3130.                 if (this.artist == p.artist) return false;
  3131.                 this.artist = p.artist;
  3132.                 this.folder = p.data_folder + p.eval("$crc32(" + p.artist_tf + ")");
  3133.                 if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
  3134.                 this.filename = this.folder + "\\artist.getInfo_mod.json";
  3135.                 this.text = "Nothing found.";
  3136.                 this.url = "http://www.last.fm/";
  3137.                 if (p.fso.fileExists(this.filename)) {
  3138.                     this.json_text = p.open(this.filename);
  3139.                     this.json_data = p.json(this.json_text);
  3140.                     if (this.json_data && this.json_data.response && this.json_data.response.biographies) {
  3141.                         this.items = this.json_data.response.biographies.length;
  3142.                         for (i = 0; i < this.items; i++) {
  3143.                             if (this.json_data.response.biographies[i].site == this.source) {
  3144.                                 this.text = this.json_data.response.biographies[i].text;
  3145.                                 this.url = this.json_data.response.biographies[i].license["attribution-url"];
  3146.                                 break;
  3147.                             }
  3148.                         }
  3149.                         if (this.source == "last.fm") {
  3150.                             this.text = this.text.replace(/\.  /g, ".\n\n")
  3151.                         } else {
  3152.                             this.text = this.text.replace(/\. \n/g, ".\n\n").replace(/\n\n\n/g, "\n\n").replace(/edit:\n/g , ":\n");
  3153.                         }
  3154.                     }
  3155.                 } else {
  3156.                     this.get();
  3157.                 }
  3158.                 break;
  3159.             case "lastfm_album":
  3160.                 var temp_album = p.eval("[%album%]");
  3161.                 var temp_artist = p.eval("[%album artist%]");
  3162.                 if (this.album == temp_album && this.artist == temp_artist) return false;
  3163.                 this.artist = temp_artist;
  3164.                 this.album = temp_album;
  3165.                 this.folder = p.data_folder + p.eval("$crc32(" + p.artist_tf + ")");
  3166.                 if (!p.fso.FolderExists(this.folder)) p.fso.CreateFolder(this.folder);
  3167.                 this.filename = this.folder + "\\album.getInfo_" + p.eval("$crc32(%album%)") + ".json";
  3168.                 this.text = "Nothing found.";
  3169.                 this.url = l.url;
  3170.                 if (p.fso.fileExists(this.filename)) {
  3171.                     this.file = p.fso.GetFile(this.filename);
  3172.                     this.json_text = p.open(this.filename);
  3173.                     this.json_data = p.json(this.json_text);
  3174.                     if (this.json_data && this.json_data.album) {
  3175.                         if (this.json_data.album.url) this.url = this.json_data.album.url;
  3176.                         if (this.json_data.album.wiki && this.json_data.album.wiki.content) {
  3177.                             this.text = p.strip_tags(this.json_data.album.wiki.content);
  3178.                             this.text = this.text.replace("User-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.", "").trim();
  3179.                         }
  3180.                     }
  3181.                     if (Date.parse(Date()) - Date.parse(this.file.DateLastModified) > ONE_WEEK) this.get();
  3182.                 } else {
  3183.                     this.get();
  3184.                 }
  3185.                 break;
  3186.         }
  3187.         this.calc();
  3188.         window.Repaint();
  3189.         return true;
  3190.     }
  3191.    
  3192.     this.trace = function(x, y) {
  3193.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  3194.     }
  3195.    
  3196.     this.wheel = function(step) {
  3197.         if (!this.trace(p.mx, p.my)) return false;
  3198.         if (this.text_rows > this.rows) {
  3199.             this.offset -= step * 3;
  3200.             if (this.offset < 0) this.offset = 0;
  3201.             if (this.offset + this.rows > this.text_rows) this.offset = this.text_rows - this.rows;
  3202.             window.RepaintRect(this.x, this.y, this.w, this.h);
  3203.         }
  3204.         return true;
  3205.     }
  3206.    
  3207.     this.move = function(x, y) {
  3208.         switch(true) {
  3209.             case !this.trace(x, y):
  3210.                 window.SetCursor(IDC_ARROW);
  3211.                 return false;
  3212.             case this.up_btn.trace(x, y):
  3213.             case this.down_btn.trace(x, y):
  3214.                 window.SetCursor(IDC_HAND);
  3215.                 return true;
  3216.             default:
  3217.                 window.SetCursor(IDC_ARROW);
  3218.                 return false;
  3219.         }
  3220.     }
  3221.    
  3222.     this.lbtn_up = function(x, y) {
  3223.         if (!this.trace(x, y)) return false;
  3224.         this.up_btn.lbtn_up(x, y);
  3225.         this.down_btn.lbtn_up(x, y);
  3226.         return true;
  3227.     }
  3228.    
  3229.     this.get = function() {
  3230.         var fn = this.filename;
  3231.         var func = function() {
  3232.             if (!p.save(t.xmlhttp.responsetext, fn)) return;
  3233.             t.artist = "";
  3234.             t.album = "";
  3235.             on_item_focus_change();
  3236.         }
  3237.         var url = "";
  3238.         var user_agent = "";
  3239.         switch(this.mode) {
  3240.             case "lastfm_album":
  3241.                 if (this.artist == "" || this.album == "") return;
  3242.                 url = l.get_url() + "&method=album.getInfo&artist=" + encodeURIComponent(this.artist) + "&album=" + encodeURIComponent(this.album);
  3243.                 user_agent = l.user_agent;
  3244.                 break;
  3245.             case "lastfm_wiki":
  3246.                 if (this.artist == "" || this.artist == "?") return;
  3247.                 url = "http://developer.echonest.com/api/v4/artist/biographies?api_key=EKWS4ESQLKN3G2ZWV&format=json&name=" + encodeURIComponent(this.artist);
  3248.                 break;
  3249.         }
  3250.         if (url.length == 0) return;
  3251.         this.xmlhttp.open("GET", url, true);
  3252.         if (user_agent.length > 0) this.xmlhttp.setRequestHeader('User-Agent', user_agent);
  3253.         this.xmlhttp.send();
  3254.         this.xmlhttp.onreadystatechange = function() {
  3255.             if (t.xmlhttp.readyState == 4) {
  3256.                 if (t.xmlhttp.status == 200) {
  3257.                     func();
  3258.                 } else {
  3259.                     p.console(t.xmlhttp.responsetext || "HTTP error: " + t.xmlhttp.status);
  3260.                 }
  3261.             }
  3262.         }
  3263.     }
  3264.    
  3265.     this.calc = function() {
  3266.         this.offset = 0;
  3267.         this.text_rows = 0;
  3268.         if (this.w < 100 || this.text.length == 0) return;
  3269.         var temp_bmp = gdi.CreateImage(1, 1);
  3270.         var temp_gr = temp_bmp.GetGraphics();
  3271.         var paragraphs = this.text.split("\n");
  3272.         this.text_array = [];
  3273.         for (i = 0; i < paragraphs.length; i++) {
  3274.             if (this.fixed) {
  3275.                 this.text_array.push(paragraphs[i]);
  3276.             } else {
  3277.                 var lines = temp_gr.EstimateLineWrap(paragraphs[i], p.normal_font, this.w).toArray();
  3278.                 for (j = 0; j < lines.length; j += 2) {
  3279.                     this.text_array.push(lines[j].trim());
  3280.                 }
  3281.             }
  3282.         }
  3283.         this.text_rows = this.text_array.length;
  3284.         temp_bmp.ReleaseGraphics(temp_gr);
  3285.         temp_bmp.Dispose();
  3286.         temp_gr = null;
  3287.         temp_bmp = null;
  3288.     }
  3289.    
  3290.     this.init = function() {
  3291.         switch(true) {
  3292.             case p.check_feature("lastfm_album"):
  3293.                 this.mode = "lastfm_album";
  3294.                 break;
  3295.             case p.check_feature("lastfm_wiki"):
  3296.                 this.mode = "lastfm_wiki";
  3297.                 this.source = window.GetProperty("biography_source", "last.fm");
  3298.                 break;
  3299.             case p.check_feature("simple_text"):
  3300.                 this.mode = "simple_text";
  3301.                 this.title = window.GetProperty("text_title", "$directory_path(%path%)");
  3302.                 this.filename_tf = window.GetProperty("text_filename_tf", "$directory_path(%path%)");
  3303.                 this.filename = "";
  3304.                 this.fixed = window.GetProperty("text_fixed_font", true);
  3305.                 break;
  3306.             case p.check_feature("simple_tag"):
  3307.                 this.mode = "simple_tag";
  3308.                 this.title = window.GetProperty("text_title", "%title%");
  3309.                 this.filename = "";
  3310.                 this.centre = window.GetProperty("text_centre", false);
  3311.                 this.tag = window.GetProperty("text_tag", "[%lyrics%]");
  3312.                 break;
  3313.         }
  3314.     }
  3315.    
  3316.     this.x = x;
  3317.     this.y = y;
  3318.     this.w = w;
  3319.     this.h = h;
  3320.     this.text = "";
  3321.     this.artist = "";
  3322.     this.album = "";
  3323.     this.url = "";
  3324.     this.fixed = false;
  3325.     this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  3326.     this.init();
  3327.     this.size();
  3328. }
  3329.  
  3330. function thumbs() {
  3331.     this.trace = function(x, y) {
  3332.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  3333.     }
  3334.    
  3335.     this.draw = function(gr) {
  3336.         switch(true) {
  3337.             case im.images.length == 0:
  3338.                 break;
  3339.             case this.mode == "off":
  3340.                 p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
  3341.                 break;
  3342.             case !this.img:
  3343.                 break;
  3344.             case this.mode == "grid":
  3345.                 gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
  3346.                 if (this.overlay) {
  3347.                     gr.FillSolidRect(this.x, this.y, this.w, this.h, RGBA(0, 0, 0, 126));
  3348.                     p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, "centre");
  3349.                 }
  3350.                 break;
  3351.             case this.mode == "left":
  3352.             case this.mode == "right":
  3353.                 gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, this.offset * this.px, this.w, this.h);
  3354.                 p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
  3355.                 break;
  3356.             case this.mode == "bottom":
  3357.             case this.mode == "top":
  3358.                 gr.DrawImage(this.img, this.x, this.y, this.w, this.h, this.offset * this.px, 0, this.w, this.h);
  3359.                 p.draw_image(gr, im.images[im.index], im.x, im.y, im.w, im.h, im.type);
  3360.                 break;
  3361.         }
  3362.     }
  3363.    
  3364.     this.calc = function() {
  3365.         this.offset = 0;
  3366.         switch(true) {
  3367.             case p.w < this.px || p.h < this.px || this.mode == "off":
  3368.                 this.nc = true;
  3369.                 this.img && this.img.Dispose();
  3370.                 this.img = null;
  3371.                 im.x = 0;
  3372.                 im.y = 0;
  3373.                 im.w = p.w;
  3374.                 im.h = p.h;
  3375.                 break;
  3376.             case this.mode == "grid":
  3377.                 this.x = 0;
  3378.                 this.y = 0;
  3379.                 this.w = p.w;
  3380.                 this.h = p.h;
  3381.                 im.x = 40;
  3382.                 im.y = 40;
  3383.                 im.w = this.w - 80;
  3384.                 im.h = this.h - 80;
  3385.                 if (!this.nc && this.columns != Math.floor(this.w / this.px)) this.nc = true;
  3386.                 this.overlay = false;
  3387.                 this.rows = Math.ceil(this.h / this.px);
  3388.                 this.columns = Math.floor(this.w / this.px);
  3389.                 this.img_rows = Math.ceil(im.images.length / this.columns);
  3390.                 if (this.nc && im.images.length > 0) {
  3391.                     this.nc = false;
  3392.                     this.img && this.img.Dispose();
  3393.                     this.img = null;
  3394.                     this.img = gdi.CreateImage(Math.min(this.columns, im.images.length) * this.px, this.img_rows * this.px);
  3395.                     var temp_gr = this.img.GetGraphics();
  3396.                     temp_gr.SetInterpolationMode(7);
  3397.                     var ci = 0;
  3398.                     var row, col;
  3399.                     for (row = 0; row < this.img_rows; row++) {
  3400.                         for (col = 0; col < this.columns; col++) {
  3401.                             if (ci == im.images.length) continue;
  3402.                             p.draw_image(temp_gr, im.images[ci], col * this.px, row * this.px, this.px, this.px, "crop top");
  3403.                             ci++;
  3404.                         }
  3405.                     }
  3406.                     this.img.ReleaseGraphics(temp_gr);
  3407.                     temp_gr = null;
  3408.                 }
  3409.                 break;
  3410.             case this.mode == "left":
  3411.             case this.mode == "right":
  3412.                 this.x = this.mode == "left" ? 0 : p.w - this.px;
  3413.                 this.y = 0;
  3414.                 this.w = this.px;
  3415.                 this.h = p.h;
  3416.                 im.x = this.mode == "right" ? 0 : this.px;
  3417.                 im.y = 0;
  3418.                 im.w = p.w - this.px;
  3419.                 im.h = p.h;
  3420.                 this.rows = Math.ceil(this.h / this.px);
  3421.                 if (this.nc && im.images.length > 0) {
  3422.                     this.nc = false;
  3423.                     this.img && this.img.Dispose();
  3424.                     this.img = null;
  3425.                     this.img = gdi.CreateImage(this.px, this.px * im.images.length);
  3426.                     var temp_gr = this.img.GetGraphics();
  3427.                     temp_gr.SetInterpolationMode(7);
  3428.                     for (i = 0; i < im.images.length; i++) {
  3429.                         p.draw_image(temp_gr, im.images[i], 0, i * this.px, this.px, this.px, "crop top");
  3430.                     }
  3431.                     this.img.ReleaseGraphics(temp_gr);
  3432.                     temp_gr = null;
  3433.                 }
  3434.                 break;
  3435.             case this.mode == "bottom":
  3436.             case this.mode == "top":
  3437.                 this.x = 0;
  3438.                 this.y = this.mode == "top" ? 0 : p.h - this.px;
  3439.                 this.w = p.w;
  3440.                 this.h = this.px;
  3441.                 im.x = 0;
  3442.                 im.y = this.mode == "bottom" ? 0 : this.px;
  3443.                 im.w = p.w;
  3444.                 im.h = p.h - this.px;
  3445.                 this.columns = Math.ceil(this.w / this.px);
  3446.                 if (this.nc && im.images.length > 0) {
  3447.                     this.nc = false;
  3448.                     this.img && this.img.Dispose();
  3449.                     this.img = null;
  3450.                     this.img = gdi.CreateImage(this.px * im.images.length, this.px);
  3451.                     var temp_gr = this.img.GetGraphics();
  3452.                     temp_gr.SetInterpolationMode(7);
  3453.                     for (i = 0; i < im.images.length; i++) {
  3454.                         p.draw_image(temp_gr, im.images[i], i * this.px, 0, this.px, this.px, "crop top");
  3455.                     }
  3456.                     this.img.ReleaseGraphics(temp_gr);
  3457.                     temp_gr = null;
  3458.                 }
  3459.                 break;
  3460.         }
  3461.     }
  3462.    
  3463.     this.wheel = function(step) {
  3464.         switch(true) {
  3465.             case !this.trace(p.mx, p.my):
  3466.             case this.overlay:
  3467.                 return false;
  3468.             case this.mode == "grid":
  3469.                 if (this.img_rows < this.rows) return true;
  3470.                 this.offset -= step;
  3471.                 if (this.offset < 0) this.offset = 0;
  3472.                 if (this.offset > this.img_rows - this.rows) this.offset = this.img_rows - this.rows + 1;
  3473.                 break;
  3474.             case this.mode == "left":
  3475.             case this.mode == "right":
  3476.                 if (im.images.length < this.rows) return true;
  3477.                 this.offset -= step;
  3478.                 if (this.offset < 0) this.offset = 0;
  3479.                 if (this.rows + this.offset > im.images.length) this.offset = im.images.length - this.rows + 1;
  3480.                 break;
  3481.             case this.mode == "bottom":
  3482.             case this.mode == "top":
  3483.                 if (im.images.length < this.columns) return true;
  3484.                 this.offset -= step;
  3485.                 if (this.offset < 0) this.offset = 0;
  3486.                 if (this.columns + this.offset > im.images.length) this.offset = im.images.length - this.columns + 1;
  3487.                 break;
  3488.         }
  3489.         window.RepaintRect(this.x, this.y, this.w, this.h);
  3490.         return true;
  3491.     }
  3492.    
  3493.     this.move = function(x, y) {
  3494.         switch(true) {
  3495.             case !this.trace(x, y):
  3496.                 window.SetCursor(IDC_ARROW);
  3497.                 return false;
  3498.             case this.overlay:
  3499.                 window.SetCursor(IDC_ARROW);
  3500.                 return true;
  3501.             case this.mode == "grid":
  3502.                 this.index = Math.floor((x - this.x) / this.px) + (Math.floor((y - this.y) / this.px) * this.columns) + (this.offset * this.columns);
  3503.                 break;
  3504.             case this.mode == "left":
  3505.             case this.mode == "right":
  3506.                 this.index = Math.floor((y - this.y) / this.px) + this.offset;
  3507.                 break;
  3508.             case this.mode == "bottom":
  3509.             case this.mode == "top":
  3510.                 this.index = Math.floor((x - this.x) / this.px) + this.offset;
  3511.                 break;
  3512.         }
  3513.         window.SetCursor(this.index < im.images.length ? IDC_HAND : IDC_ARROW);
  3514.         return true;
  3515.     }
  3516.    
  3517.     this.lbtn_up = function(x, y) {
  3518.         switch(true) {
  3519.             case !this.trace(x, y):
  3520.                 return false;
  3521.             case this.mode == "grid" && this.overlay && im.trace(x, y):
  3522.                 this.overlay = false;
  3523.                 window.Repaint();
  3524.                 break;
  3525.             case this.mode == "grid" && this.index < im.images.length && !this.overlay:
  3526.                 this.overlay = true;
  3527.                 im.index = this.index;
  3528.                 window.Repaint();
  3529.                 break;
  3530.             case this.overlay:
  3531.                 break;
  3532.             case this.index < im.images.length:
  3533.                 im.index = this.index;
  3534.                 window.Repaint();
  3535.         }
  3536.         return true;
  3537.     }
  3538.    
  3539.     this.lbtn_dblclk = function(x, y) {
  3540.         if (!im.trace(x, y) || th.mode == "grid") return false;
  3541.         p.run("\"" + im.files[im.index] + "\"");
  3542.         return true;
  3543.     }
  3544.    
  3545.     this.nc = false;
  3546.     this.mode = window.GetProperty("thumbs_mode", p.check_feature("now_playing") ? "off" : "bottom");
  3547.     this.px = window.GetProperty("thumbs_px", 100);
  3548.     this.img = null;
  3549. }
  3550.  
  3551. //json2.js
  3552. if(typeof JSON!=='object'){JSON={};}
  3553. (function(){'use strict';function f(n){return n<10?'0'+n:n;}
  3554. if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
  3555. f(this.getUTCMonth()+1)+'-'+
  3556. f(this.getUTCDate())+'T'+
  3557. f(this.getUTCHours())+':'+
  3558. f(this.getUTCMinutes())+':'+
  3559. f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
  3560. var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
  3561. function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
  3562. if(typeof rep==='function'){value=rep.call(holder,key,value);}
  3563. switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
  3564. gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
  3565. v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
  3566. if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
  3567. v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
  3568. if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
  3569. rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
  3570. return str('',{'':value});};}
  3571. if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
  3572. return reviver.call(holder,key,value);}
  3573. text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
  3574. ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
  3575. if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
  3576. throw new SyntaxError('JSON.parse');};}}());
  3577.  
  3578. /*
  3579. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  3580. * Digest Algorithm, as defined in RFC 1321.
  3581. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  3582. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  3583. * Distributed under the BSD License
  3584. * See http://pajhome.org.uk/crypt/md5 for more info.
  3585. */
  3586. var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}
  3587. function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}
  3588. function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}
  3589. function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}
  3590. function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}
  3591. var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}
  3592. var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}
  3593. function rstr2hex(c){try{hexcase}catch(g){hexcase=0}
  3594. var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}
  3595. return b}
  3596. function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}
  3597. if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}
  3598. return b}
  3599. function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}
  3600. for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}
  3601. return a}
  3602. function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}
  3603. return a}
  3604. function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}
  3605. return Array(o,n,m,l)}
  3606. function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}
  3607. function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}
  3608. function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}
  3609. function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}
  3610. function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}
  3611. function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}
  3612. function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
  3613. var p = new panel("Last.fm & Wikipedia Biography", ["metadb", "lastfm_wiki", "remap"]);
  3614. var b = new buttons();
  3615. var t = new text(0, -20, p.w - 0);
  3616.  
  3617. b.buttons.lastfm = new button(p.w - 56, 8, 50, 18, {normal: ""}, function() { p.browser(""); }, "");
  3618.  
  3619. on_item_focus_change();
  3620.  
  3621. function on_size() {
  3622.     p.size();
  3623.     t.w = p.w - 1;
  3624.     t.h = p.h + 34;
  3625.     t.size();
  3626. }
  3627.  
  3628. function on_paint(gr) {
  3629.     p.draw_background(gr);
  3630.     //p.header(gr, p.artist);
  3631.     lastfm.x = t.source == "last.fm" ? p.w -56 : -100;
  3632.     b.draw(gr);
  3633.     if (!p.metadb) p.centre_text(gr, "", p.normal_font, p.textcolour, 0, 0, t.w, t.h);
  3634.     else t.draw(gr);
  3635. }
  3636.  
  3637. function on_metadb_changed() {
  3638.     if (t.metadb_changed()) {
  3639.         //b.buttons.lastfm.func = function() { p.browser(t.url); };
  3640.         //b.buttons.lastfm.tiptext = t.url;
  3641.     }
  3642. }
  3643.  
  3644. function on_mouse_wheel(step) {
  3645.     t.wheel(step);
  3646. }
  3647.  
  3648. function on_mouse_move(x, y) {
  3649.     p.move(x, y);
  3650.     if (b.move(x, y)) return;
  3651.     if (t.move(x, y)) return;
  3652. }
  3653.  
  3654. function on_mouse_lbtn_up(x, y) {
  3655.     if (b.lbtn_up(x, y)) return;
  3656.     if (t.lbtn_up(x, y)) return;
  3657. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement