PCCar.ru - Ваш автомобильный компьютер

Вернуться   PCCar.ru - Ваш автомобильный компьютер > MP3Car ТехИнфа > АвтоЗвук

Ответ
 
Опции темы Поиск в этой теме
Старый 28.06.2016, 17:24   #1961
duzzy
Гуру
 
Регистрация: 01.06.2013
Регион: 78, 98
Машина: SUBARU Impreza WRX
Сообщений: 1,766
duzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond repute
По умолчанию

Цитата:
Сообщение от seriousstas Посмотреть сообщение
Область попадания прибавляется расстоянием до текста .
"их" я увеличил в пару раз - можно и 10 раз увеличить
Ну можно и больше сделать, надо в машине смотреть как оно будет с пальцем
Сделай проще вынеси настройки зон и "точки" в Properties, будет проще настраивать.
например:
(переменные можешь обозвать как тебе нужно, ниже просто пример)

var click_expand_zone = window.GetProperties("Зона кнопки Развернуть", 30);
var btn_expand_size = window.GetProperties("Кнопка Развернуть размер ", 30);

и прописываешь эти переменные click_expand_zone, btn_expand_size в то место где ты цифры меняешь... бонус в том чтоб в редактор не лазить без конца при подгоне

Забыл сказать, у тебя прокрутка страницы целиком включена, т.е. постраничная прокрутка. Ее можно отключить в настройках.

--------------------------------

обманул тебя))) шрифт не Segoe UI Symbol а Wingdings для этих папочек...открытой и закрытой папки.
duzzy вне форума   Ответить с цитированием
Старый 28.06.2016, 17:39   #1962
seriousstas
Бывалый писикарщик
 
Регистрация: 14.06.2013
Регион: Украина
Машина: Nissan Qashqai+2
Сообщений: 3,424
seriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant future
По умолчанию

Цитата:
Сделай проще
Думал, но ..
Все не так просто - там по линиям ещё несколько параметров,
отдельно настраивается "+" и отдельно "-" и тд..
Выйдет около 10-ка настроек - проще сноски сделать и быстро подогнать в скрипте ..
Цитата:
Забыл сказать, у тебя прокрутка страницы целиком включена
Я думал прокрутка взбесилась

Цитата:
не выбивается из общей массы))), при взгляде на панель не сосредотачиваешь внимание на них
Ну хорошо , а как Тебе такой вариант с полупрозрачними "точками" )
:
Код:
// ==PREPROCESSOR==
// @name "Library Tree"
// @author "Wilb"
// @version "0.8"
// ==/PREPROCESSOR==

//if (!("GetQueryItems" in fb))
	//fb.ShowPopupMessage("Library Tree requires:\n\nJScript Panel 1.1.0+\n\n(https://github.com/19379/foo-jscript-panel/releases)");

String.prototype.trim = function () {
	return this.replace(/^\s+|[\n\s]+$/g, "");
}

//============================
var g_color_normal_bg = 0;

ppt = {

	showwallpaper : window.GetProperty("_DISPLAY: Show Wallpaper", true),
	wallpaperblurred : window.GetProperty("_DISPLAY: Wallpaper Blurred", true),
	wallpaperblurvalue : window.GetProperty("_DISPLAY: Wallpaper Blur value", 2.00) / 1.6,
	wallpapermode : window.GetProperty("_DISPLAY: Wallpaper Mode", false),
	wallpaperpath : window.GetProperty("_DISPLAY: Default Wallpaper Path", ".\\wsh_br3tt\\jsplaylist\\images\\default.jpg"),
	wallpaperalfa : window.GetProperty("_DISPLAY: Wallpaper Alfa", 150),
	wallpaperoverlayalfa : window.GetProperty("_DISPLAY: Wallpaper Overlay Alfa", 50),
};

var brw = null;
var wpp_img_info = {
	orient : 0,
	cut : 0,
	cut_offset : 0,
	ratio : 0,
	x : 0,
	y : 0,
	w : 0,
	h : 0
};
var g_wallpaperImg = null;
//===================================
function userinterface() {
	var blend = "",
	custom_col = window.GetProperty("_CUSTOM COLOURS: USE", false),
	linecol = window.GetProperty(" Node: Lines: Hide-0 Grey-1 Blend-2 Text-3", 3),
	mix = 0,
	orig_font_sz = 16,
	s_col = window.GetProperty(" Search Style: Fade-0 Blend-1 Norm-2 Highlight-3", 1),
	s_linecol = window.GetProperty(" Search: Line Colour: Grey-0 Blend-1 Text-2", 2),
	sp = 6,
	sp1 = 6,
	sp2 = 6,
	sum = 0,
	sy = window.GetProperty(" Node: Custom Symbols: Collapse|Expand", "[-]|[+]").split("|"),
	zoom_font_sz = 16,
	zoom = 100;
	this.b1 = 0x04ffffff;
	this.b2 = 0x04000000;
	this.backcol = "";
	this.backcol_h = "";
	this.backcolsel = "";
	this.backcoltrans = "";
	this.bg = false;
	this.collapse = sy[0].trim();
	this.dui = window.InstanceType;
	this.expand = sy[1].trim();
	this.fill = 0;
	this.font;
	this.framecol = "";
	this.h = 0;
	this.j_font;
	this.linecol = "";
	this.pen = 1;
	this.pen_c = 0x55888888;
	this.row_h = 20;
	this.s_font;
	this.s_linecol = "";
	this.searchcol = "";
	this.sel = 3;
	this.symbol_w = 17;
	this.textcol = "";
	this.textcol_h = "";
	this.textselcol = "";
	this.textsymbcol = "";
	this.txt_box = "";
	this.w = 0;
	this.alternate = window.GetProperty(" Row Stripes", false);
	this.local = typeof conf === 'undefined' ? false : true;
	this.margin = window.GetProperty(" Margin", 8);
	this.node_style = !window.GetProperty(" Node: Custom Symbols (No Lines)", false);
	this.pad = window.GetProperty(" Tree Indent", 19);
	this.scrollbar_show = window.GetProperty(" Scrollbar Show", true);
	this.scr_w = this.scrollbar_show ? window.GetProperty(" Scrollbar Width", 12) : 0;
	window.SetProperty("_CUSTOM COLOURS: EMPTY = DEFAULT", "R-G-B (any) or R-G-B-A (not Text...), e.g. 255-0-0");
	var R = function (c) {
		return c >> 16 & 0xff;
	};
	var G = function (c) {
		return c >> 8 & 0xff;
	};
	var B = function (c) {
		return c & 0xff;
	}
	var get_blend = function (c1, c2, f) {
		var nf = 1 - f,
		r = (R(c1) * f + R(c2) * nf),
		g = (G(c1) * f + G(c2) * nf),
		b = (B(c1) * f + B(c2) * nf);
		return RGB(r, g, b);
	}
	var set_custom_col = function (c, t) {
		if (!custom_col)
			return "";
		try {
			var cc = "",
			col = [];
			col = c.split("-");
			if (col.length != 3 && col.length != 4)
				return "";
			switch (t) {
			case 0:
				cc = RGB(col[0], col[1], col[2]);
				break;
			case 1:
				switch (col.length) {
				case 3:
					cc = RGB(col[0], col[1], col[2]);
					break;
				case 4:
					cc = RGBA(col[0], col[1], col[2], col[3]);
					break;
				}
				break;
			}
			return cc;
		} catch (e) {
			return ""
		};
	}
	this.get_textselcol = function (c) {
		var cc = [R(c), G(c), B(c)];
		var ccc = [];
		for (var i = 0; i < cc.length; i++) {
			ccc[i] = cc[i] / 255;
			ccc[i] = ccc[i] <= 0.03928 ? ccc[i] / 12.92 : Math.pow(((ccc[i] + 0.055) / 1.055), 2.4);
		}
		var L = 0.2126 * ccc[0] + 0.7152 * ccc[1] + 0.0722 * ccc[2];
		if (L > 0.31)
			return RGB(0, 0, 0);
		else
			return RGB(255, 255, 255);
	}
	this.outline = function (c, but) {
		if (but) {
			if (window.IsTransparent || R(c) + G(c) + B(c) > 30)
				return RGBA(0, 0, 0, 36);
			else
				return RGBA(255, 255, 255, 36);
		} else if (R(c) + G(c) + B(c) > 255 * 1.5)
			return RGB(30, 30, 10);
		else
			return RGB(225, 225, 245);
	}
	this.reset_colors = function () {
		this.backcol = "";
		this.backcol_h = "";
		this.backcolsel = "";
		this.backcoltrans = "";
		this.framecol = "";
		this.linecol = "";
		this.s_linecol = "";
		this.searchcol = "";
		this.textcol = "";
		this.textcol_h = "";
		this.textselcol = "";
		this.textsymbcol = "";
		this.txt_box = "";
	}

	this.get_colors = function () {
		this.backcol = set_custom_col(window.GetProperty("_Custom.Colour Background", ""), 1);
		this.backcol_h = set_custom_col(window.GetProperty("_Custom.Colour Background Highlight", ""), 1);
		this.backcolsel = set_custom_col(window.GetProperty("_Custom.Colour Background Selected", ""), 1);
		this.linecol = set_custom_col(window.GetProperty("_Custom.Colour Node Lines", ""), 1);
		this.txt_box = set_custom_col(window.GetProperty("_Custom.Colour Search Name", ""), 0);
		this.s_linecol = set_custom_col(window.GetProperty("_Custom.Colour Search Line", ""), 1);
		this.searchcol = set_custom_col(window.GetProperty("_Custom.Colour Search Text", ""), 0);
		this.framecol = set_custom_col(window.GetProperty("_Custom.Colour Frame Highlight", ""), 1);
		this.textcol = set_custom_col(window.GetProperty("_Custom.Colour Text", ""), 0);
		this.textcol_h = set_custom_col(window.GetProperty("_Custom.Colour Text Highlight", ""), 0);
		this.textselcol = set_custom_col(window.GetProperty("_Custom.Colour Text Selected", ""), 0);
		this.textsymbcol = set_custom_col(window.GetProperty("_Custom.Colour Node Symbol", ""), 0);
		this.backcoltrans = set_custom_col(window.GetProperty("_Custom.Colour Transparent Fill", ""), 1);

		if (this.dui) { // custom colour mapping: DUI colours can be remapped by changing the numbers (0-3)
			if (this.textcol === "")
				this.textcol = window.GetColorDUI(0);
			if (this.backcol === "")
				this.backcol = window.GetColorDUI(1);
			if (this.textcol_h === "")
				this.textcol_h = window.GetColorDUI(2);
			if (this.backcolsel === "")
				this.backcolsel = window.GetColorDUI(3);
		} else { // custom colour mapping: CUI colours can be remapped by changing the numbers (0-6)
			if (this.textcol === "")
				this.textcol = window.GetColorCUI(0);
			if (this.backcol === "")
				this.backcol = window.GetColorCUI(3);
			if (this.textcol_h === "")
				this.textcol_h = window.GetColorCUI(2);
			if (this.backcolsel === "")
				this.backcolsel = window.GetColorCUI(4);
			if (this.textselcol === "")
				this.textselcol = window.GetColorCUI(1);
		}
		if (this.backcol_h === "")
			this.backcol_h = 0x1E30AFED;
		if (s_linecol == 1 && window.IsTransparent && !this.dui)
			s_linecol = 0;
		if (this.framecol === "")
			this.framecol = 0xA330AFED;
		var blend = get_blend(this.backcol == 0 ? 0xff000000 : this.backcol, this.textcol, 0.75);
		var ln_col = [0, RGBA(136, 136, 136, 85), blend, this.textcol];
		if (this.linecol === "")
			this.linecol = ln_col[linecol];
		if (this.searchcol === "")
			this.searchcol = s_col < 3 ? this.textcol : this.textcol_h;
		if (this.textselcol === "")
			this.textselcol = this.get_textselcol(this.backcolsel);
		blend = get_blend(this.backcol == 0 ? 0xff000000 : this.backcol, !s_col || s_col == 2 ? this.textcol : this.textcol_h, 0.75);
		if (this.txt_box === "")
			this.txt_box = s_col < 2 ? get_blend(!s_col ? this.textcol : this.textcol_h, this.backcol == 0 ? 0xff000000 : this.backcol, !s_col ? 0.65 : 0.7) : s_col == 2 ? this.textcol : this.textcol_h;
		if (!this.node_style && this.textsymbcol === "")
			this.textsymbcol = this.textcol;
		if (this.s_linecol === "")
			this.s_linecol = s_linecol == 0 ? RGBA(136, 136, 136, 85) : s_linecol == 1 ? blend : this.txt_box;
		if (window.IsTransparent && this.backcoltrans) {
			this.bg = true;
			this.backcol = this.backcoltrans
		}
		if (!window.IsTransparent || this.dui) {
			this.bg = true;
			if ((R(this.backcol) + G(this.backcol) + B(this.backcol)) > 759)
				this.b2 = 0x06000000;
		}
		if (this.local) {
			this.textcol = c_textcol;
			this.textcol_h = c_textcol_h;
			this.textselcol = c_textselcol;
			this.backcolsel = c_backcolsel;
			this.alternate = c_alternate;
			this.fill = c_fill;
			this.pen = c_pen;
			this.pen_c = c_pen_c;
			this.searchcol = this.txt_box = c_txt_box;
			this.b1 = c_b1;
			this.b2 = c_b2;
		}
		this.ibeamcol1 = window.IsTransparent ? 0xffe1e1f5 : this.outline(this.backcol);
		this.ibeamcol2 = window.IsTransparent || !this.backcolsel ? 0xff0099ff : this.backcolsel != this.searchcol ? this.backcolsel : 0xff0099ff;

	}
	this.get_colors();

	this.get_font = function () {
		if (this.dui)
			this.font = window.GetFontDUI(2);
		else
			this.font = window.GetFontCUI(0);
		try {
			this.font.Name;
			this.font.Size;
			this.font.Style;
		} catch (e) {
			this.font = gdi.Font("Segoe UI", 16, 0);
			p.trace("JScript Panel is unable to use your default font. Using Segoe UI at default size & style instead");
		}
		orig_font_sz = window.GetProperty("SYSTEM.Font Size", 18);
		if (this.font.Size != orig_font_sz)
			window.SetProperty(" Zoom Font Size (%)", 225);
		orig_font_sz = this.font.Size;
		window.SetProperty("SYSTEM.Font Size", this.font.Size)
		zoom = window.GetProperty(" Zoom Font Size (%)", 100);
		zoom_font_sz = Math.max(Math.round(orig_font_sz * zoom / 100), 1);
		this.font = gdi.Font(this.font.Name, zoom_font_sz, this.font.Style);
		window.SetProperty(" Zoom Font Size (%)", Math.round(zoom_font_sz / orig_font_sz * 100));
		this.s_font = gdi.Font(this.font.Name, this.font.Size, 2);
		this.j_font = gdi.Font(this.font.Name, this.font.Size * 1.5, 1);
		if (this.local) {
			this.font = c_font;
			this.s_font = c_s_font;
			this.j_font = gdi.Font(this.font.Name, this.font.Size * 1.5, 1);
			this.margin = c_margin;
			this.pad = c_pad;
			this.row_h = c_row_h;
			this.scr_w = c_scr_w;
		}
		this.calc_text();
	}

	this.calc_text = function () {
		var i = gdi.CreateImage(1, 1),
		g = i.GetGraphics();
		this.row_h = Math.round(g.CalcTextHeight("String", this.font)) + window.GetProperty(" Row Vertical Item Padding", 3);
		sp = Math.round(g.CalcTextWidth(" ", this.font));
		sp1 = Math.max(Math.round(sp * 1.5), 6);
		sp2 = Math.round(g.CalcTextWidth(this.expand, this.font));
		this.symbol_w = this.node_style ? 22 + sp1 : sp + sp2;
		this.sel = (this.node_style ? sp1 : sp) / 2;
		this.tt = this.node_style ? -Math.ceil(sp1 / 2 - 3) + sp1 : sp;
		i.ReleaseGraphics(g);
		i.Dispose();
	}

	this.wheel = function (step) {
		if (p.m_y > p.s_h) {
			zoom_font_sz += step;
			zoom_font_sz = Math.max(zoom_font_sz, 1);
			this.font = gdi.Font(this.font.Name, zoom_font_sz, this.font.Style);
			this.s_font = gdi.Font(this.font.Name, this.font.Size, 2);
			this.j_font = gdi.Font(this.font.Name, this.font.Size * 1.5, 1);
			this.calc_text();
			p.on_size();
			jS.on_size();
			pop.create_tooltip();
			if (p.s_show || this.scrollbar_show)
				but.refresh(true);
			sbar.reset();
			window.Repaint();
			window.SetProperty(" Zoom Font Size (%)", Math.round(zoom_font_sz / orig_font_sz * 100));
		} else {
			if (p.scale < 0.7)
				return;
			p.scale += step * 0.1;
			p.scale = Math.max(p.scale, 0.7);
			p.f_font = gdi.Font("segoe ui", p.scale > 1.05 ? Math.floor(11 * p.scale) : 11 * p.scale, 1);
			p.f_but_ft = gdi.Font("segoe ui", p.scale > 1.05 ? Math.floor(9 * p.scale) : 9 * p.scale, 1);
			p.calc_text();
			but.refresh(true);
			window.SetProperty(" Zoom Filter Size (%)", Math.round(p.scale * 100));
			p.search_paint();
		}
	}
}
var ui = new userinterface();

function on_colors_changed() {
	ui.reset_colors();
	ui.get_colors();
	if (p.s_show) {
		but.create_images();
		but.refresh();
	}
	window.Repaint();
}
function on_font_changed() {
	ui.get_font();
	sbar.reset();
	p.on_size();
	pop.create_tooltip();
	if (p.s_show || ui.scrollbar_show)
		but.refresh(true);
	window.Repaint();
}

function scrollbar() {
	var smoothness = 0.3439;
	this.count = -1;
	this.draw_timer = false;
	this.hover = false;
	this.s1 = 0;
	this.s2 = 0;
	this.scroll_step = window.GetProperty(" Scroll - Mouse Wheel: Page Scroll", false);
	this.scroll_step_mouse = window.GetProperty(" Scroll - Mouse Wheel: Step", 1);
	this.smooth = window.GetProperty(" Scroll: Smooth Scroll", true);
	this.smooth_scroll_interval = window.GetProperty(" Scroll: Smooth Scroll Interval", 30);
    this.timer_but = false;
	this.x;
	this.y;
	this.w;
	this.h;
	this.bar_ht = 0;
	this.but_h;
	this.bar_y = 0;
	this.row_count = 0;
	this.scroll = 0;
	this.delta = 0;
	this.ratio = 1;
	this.rows_drawn = 0;
	this.row_h;
	this.scrollbar_height = 0;
	this.scrollable_lines = 0;
	this.scrollbar_travel = 0;
	this.b_is_dragging = false;
	this.drag_distance_per_row;
	this.initial_drag_y = 0; // dragging
	this.draw = function (gr) {
		if (this.scrollable_lines > 0) {
			try {
				gr.FillSolidRect(this.x, this.y + this.bar_y, this.w, this.bar_ht, RGBA(200, 200, 200, !this.hover && !this.b_is_dragging ? 75 : 192));
			} catch (e) {}

		}
	}
	this.leave = function () {
		if (this.b_is_dragging)
			return;
		this.hover = false;
		this.hover_o = false;
		window.RepaintRect(this.x, this.y, this.w, this.h);
	}
	this.nearest = function (y) {
		y = (y - this.but_h) / this.scrollbar_height * this.scrollable_lines * this.row_h;
		y = y / this.row_h;
		y = Math.round(y) * this.row_h;
		return y;
	}
	this.reset = function () {
		this.delta = this.scroll = this.s1 = this.s2 = 0;
		this.metrics(this.x, this.y, this.w, this.h, this.rows_drawn, this.row_h);
	}
	this.scroll_timer = function () {
		var that = this;
		this.draw_timer = window.SetInterval(function () {
				if (p.w < 1 || !window.IsVisible)
					return;
				that.smooth_scroll();
			}, this.smooth_scroll_interval);//smooth_scroll_interval def 16
	}
	this.set_rows = function (row_count) {
		this.row_count = row_count;
		this.metrics(this.x, this.y, this.w, this.h, this.rows_drawn, this.row_h);
	}
	this.wheel = function (step) {
		this.check_scroll(this.scroll + step *  - (this.scroll_step ? this.rows_drawn : this.scroll_step_mouse) * this.row_h);
	}

	this.metrics = function (x, y, w, h, rows_drawn, row_h) {
		this.x = x;
		this.y = Math.round(y);
		this.w = w;
		this.h = h;
		this.rows_drawn = rows_drawn;
		if (!p.autofit)
			this.rows_drawn = Math.floor(this.rows_drawn);
		this.row_h = row_h;
		this.but_h = ui.scr_w;
		// draw info
		this.scrollbar_height = this.h - this.but_h * 2;
		this.bar_ht = Math.max(Math.round(this.scrollbar_height * this.rows_drawn / this.row_count), 12);
		this.scrollbar_travel = this.scrollbar_height - this.bar_ht;
		// scrolling info
		this.scrollable_lines = this.row_count - this.rows_drawn;
		this.ratio = this.row_count / this.scrollable_lines;
		this.bar_y = this.but_h + this.scrollbar_travel * (this.delta * this.ratio) / (this.row_count * this.row_h);
		this.drag_distance_per_row = this.scrollbar_travel / this.scrollable_lines;
	}

	this.lbtn_up = function (p_x, p_y) {
		var x = p_x - this.x;
		var y = p_y - this.y;
		if (this.b_is_dragging)
			this.b_is_dragging = false;
		this.initial_drag_y = 0;
		if (this.timer_but) {
			window.ClearInterval(this.timer_but);
			this.timer_but = false;
		};
		this.count = -1;
	}

	this.lbtn_dn = function (p_x, p_y) {
		var x = p_x - this.x;
		var y = p_y - this.y;
		if (x < 0 || x > this.w || y < 0 || y > this.h || this.row_count <= this.rows_drawn)
			return;
		if (y < this.but_h || y > this.h - this.but_h)
			return;
		if (y < this.bar_y)
			var dir = 1; // above bar
		else if (y > this.bar_y + this.bar_ht)
			var dir = -1; // below bar
		if (y < this.bar_y || y > this.bar_y + this.bar_ht)
			this.check_scroll(this.nearest(y));
		else { // on bar
			this.b_is_dragging = true;
			this.initial_drag_y = y - this.bar_y;
		}
	}

	this.move = function (p_x, p_y) {
		var x = p_x - this.x;
		var y = p_y - this.y;
		if (x < 0 || x > this.w || y > this.bar_y + this.bar_ht || y < this.bar_y)
			this.hover = false;
		else
			this.hover = true;
		if (this.hover != this.hover_o)
			window.RepaintRect(this.x, this.y, this.w, this.h);
		this.hover_o = this.hover;
		if (!this.b_is_dragging || this.row_count <= this.rows_drawn)
			return;
		this.check_scroll(Math.round((y - this.initial_drag_y - this.but_h) / this.drag_distance_per_row) * this.row_h);
	}

	this.check_scroll = function (new_scroll) {
		var s = Math.max(0, Math.min(new_scroll, this.scrollable_lines * this.row_h));
		if (s == this.scroll)
			return;
		this.scroll = s;
		if (this.smooth) {
			if (!this.draw_timer)
				this.scroll_timer();
		} else {
			this.delta = this.scroll;
			this.bar_y = this.but_h + this.scrollbar_travel * (this.delta * this.ratio) / (this.row_count * this.row_h);
			p.tree_paint();
		}
	}

	this.smooth_scroll = function () {
		if (Math.abs(this.scroll - this.delta) > 0.5) {
			this.s1 += (this.scroll - this.s1) * smoothness;
			this.s2 += (this.s1 - this.s2) * smoothness;
			this.delta += (this.s2 - this.delta) * smoothness;
			this.bar_y = this.but_h + this.scrollbar_travel * (this.delta * this.ratio) / (this.row_count * this.row_h);
			p.tree_paint();
		} else if (this.draw_timer) {
			window.ClearTimeout(this.draw_timer);
			this.draw_timer = false;
		}
	}

	this.but = function (dir) {
		this.check_scroll(this.scroll + (dir * -this.row_h));
		if (!this.timer_but) {
			var that = this;
			this.timer_but = window.SetInterval(function () {
					if (that.count > 6) {
						that.check_scroll(that.scroll + (dir * -that.row_h));
					} else
						that.count++;
				}, 40);
		}
	}
}
var sbar = new scrollbar();

function panel_operations() {
	var def_ppt = window.GetProperty(" View by Folder Structure: Name // Pattern", "View by Folder Structure // Pattern Not Configurable");
	var DT_LEFT = 0x00000000,
	DT_CENTER = 0x00000001,
	DT_RIGHT = 0x00000002,
	DT_VCENTER = 0x00000004,
	DT_SINGLELINE = 0x00000020,
	DT_CALCRECT = 0x00000400,
	DT_NOPREFIX = 0x00000800,
	DT_END_ELLIPSIS = 0x00008000,
	grps = [],
	i = 0,
	sort = "";
	var view_ppt = [
		window.GetProperty(" View 01: Name // Pattern", "View by Artist // %artist%|%album%|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%"),
		window.GetProperty(" View 02: Name // Pattern", "View by Album Artist // %album artist%|%album%|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%"),
		window.GetProperty(" View 03: Name // Pattern", "View by Album Artist - Album // [%album artist% - ]['['%date%']' ]%album%|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%"),
		window.GetProperty(" View 04: Name // Pattern", "View by Album // %album%[ '['%album artist%']']|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%"),
		window.GetProperty(" View 05: Name // Pattern", "View by Genre // %<genre>%|[%album artist% - ]%album%|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%"),
		window.GetProperty(" View 06: Name // Pattern", "View by Year // %date%|[%album artist% - ]%album%|[[%discnumber%.]%tracknumber%. ][%track artist% - ]%title%")
	];
	var nm = "",
	ppt_l = view_ppt.length + 1;
	for (i = ppt_l; i < ppt_l + 93; i++) {
		nm = window.GetProperty(" View " + (i < 10 ? "0" + i : i) + ": Name // Pattern");
		if (nm && nm != " // ")
			view_ppt.push(window.GetProperty(" View " + (i < 10 ? "0" + i : i) + ": Name // Pattern"));
	}

	var filter_ppt = [
		window.GetProperty(" View Filter 01: Name // Query", "Filter // Query Not Configurable"),
		window.GetProperty(" View Filter 02: Name // Query", "Lossless // \"$info(encoding)\" IS lossless"),
		window.GetProperty(" View Filter 03: Name // Query", "Lossy // \"$info(encoding)\" IS lossy"),
		window.GetProperty(" View Filter 04: Name // Query", "Missing Replaygain // %replaygain_track_gain% MISSING"),
		window.GetProperty(" View Filter 05: Name // Query", "Never Played // %play_count% MISSING"),
		window.GetProperty(" View Filter 06: Name // Query", "Played Often // %play_count% GREATER 9"),
		window.GetProperty(" View Filter 07: Name // Query", "Recently Added // %added% DURING LAST 2 WEEKS"),
		window.GetProperty(" View Filter 08: Name // Query", "Recently Played // %last_played% DURING LAST 2 WEEKS"),
		window.GetProperty(" View Filter 09: Name // Query", "Top Rated // rating IS 5")
	];
	var filt_l = filter_ppt.length + 1;
	for (i = filt_l; i < filt_l + 90; i++) {
		nm = window.GetProperty(" View Filter " + (i < 10 ? "0" + i : i) + ": Name // Query");
		if (nm && nm != " // ")
			filter_ppt.push(window.GetProperty(" View Filter " + (i < 10 ? "0" + i : i) + ": Name // Query"));
	}

	this.cc = DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX;
	this.l = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX;
	this.lc = DT_VCENTER | DT_CALCRECT | DT_NOPREFIX | DT_END_ELLIPSIS;
	this.rc = DT_RIGHT | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX;
	this.f_w = [];
	this.f_h = 0;
	this.f_x1 = 0;
	this.filt = [];
	this.folder_view = 10;
	this.grp = [];
	this.grp_sort = "";
	this.grp_split = [];
	this.grp_split_clone = [];
	this.grp_split_orig = [];
	this.f_menu = [];
	this.menu = [];
	this.multi_value = [];
	this.m_x = 0;
	this.m_y = 0;
	this.pos = -1;
	this.s_cursor = false;
	this.s_search = false;
	this.s_txt = "";
	this.s_x = 0;
	this.s_h = 0;
	this.s_w1 = 0;
	this.s_w2 = 0;
	this.single_br = false;
	this.statistics = false;
	this.tf = "";
	this.view = "";
	this.autofit = window.GetProperty(" Auto Fit", true);
	this.syncType = window.GetProperty(" Library Sync: Auto-0, Initialisation Only-1", 0);
	this.base = window.GetProperty(" Node: Show All Music", true);
	this.s_show = window.GetProperty(" Search: Hide-0, SearchOnly-1, Search+Filter-2", 0);
	if (!this.s_show)
		this.autofit = true;
	this.scale = Math.max(window.GetProperty(" Zoom Filter Size (%)", 100) / 100, 0.7);
	window.SetProperty(" Zoom Filter Size (%)", this.scale * 100);
	this.f_font = gdi.Font("segoe ui", this.scale > 1.05 ? Math.floor(11 * this.scale) : 11 * this.scale, 1);
	this.f_but_ft = gdi.Font("segoe ui", this.scale > 1.05 ? Math.floor(9 * this.scale) : 9 * this.scale, 1);
	this.filter_by = window.GetProperty("SYSTEM.Filter By", 0);
	this.items = function () {
		return plman.GetPlaylistItems(-1);
	};
	this.list = this.items();
	this.reset = window.GetProperty("SYSTEM.Reset Tree", false);
	this.search_paint = function () {
		window.RepaintRect(ui.margin, 0, ui.w - ui.margin, this.s_h);
	}
	this.set_statistics_mode = function () {
		this.statistics = false;
		var chk = this.grp[this.view_by].name + this.grp[this.view_by].type + this.filt[this.filter_by].name + this.filt[this.filter_by].type;
		chk = chk.toUpperCase();
		if (chk.indexOf("ADD") != -1 || chk.indexOf("PLAY") != -1 || chk.indexOf("RATING") != -1)
			this.statistics = true;
	}
	this.show_tracks = window.GetProperty(" Node: Show Tracks", true);
	this.sort = function (li) {
		switch (this.view_by) {
		case this.folder_view:
			li.OrderByPath();
			lib.it = li.Clone();
			li.OrderByRelativePath();
			break;
		default:
			var tfs = fb.TitleFormat(this.grp_sort);
			li.OrderByFormat(fb.TitleFormat(this.grp_sort), 1);
			break;
		}
	}
	this.tooltip = window.GetProperty(" Tooltips", false);
	this.trace = function (message) {
		var trace = true;
		if (trace)
			fb.trace("Library Tree: " + message);
	} // true enables fb.trace
	this.tree_paint = function () {
		window.RepaintRect(0, Math.floor(this.s_h), ui.w, Math.round(ui.h - this.s_h) + 1);
	}
	this.view_by = window.GetProperty("SYSTEM.View By", 6);
	this.calc_text = function () {
		this.f_w = [];
		var im = gdi.CreateImage(1, 1),
		g = im.GetGraphics();
		for (i = 0; i < this.filt.length; i++) {
			this.f_w[i] = g.CalcTextWidth(this.filt[i].name, this.f_font);
			if (!i)
				this.f_h = g.CalcTextHeight("String", this.f_font);
		}
		this.f_sw = g.CalcTextWidth("   Ў", this.f_but_ft);
		this.f_x1 = ui.w - ui.margin - this.f_w[this.filter_by] - this.f_sw;
		this.s_w2 = this.s_show > 1 ? this.f_x1 - this.s_x - 11 : this.s_w1 - Math.round(ui.row_h * 0.75) - this.s_x + 1;
		im.ReleaseGraphics(g);
		im.Dispose();
	}

	this.fields = function (view, filter) {
		this.filt = [];
		this.folder_view = 10;
		this.grp = [];
		this.grp_sort = "";
		this.multi_process = false;
		this.filter_by = filter;
		this.view_by = view;
		for (i = 0; i < view_ppt.length; i++) {
			if (view_ppt[i].indexOf("//") != -1) {
				grps = view_ppt[i].split("//");
				this.grp[i] = {
					name : grps[0].trim(),
					type : grps[1].replace(/\|\]/g, " - ]").replace(/\[\|/g, "[ - ").trim()
				}
			}
		}
		grps = [];
		for (i = 0; i < filter_ppt.length; i++) {
			if (filter_ppt[i].indexOf("//") != -1) {
				grps = filter_ppt[i].split("//");
				this.filt[i] = {
					name : grps[0].trim(),
					type : grps[1].trim()
				}
			}
		}
		i = this.grp.length;
		while (i--)
			if (!this.grp[i] || this.grp[i].name == "" || this.grp[i].type == "")
				this.grp.splice(i, 1);
		i = this.filt.length;
		while (i--)
			if (!this.filt[i] || this.filt[i].name == "" || this.filt[i].type == "")
				this.filt.splice(i, 1);
		this.grp[this.grp.length] = {
			name : def_ppt.split("//")[0].trim(),
			type : ""
		}
		this.folder_view = this.grp.length - 1;
		this.filter_by = Math.min(this.filter_by, this.filt.length - 1);
		this.view_by = Math.min(this.view_by, this.grp.length - 1);
		if (this.view_by != this.folder_view) {
			this.grp_split = this.grp[this.view_by].type.split("|");
			this.single_br = !this.base && (this.grp_split.length == 1 || this.grp_split.length == 2 && !this.show_tracks);
			this.tf = this.grp_split.length > 1 ? this.grp_split.pop() : this.grp_split[0];
			for (i = 0; i < this.grp_split.length; i++) {
				this.grp_split[i] = this.grp_split[i].trim();
				this.multi_value[i] = this.grp_split[i].indexOf("%<") != -1 ? true : false;
				if (this.grp_split[i].indexOf("%<") != -1)
					this.multi_process = true;
				if (this.multi_value[i]) {
					this.grp_split_orig[i] = this.grp_split[i].slice();
					this.grp_split[i] = this.grp_split[i].replace(/%<album artist>%/i, "$if3(%<album artist>%,%<artist>%,%<composer>%,%<performer>%)").replace(/%<album>%/i, "$if2(%<album>%,%<venue>%)").replace(/%<artist>%/i, "$if3(%<artist>%,%<album artist>%,%<composer>%,%<performer>%)");
					this.grp_split_clone[i] = this.grp_split[i].slice();
					this.grp_split[i] = this.grp_split_orig[i].replace(/[<>]/g, "");
				}
				this.grp_sort += (this.grp_split[i] + "|");
				if (this.multi_value[i])
					this.grp_split[i] = this.grp_split_clone[i].replace(/%</g, "#!#$meta_sep(").replace(/>%/g, "," + "|)#!#");
			}
			this.grp_sort = this.grp_sort + this.tf;
			this.view = this.grp_split[0];
		}
		this.set_statistics_mode();
		window.SetProperty("SYSTEM.Filter By", filter);
		window.SetProperty("SYSTEM.View By", view);
		this.f_menu = [];
		this.menu = [];
		for (i = 0; i < this.grp.length; i++)
			this.menu.push(this.grp[i].name);
		for (i = 0; i < this.filt.length; i++) {
			this.f_menu.push(this.filt[i].name);
		}
		this.menu.splice(this.menu.length, 0, "Panel Properties");
		if (this.syncType)
			this.menu.splice(this.menu.length, 0, "Refresh");
		this.menu.splice(this.menu.length, 0, "Configure...");
		this.calc_text();
	}
	this.fields(this.view_by, this.filter_by);

	var k = 1;
	for (i = 0; i < 100; i++) {
		nm = window.GetProperty(" View " + (i < 10 ? "0" + i : i) + ": Name // Pattern");
		if (nm && nm != " // ") {
			window.SetProperty(" View " + (k < 10 ? "0" + k : k) + ": Name // Pattern", nm);
			k += 1
		} else
			window.SetProperty(" View " + (i < 10 ? "0" + i : i) + ": Name // Pattern", null);
	}
	for (i = k; i < k + 5; i++)
		window.SetProperty(" View " + (i < 10 ? "0" + i : i) + ": Name // Pattern", " // ");
	k = 1;
	for (i = 0; i < 100; i++) {
		nm = window.GetProperty(" View Filter " + (i < 10 ? "0" + i : i) + ": Name // Query");
		if (nm && nm != " // ") {
			window.SetProperty(" View Filter " + (k < 10 ? "0" + k : k) + ": Name // Query", nm);
			k += 1
		} else
			window.SetProperty(" View Filter " + (i < 10 ? "0" + i : i) + ": Name // Query", null);
	}
	for (i = k; i < k + 5; i++)
		window.SetProperty(" View Filter " + (i < 10 ? "0" + i : i) + ": Name // Query", " // ");

	this.on_size = function () {
		this.f_x1 = ui.w - ui.margin - this.f_w[this.filter_by] - this.f_sw;
		this.s_x = Math.round(ui.margin + ui.row_h);
		this.s_w1 = ui.w - ui.margin;
		this.s_w2 = this.s_show > 1 ? this.f_x1 - this.s_x - 11 : this.s_w1 - Math.round(ui.row_h * 0.75) - this.s_x + 1;
		this.ln_sp = this.s_show && !ui.local ? ui.row_h * 0.1 : 0;
		this.s_h = this.s_show ? ui.row_h + (!ui.local ? this.ln_sp * 2 : 0) : ui.margin;
		this.s_sp = this.s_h - this.ln_sp;
		this.sp = ui.h - this.s_h - (this.s_show ? 0 : ui.margin);
		this.rows = this.sp / ui.row_h;
		if (this.autofit) {
			this.rows = Math.floor(this.rows);
			this.sp = ui.row_h * this.rows;
		}
		this.node_y = Math.round((ui.row_h - 11) / 2);
		var scr_w = ui.scr_w;
		if (this.scrollbar_show)
			scr_w += 5;
		this.r_mg = Math.max(ui.margin, scr_w);
		sbar.metrics(ui.w - ui.scr_w, this.s_h, Math.max(ui.scr_w - 1, 0), this.sp - (this.autofit ? 0 : 4), this.rows, ui.row_h);
	}
}
var p = new panel_operations();
window.DlgCode = 0x004;

function v_keys() {
	this.selAll = 1;
	this.copy = 3;
	this.back = 8;
	this.enter = 13;
	this.shift = 16;
	this.paste = 22;
	this.cut = 24;
	this.redo = 25;
	this.undo = 26;
	this.pgUp = 33;
	this.pgDn = 34;
	this.end = 35;
	this.home = 36;
	this.left = 37;
	this.up = 38;
	this.right = 39;
	this.dn = 40;
	this.del = 46;
	this.k = function (n) {
		switch (n) {
		case 0:
			return utils.IsKeyPressed(0x10);
			break;
		case 1:
			return utils.IsKeyPressed(0x11);
			break;
		}
	}
}
var v = new v_keys();

function library_manager() {
	var exp = [],
	expanded_items = [],
	lib_paths = [],
	lib_update = false,
	name_idx = [],
	name_ix = [],
	node = [],
	node_s = [],
	process = false,
	scr = [],
	sel = [];
	this.allmusic = [];
	this.get_paths = true;
	this.it = p.items();
	this.list;
	this.none = "";
	this.pth_sort = "";
	this.node = [];
	this.root = [];
	this.time = fb.CreateProfiler();
	this.upd = false,
	this.upd_search = false;
	var tr_sort = function (data) {
		data.sort(function (a, b) {
			return parseFloat(a.tr) - parseFloat(b.tr)
		});
		return data;
	}
	this.update = function () {
		if (ui.w < 1 || !window.IsVisible)
			this.upd = true;
		else {
			this.refresh();
			this.upd = false;
		}
	}

	this.refresh = function (b) {
		if (this.upd) {
			p.search_paint();
			p.tree_paint();
		}
		var ix = -1,
		tr = 0;
		process = false;
		if (pop.tree.length && (!b || b && !p.reset)) {
			tr = 0;
			expanded_items = [];
			process = true;
			scr = [];
			sel = [];
			for (var i = 0; i < pop.tree.length; i++) {
				tr = !p.base ? pop.tree[i].tr : pop.tree[i].tr - 1;
				if (pop.tree[i].child.length)
					expanded_items.push({
						tr : tr,
						a : tr < 1 ? pop.tree[i].name : pop.tree[pop.tree[i].par].name,
						b : tr < 1 ? "" : pop.tree[i].name
					});
				tr = pop.tree[i].tr;
				if (pop.tree[i].sel == true)
					sel.push({
						tr : tr,
						a : pop.tree[i].name,
						b : tr != 0 ? pop.tree[pop.tree[i].par].name : "",
						c : tr > 1 ? pop.tree[pop.tree[pop.tree[i].par].par].name : ""
					});
			}
			var l = Math.min(Math.floor(p.rows), pop.tree.length);
			ix = pop.get_ix(0, p.s_h + ui.row_h / 2, true, false);
			tr = 0;
			for (var i = ix; i < ix + l; i++) {
				tr = pop.tree[i].tr;
				scr.push({
					tr : tr,
					a : pop.tree[i].name,
					b : tr != 0 ? pop.tree[pop.tree[i].par].name : "",
					c : tr > 1 ? pop.tree[pop.tree[pop.tree[i].par].par].name : ""
				})
			}
			exp = JSON.parse(JSON.stringify(tr_sort(expanded_items)));
		}
		lib_update = true;
		this.get_library();
		this.rootNodes();
	}

	this.get_library = function () {
		if (this.list)
			this.list.Dispose();
		if (p.list)
			p.list.Dispose();
		this.time.Reset();
		this.none = "";
		this.list = fb.GetLibraryItems();
		if (!this.list.Count) {
			pop.tree = [];
			pop.line_l = 0;
			sbar.set_rows(0);
			this.none = "Nothing to show\n\nConfigure Media Library first\n\nFile>Preferences>Media library";
			p.tree_paint();
			return;
		}
		if (p.filter_by > 0 && p.s_show > 1)
			try {
				this.list = fb.GetQueryItems(this.list, p.filt[p.filter_by].type)
			} catch (e) {};
		if (!this.list.Count) {
			pop.tree = [];
			pop.line_l = 0;
			sbar.set_rows(0);
			this.none = "Nothing found";
			p.tree_paint();
			return;
		}
		this.rootNames("", 0);
	}

	this.rootNames = function (li, search) {
		var i = 0,
		name = "",
		search_name = "",
		tf = fb.TitleFormat(p.view),
		total;
		switch (search) {
		case 0:
			p.sort(this.list);
			li = p.list = this.list;
			name_idx = [];
			break;
		case 1:
			name_ix = [];
			break;
		}
		total = li.Count;
		var tree_type = !search ? p.view_by != p.folder_view ? !p.base ? 0 : 1 : !p.base ? 2 : 3 : p.view_by != p.folder_view ? !p.base ? 4 : 7 : !p.base ? 5 : 6;
		switch (tree_type) {
		case 0:
			for (i = 0; i < total; i++) {
				name = tf.EvalWithMetadb(li.Item(i));
				name_idx[i] = !name.length || name == "#!##!#" ? "?" : name;
			};
			break;
		case 1:
			for (i = 0; i < total; i++) {
				this.allmusic[i] = tf.EvalWithMetadb(li.Item(i));
			};
			break;
		case 2:
			for (i = 0; i < total; i++) {
				node[i] = fb.GetLibraryRelativePath(li.Item(i)).split("\\");
				name_idx[i] = node[i][0];
			};
			break;
		case 3:
			for (i = 0; i < total; i++) {
				node[i] = fb.GetLibraryRelativePath(li.Item(i)).split("\\");
			};
			break;
		case 4:
			for (i = 0; i < total; i++) {
				name = tf.EvalWithMetadb(li.Item(i));
				name_ix[i] = !name.length || name == "#!##!#" ? "?" : name;
			};
			break
		case 5:
			for (i = 0; i < total; i++) {
				node_s[i] = fb.GetLibraryRelativePath(li.Item(i)).split("\\");
				name_ix[i] = node_s[i][0];
			};
			break;
		case 6:
			for (i = 0; i < total; i++) {
				node_s[i] = fb.GetLibraryRelativePath(li.Item(i)).split("\\");
			};
			break;
		}
	}

	this.rootNodes = function () {
		this.root = [];
		var i = 0,
		j = 1,
		h = 0,
		l = 0,
		n = "";
		if (p.s_txt && (this.upd_search || lib_update)) {
			if (!this.list.Count)
				return;
			this.none = "";
			try {
				p.list = fb.GetQueryItems(this.list, p.s_txt)
			} catch (e) {};
			if (!p.list.Count) {
				pop.tree = [];
				pop.line_l = 0;
				sbar.set_rows(0);
				this.none = "Nothing found";
				p.tree_paint();
				return;
			}
			this.rootNames(p.list, 1);
			this.node = node_s.slice();
			this.upd_search = false;
		} else if (!p.s_txt) {
			p.list = this.list;
			this.node = node.slice()
		};
		var arr = !p.s_txt ? name_idx : name_ix,
		n_o = "#get_node#",
		nU = "",
		total = p.list.Count;
		if (!p.base)
			for (l = 0; l < total; l++) {
				n = arr[l];
				nU = n.toUpperCase();
				if (nU != n_o) {
					n_o = nU;
					this.root[i] = {
						name : n,
						sel : false,
						child : [],
						item : []
					};
					this.root[i].item.push(l);
					i++;
				} else
					this.root[i - 1].item.push(l);
			}
		else {
			this.root[0] = {
				name : "All Music",
				sel : false,
				child : [],
				item : []
			};
			for (l = 0; l < total; l++)
				this.root[0].item.push(l);
		}
		if (!lib_update)
			sbar.reset();
		/* Draw tree -> */
		if (!p.base || p.s_txt)
			pop.buildTree(this.root, 0);
		if (p.base)
			pop.branch(this.root[0], true);
		p.trace("populated in: " + this.time.Time / 1000 + " seconds");
		var gp = p.grp_split.length,
		tot = this.list.Count;
		if (gp > 1 && !p.s_txt && p.view_by != p.folder_view) {
			this.node = [];
			for (h = 0; h < gp; h++)
				this.node[h] = [];
			var tf_gr = [];
			for (j = 1; j < gp; j++)
				tf_gr[j] = fb.TitleFormat(p.grp_split[j])
					for (i = 0; i < tot; i++)
						for (j = 1; j < gp; j++)
							this.node[j][i] = tf_gr[j].EvalWithMetadb(this.list.Item(i));
		}

		if (lib_update && process) {
			try {
				var exp_l = exp.length,
				scr_l = scr.length,
				sel_l = sel.length,
				tree_l = pop.tree.length;
				for (h = 0; h < exp_l; h++) {
					if (exp[h].tr == 0) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == exp[h].a.toUpperCase()) {
								pop.branch(pop.tree[j]);
								break;
							}
					} else if (exp[h].tr > 0) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == exp[h].b.toUpperCase() && pop.tree[pop.tree[j].par].name.toUpperCase() == exp[h].a.toUpperCase()) {
								pop.branch(pop.tree[j]);
								break;
							}
					}
				}
				for (h = 0; h < sel_l; h++) {
					if (sel[h].tr == 0) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == sel[h].a.toUpperCase()) {
								pop.tree[j].sel = true;
								break;
							}
					} else if (sel[h].tr == 1) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == sel[h].a.toUpperCase() && pop.tree[pop.tree[j].par].name.toUpperCase() == sel[h].b.toUpperCase()) {
								pop.tree[j].sel = true;
								break;
							}
					} else if (sel[h].tr > 1) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == sel[h].a.toUpperCase() && pop.tree[pop.tree[j].par].name.toUpperCase() == sel[h].b.toUpperCase() && pop.tree[pop.tree[pop.tree[j].par].par].name.toUpperCase() == sel[h].c.toUpperCase()) {
								pop.tree[j].sel = true;
								break;
							}
					}
				}
				var scr_pos = false;
				h = 0;
				while (h < scr_l && !scr_pos) {
					if (scr[h].tr == 0) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == scr[h].a.toUpperCase()) {
								sbar.check_scroll(!h ? j * ui.row_h : (j - 3) * ui.row_h);
								scr_pos = true;
								break;
							}
					} else if (scr[h].tr == 1 && !scr_pos) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == scr[h].a.toUpperCase() && pop.tree[pop.tree[j].par].name.toUpperCase() == scr[h].b.toUpperCase()) {
								sbar.check_scroll(!h ? j * ui.row_h : (j - 3) * ui.row_h);
								scr_pos = true;
								break;
							}
					} else if (scr[h].tr > 1 && !scr_pos) {
						for (j = 0; j < tree_l; j++)
							if (pop.tree[j].name.toUpperCase() == scr[h].a.toUpperCase() && pop.tree[pop.tree[j].par].name.toUpperCase() == scr[h].b.toUpperCase() && pop.tree[pop.tree[pop.tree[j].par].par].name.toUpperCase() == scr[h].c.toUpperCase()) {
								sbar.check_scroll(!h ? j * ui.row_h : (j - 3) * ui.row_h);
								scr_pos = true;
								break;
							}
					}
					h++;
				}
				if (!scr_pos) {
					sbar.reset();
					p.tree_paint();
				}
			} catch (e) {};
		}
		if (lib_update && !process) {
			sbar.reset();
			p.tree_paint();
		}

		if (p.view_by == p.folder_view && (this.get_paths || lib_update)) {
			var f = "",
			f_o = "",
			it_l = this.it.Count;
			this.pth_sort = "";
			for (var b = 0; b < it_l; b++) {
				f = this.it.Item(b).Path.replace(fb.GetLibraryRelativePath(this.it.Item(b)), "");
				if (f != f_o) {
					f_o = f;
					lib_paths.push(f_o);
				}
			}
			var pth_l = lib_paths.length;
			for (b = 0; b < pth_l; b++) {
				if (!b)
					this.pth_sort = lib_paths[0] + ",";
				else
					this.pth_sort += ("," + lib_paths[b] + ",");
			}
			this.pth_sort = "$replace(%path%," + this.pth_sort + ")";
		}
		this.get_paths = false;
		lib_update = false;
	}
}
var lib = new library_manager();

function populate() {
	var get_pos = -1,
	ix_o = 0,
	last_sel = -1,
	m_i = -1,
	tt = "",
	tooltip = false,
	tt_c = 0,
	tt_h = 20,
	tt_id = -1;
	var dbl_action = window.GetProperty(" Double-Click Action: ExplorerStyle-0 Play-1", 1);
	var auto = window.GetProperty(" Node: Auto Collapse", false);
	var autoplay = window.GetProperty(" Playlist: Autoplay On Send", false);
	var lib_playlist = window.GetProperty(" Playlist", "Library view");
	var show_counts = window.GetProperty(" Node: Show Item Counts", true);
	var symb = window.CreateThemeManager("TREEVIEW");
	var im = gdi.CreateImage(11, 11),
	g = im.GetGraphics(),
	symb_style = 0;
	if (ui.node_style)
		try {
			symb.SetPartAndStateId(2, 1);
			symb.SetPartAndStateId(2, 2);
			symb.DrawThemeBackground(g, 0, 0, 11, 11);
		} catch (e) {
			symb_style = 1;
		}
	im.ReleaseGraphics(g);
	im.Dispose();
	var sy_font = gdi.Font("Segoe UI", 24, 1),//                                 font symb
	symb_style = 0;
	this.line_l = 0;
	this.sel_items = [];
	this.tree = [];
	if (!window.GetProperty("SYSTEM.Playlist Checked", false))
		fb.ShowPopupMessage("Library Tree uses the following playlist by default:\n\nLibrary view\n\nIf you wish to use a different playlist, change the one used by Library Tree in properties.", "Library Tree");
	window.SetProperty("SYSTEM.Playlist Checked", true);
	var arr_contains = function (arr, item) {
		var n = false;
		for (var i = 0; i < arr.length; i++)
			if (arr[i] == item) {
				n = true;
				break;
			}
		return n;
	}
	var arr_index = function (arr, item) {
		var n = -1;
		for (var i = 0; i < arr.length; i++)
			if (arr[i] == item) {
				n = i;
				break;
			}
		return n;
	}
	var check_node = function (gr) {
		if (sbar.draw_timer || !ui.node_style)
			return;
		symb_style = 0;
		try {
			symb.SetPartAndStateId(2, 1);
			symb.SetPartAndStateId(2, 2);
			symb.DrawThemeBackground(gr, -11, -11, 11, 11);
		} catch (e) {
			symb_style = 1;
		}
	}
	var draw_node = function (gr, parent, x, y) {
		switch (symb_style) {
		case 1:
			symb.SetPartAndStateId(2, parent ? 1 : 2);
			symb.DrawThemeBackground(gr, x, y, 11, 11);
			break;
		case 0:
			gr.FillSolidRect(x+0.5, y-2, 17, 17, RGBA(226, 226, 226 ,100));
			gr.DrawRect(x+0.5, y-2, 16, 17, 2, RGB(163, 163, 163));
            if (parent) {
			gr.GdiDrawText("+" , sy_font, RGB(0, 0, 0), x, y-12 , 26, 26)
              }
            else 
            gr.GdiDrawText("-" , sy_font, RGB(0, 0, 0), x+4, y-12 , 26, 26)
			break;
		}
	}
	var num_sort = function (a, b) {
		return a - b;
	}
	var plID = function (Playlist_Name) {
		for (var i = 0; i < plman.PlaylistCount; i++)
			if (plman.GetPlaylistName(i) == Playlist_Name)
				return i;
		plman.CreatePlaylist(plman.PlaylistCount, Playlist_Name);
		return i;
	}
	var searchBranches = function (item, tr) {
		var nn = "",
		tf_l = fb.TitleFormat("[" + p.grp_split[tr] + "]");
		if (tr < p.grp_split.length) {
			nn = tf_l.EvalWithMetadb(p.list.Item(item));
			if (!nn || nn == "#!##!#")
				nn = "?";
			return nn;
		} else
			return "#get_track#";
	}
	var sort = function (c, d) {
		a = c.name.toUpperCase().replace(/^\?/, "");
		b = d.name.toUpperCase().replace(/^\?/, "");
		if (a < b)
			return -1;
		if (a > b)
			return 1;
		return 0;
	}
	var uniq = function (a) {
		var j = 0,
		len = a.length,
		out = [],
		seen = {};
		for (var i = 0; i < len; i++) {
			var item = a[i];
			if (seen[item] !== 1) {
				seen[item] = 1;
				out[j++] = item;
			}
		}
		return out.sort(num_sort);
	}
	this.branch_chg = function (br) {
		var new_br = 0;
		if (br.tr == 0) {
			for (var i = 0; i < lib.root.length; i++) {
				new_br += lib.root[i].child.length;
				lib.root[i].child = [];
			}
		} else {
			var par = this.tree[br.par];
			for (var i = 0; i < par.child.length; i++) {
				new_br += par.child[i].child.length;
				par.child[i].child = [];
			}
		}
		return new_br;
	}
	this.clear = function () {
		for (var i = 0; i < this.tree.length; i++)
			this.tree[i].sel = false;
	}
	this.clear_child = function (br) {
		br.child = [];
		this.buildTree(lib.root, 0, true, true);
	}
	this.deactivate_tooltip = function () {
		tt_c = 0;
		tt.Text = "";
		tt.TrackActivate = false;
		tt.Deactivate();
	}
	this.mbtn_dn = function (x, y) {
		if (y < p.s_h)
			return;
		var ix = this.get_ix(x, y, true, false);
		p.pos = ix;
		if (ix < this.tree.length && ix >= 0)
			if (this.check_ix(this.tree[ix], x, y, true)) {
				this.load(this.tree[ix].item, true, true, false, false);
				this.tree[ix].sel = true;
			}
	}

	this.create_tooltip = function () {
		if (!p.tooltip)
			return;
		if (tt)
			tt.Dispose();
		tt = window.CreateTooltip(ui.font.Name, ui.font.Size, ui.font.Style);
		tt_h = ui.row_h - window.GetProperty(" Row Vertical Item Padding", 3);
		tt.SetDelayTime(0, 500);
		tt.Text = "";
	}

	this.activate_tooltip = function (ix, row) {
		if (tt_c == 2) {
			tt_id = ix;
			return;
		}
		tt_c += 1;
		tt.Activate();
		tt.TrackActivate = true;
		tt.Text = this.tree[ix].name + ((this.tree[ix].track && p.show_tracks) ? ("") : (" (" + this.tree[ix].item.length + ")"));
		tt.TrackPosition(Math.round(ui.pad * this.tree[ix].tr + ui.margin) + (!ui.node_style && this.tree[ix].track ? 0 : ui.symbol_w) - ui.tt, row * ui.row_h + p.s_h - Math.floor((ui.row_h - tt_h) / 2));
		timer.tooltip();
	}

	this.branch = function (br, base, node) {
		if (!br)
			return;
		var br_l = br.item.length,
		branch = false,
		folderView = p.view_by == p.folder_view ? true : false,
		i = 0,
		k = 0,
		isTrack = false,
		l = base ? 0 : p.base ? br.tr : br.tr + 1,
		n = "",
		n_o = "#get_branch#",
		nU = "",
		tf = fb.TitleFormat(p.tf),
		treatAsTrack = !folderView && l < p.grp_split.length - 1 ? true : false;
		if (folderView)
			base = false;
		if (base)
			node = false;
		if (!folderView && l < p.grp_split.length)
			branch = true;
		if (!folderView && !branch && !p.show_tracks)
			return;
		for (k = 0; k < br_l; k++) {
			var get_track = true,
			pos = br.item[k];
			if (folderView && l == lib.node[pos].length - 1 && !p.show_tracks)
				get_track = false;
			if (get_track) {
				if (base) {
					n = lib.allmusic[pos];
					if (!n || n == "#!##!#")
						n = "?";
				}
				if (!p.s_txt && !base) {
					if (branch || folderView && l < lib.node[pos].length - 1) {
						n = (!folderView ? lib.node[l][pos] : lib.node[pos][l]);
						if (!n || n == "#!##!#")
							n = "?";
					} else
						n = "#get_track#";
				} else if (p.s_txt) {
					if (folderView && l < lib.node[pos].length - 1) {
						n = lib.node[pos][l];
						if (!n || n == "#!##!#")
							n = "?";
					} else
						n = searchBranches(pos, l);
				}
				if (br.track)
					continue;
				isTrack = p.show_tracks ? false : treatAsTrack || folderView && l < lib.node[pos].length - 2 ? false : true;
				if (n == "#get_track#") {
					n = !folderView ? tf.EvalWithMetadb(p.list.Item(pos)) : lib.node[pos][l];
					isTrack = true;
				}
				nU = n.toUpperCase();
				if (n_o != nU) {
					n_o = nU;
					br.child[i] = {
						name : n,
						sel : false,
						child : [],
						track : isTrack,
						item : []
					};
					br.child[i].item.push(pos);
					i++;
				} else
					br.child[i - 1].item.push(pos);
			}
		}
		this.buildTree(lib.root, 0, node, true);
	}

	var getAllCombinations = function (n) {
		var combinations = [],
		divisors = [],
		nn = [],
		arraysToCombine = [];
		nn = n.split("#!#");
		for (var i = 0; i < nn.length; i++) {
			nn[i] = nn[i].split("|");
			if (nn[i] != "")
				arraysToCombine.push(nn[i]);
		}
		for (var i = arraysToCombine.length - 1; i >= 0; i--)
			divisors[i] = divisors[i + 1] ? divisors[i + 1] * arraysToCombine[i + 1].length : 1;
		function getPermutation(n, arraysToCombine) {
			var result = [],
			curArray;
			for (var i = 0; i < arraysToCombine.length; i++) {
				curArray = arraysToCombine[i];
				result.push(curArray[Math.floor(n / divisors[i]) % curArray.length]);
			}
			return result;
		}
		var numPerms = arraysToCombine[0].length;
		for (var i = 1; i < arraysToCombine.length; i++)
			numPerms *= arraysToCombine[i].length;
		for (var i = 0; i < numPerms; i++)
			combinations.push(getPermutation(i, arraysToCombine));
		return combinations;
	}

	this.buildTree = function (br, tr, node, full) {
		var br_l = br.length,
		i = 0,
		j = 0,
		l = !p.base ? tr : tr - 1;
		if (p.multi_process) {
			var simple = l == p.grp_split.length ? true : false;
			var h = -1,
			multi = [],
			multi_cond = [],
			multi_obj = [],
			multi_rem = [],
			n = "",
			n_o = "#condense#",
			nm_arr = [],
			nU = "";
			if (!simple) {
				for (i = 0; i < br_l; i++) {
					if (br[i].name.indexOf("|") != -1) {
						multi = getAllCombinations(br[i].name);
						multi_rem.push(i);
						for (var m = 0; m < multi.length; m++)
							multi_obj.push({
								name : multi[m].join(""),
								item : br[i].item.slice()
							});
					}
				}
				i = multi_rem.length;
				while (i--)
					br.splice(multi_rem[i], 1);
				br_l = br.length;
				multi_obj.sort(sort);
				i = 0;
				while (i < multi_obj.length) {
					n = multi_obj[i].name;
					nU = n.toUpperCase();
					if (n_o != nU) {
						n_o = nU;
						multi_cond[j] = {
							name : n,
							item : multi_obj[i].item.slice()
						};
						j++
					} else
						multi_cond[j - 1].item.push.apply(multi_cond[j - 1].item, multi_obj[i].item.slice());
					i++
				}
				for (i = 0; i < br_l; i++) {
					br[i].name = br[i].name.replace(/#!#/g, "");
					nm_arr.push(br[i].name);
				}
				for (i = 0; i < multi_cond.length; i++) {
					h = arr_index(nm_arr, multi_cond[i].name);
					if (h != -1) {
						br[h].item.push.apply(br[h].item, multi_cond[i].item.slice());
						multi_cond.splice(i, 1);
					}
				}
				for (i = 0; i < multi_cond.length; i++)
					br.splice(i + 1, 0, {
						name : multi_cond[i].name,
						sel : false,
						track : false,
						child : [],
						item : multi_cond[i].item.slice()
					});
			}
			if (!node || node && !full)
				br.sort(sort);
			i = br.length;
			while (i--) {
				if (i != 0 && br[i].name.toUpperCase() == br[i - 1].name.toUpperCase()) {
					br[i - 1].item.push.apply(br[i - 1].item, br[i].item.slice());
					br.splice(i, 1);
				}
			}
		}
		var par = this.tree.length - 1;
		if (tr == 0)
			this.tree = [];
		br_l = br.length;
		for (i = 0; i < br_l; i++) {
			j = this.tree.length;
			this.tree[j] = br[i];
			this.tree[j].top = !i ? true : false;
			this.tree[j].bot = i == br_l - 1 ? true : false;
			if (tr == (p.base ? 1 : 0) && i == br_l - 1)
				this.line_l = j;
			this.tree[j].tr = tr;
			this.tree[j].par = par;
			this.tree[j].ix = j;
			if (p.single_br)
				this.tree[j].track = true;
			if (!p.base && p.view_by == p.folder_view && !p.show_tracks) {
				var n_id = this.tree[j].item[0];
				if (lib.node[n_id].length == 1 || lib.node[n_id].length == 2 && !p.show_tracks)
					this.tree[j].track = true;
			}
			if (br[i].child.length > 0)
				this.buildTree(br[i].child, tr + 1, node, p.base && tr == 0 ? true : false);
		}
		if (p.base && this.tree.length == 1)
			this.line_l = 0;
		sbar.set_rows(this.tree.length);
		p.tree_paint();
	}

	this.load = function (list, type, add, send, sort) {
		var i = 0,
		np_item = -1,
		pid = -1,
		pln = plID(lib_playlist);
		plman.ActivePlaylist = pln;
		if (type) {
			var items = p.items();
			for (var i = 0; i < list.length; i++)
				items.Add(p.list.Item(list[i]));
		} else
			var items = list.Clone();
		if (fb.IsPlaying && !add && fb.GetNowPlaying()) {
			for (i = 0; i < items.Count; i++)
				if (fb.GetNowPlaying().Compare(items.Item(i))) {
					np_item = i;
					break;
				}
			if (np_item != -1) {
				var np = plman.GetPlayingItemLocation();
				if (np.IsValid && np.PlaylistIndex == pln)
					pid = np.PlaylistItemIndex;
			}
			if (np_item != -1 && pid == -1 && items.Count < 5000) {
				if (ui.dui)
					plman.SetActivePlaylistContext();
				for (i = 0; i < 20; i++) {
					fb.RunMainMenuCommand("Edit/Undo");
					var np = plman.GetPlayingItemLocation();
					if (np.IsValid && lib_playlist == plman.GetPlaylistName(np.PlaylistIndex)) {
						pid = np.PlaylistItemIndex;
						if (pid != -1)
							break;
					}
				}
			}
			if (np_item != -1 && pid != -1) {
				plman.SetPlaylistSelectionSingle(pln, pid, true);
				plman.RemovePlaylistSelection(pln, true);
				var it = items.Clone();
				items.RemoveRange(np_item, items.Count);
				it.RemoveRange(0, np_item + 1);
				plman.UndoBackup(pln);
				plman.InsertPlaylistItems(pln, 0, items);
				plman.InsertPlaylistItems(pln, plman.PlaylistItemCount(pln), it);
			} else {
				plman.UndoBackup(pln);
				plman.ClearPlaylist(pln);
				plman.InsertPlaylistItems(pln, 0, items);
			}
		} else if (!add) {
			plman.UndoBackup(pln);
			plman.ClearPlaylist(pln);
			plman.InsertPlaylistItems(pln, 0, items);
		} else {
			if (items.Count < 5000 && plman.PlaylistItemCount(pln) < 5000 && sort) {
				plman.UndoBackup(pln);
				plman.InsertPlaylistItems(pln, plman.PlaylistItemCount(pln), items);
				if (ui.dui)
					plman.SetActivePlaylistContext();
				fb.RunMainMenuCommand("Edit/Remove Duplicates");
				plman.SortByFormat(pln, p.view_by != p.folder_view ? p.grp_sort : lib.pth_sort);
			} else {
				plman.UndoBackup(pln);
				plman.InsertPlaylistItems(pln, plman.PlaylistItemCount(pln), items);
			}
		}
		if (autoplay && send) {
			var c = (plman.PlaybackOrder == 3 || plman.PlaybackOrder == 4) ? Math.ceil(plman.PlaylistItemCount(pln) * Math.random() - 1) : 0;
			plman.ExecutePlaylistDefaultAction(pln, c);
		}
	}

	this.draw = function (gr) {
		if (!pop.tree.length)
			return gr.GdiDrawText(lib.none, ui.font, ui.textcol, ui.margin, p.s_h, ui.w - p.r_mg, ui.row_h * (lib.none.length > 14 ? 5 : 1), 0x00000004 | 0x00000400);
		var item_x = 0,
		item_y = 0,
		item_w = 0,
		ln_x = ui.margin + 5 + (p.base ? ui.pad : 0),
		nm = "",
		s = Math.round(sbar.delta / ui.row_h + 0.4),
		e = s + p.rows;
		e = this.tree.length < e ? this.tree.length : e,
		sel_x = 0,
		sel_w = 0,
		y1 = p.s_h - sbar.delta + p.node_y;
		check_node(gr);
		for (var i = s; i < e; i++) {
			item_y = ui.row_h * i + p.s_h - sbar.delta;
			if (ui.alternate) {
				if (i % 2 == 0)
					gr.FillSolidRect(0, item_y + 1, ui.w, ui.row_h - 2, ui.b1);
				else
					gr.FillSolidRect(0, item_y, ui.w, ui.row_h, ui.b2);
			}
			if (ui.node_style && ui.linecol) {
				var end_br = [],
				j = this.tree[i].tr,
				l_x = 0,
				l_y = item_y + ui.row_h / 2;
				if (p.base)
					j -= 1;
				var h1 = this.tree[i].top ? ui.row_h / 4 : ui.row_h;
				if (this.tree[i].tr != 0) {
					var par = this.tree[i].par,
					pr_pr = [];
					for (var m = 1; m < j + 1; m++) {
						if (m == 1)
							pr_pr[m] = par;
						else
							pr_pr[m] = this.tree[pr_pr[m - 1]].par
								if (this.tree[pr_pr[m]].bot)
									end_br[m] = true;
								else
									end_br[m] = false;
					}
				}
				for (var k = 0; k < j + 1; k++) {
					if (this.tree[i].top && !k && !this.tree[i].track)
						h1 = ui.row_h / 2;
					else
						h1 = ui.row_h;
					if (!k && !j && this.tree[i].top && !this.tree[i].track)
						h1 = -ui.row_h / 4;
					if (this.tree[i].track && !k && this.tree[i].top)
						h1 = ui.row_h / 2
							if (!end_br[k] && k == 1)
								h1 = ui.row_h;
							if (end_br[k])
								h1 = 0;
							var h3 = l_y - h1;
					if (h3 < p.s_h)
						h1 = p.s_h - h3;
					l_x = (Math.round(ui.pad * this.tree[i].tr + ui.margin) + 5) - ui.pad * k;
					var h2 = ((!this.tree[i].bot && !k && this.tree[i].track && i == Math.ceil(e - 1)) ||
						(!this.tree[i].bot && !end_br[k] && !this.tree[i].track && i == Math.ceil(e - 1)) ||
						(k && !end_br[k] && i == e - 1)) ? ui.row_h / 2 : 0;
					if (k != j)
						gr.FillSolidRect(l_x+2.5, l_y+3 - h1, 1, h1 + h2, ui.linecol);//                                        ___Y_LINE___
				}
			}
		}
		if (ui.node_style && ui.linecol) {
			var top = p.base ? p.s_h + ui.row_h * 3 / 4 : p.s_h;
			var ln_y = sbar.scroll == 0 ? top + p.node_y : p.s_h;
			var ln_h = Math.min(this.line_l * ui.row_h - sbar.delta + (sbar.scroll == 0 ? (p.base ? -ui.row_h * 3 / 4 : 0) : p.node_y), ui.row_h * Math.ceil(p.rows) - (sbar.scroll == 0 ? (p.node_y + (p.base ? ui.row_h * 3 / 4 : 0)) : 0));
			if (e == this.tree.length)
				ln_h += ui.row_h / 4;
			if (this.line_l)
            {}
				gr.FillSolidRect(ln_x+3, ln_y, 1, ln_h, ui.linecol);//                                        ___X_LINE___
		}
		for (i = s; i < e; i++) {
			if (this.tree[i].sel && ui.backcolsel != 0) {
				item_y = ui.row_h * i + p.s_h - sbar.delta;
				nm = this.tree[i].name + (show_counts && (!this.tree[i].track || !p.show_tracks) ? " (" + this.tree[i].item.length + ")" : "");
				item_w = gr.CalcTextWidth(nm, ui.font) + ui.row_h * 0.2;
				item_x = Math.round(ui.pad * this.tree[i].tr + ui.margin);
				if (ui.node_style || !this.tree[i].track)
					item_x = item_x + ui.symbol_w;
				sel_x = item_x - ui.sel;
				sel_w = Math.min(item_w, ui.w - sel_x - 1 - p.r_mg)
                {}
					gr.FillSolidRect(sel_x, item_y, sel_w, ui.row_h, ui.backcolsel);
			}
		}
		for (i = s; i < e; i++) {
			item_y = ui.row_h * i + p.s_h - sbar.delta;
			nm = this.tree[i].name + (show_counts && (!this.tree[i].track || !p.show_tracks) ? " (" + this.tree[i].item.length + ")" : "");
			item_w = gr.CalcTextWidth(nm, ui.font) + ui.row_h * 0.2;
			this.tree[i].w = item_w;
			item_x = Math.round(ui.pad * this.tree[i].tr + ui.margin);
			if (ui.node_style) {
				var y2 = ui.row_h * i + y1 + 5;
				if (!this.tree[i].track) {
					if (ui.linecol)
						gr.FillSolidRect(item_x + 25, y2+1, 4, 1, ui.linecol); //                                      X_LINE
					draw_node(gr, this.tree[i].child.length < 1, item_x, item_y + p.node_y);
				} else if (ui.linecol)
					gr.FillSolidRect(item_x + 9, y2, 7, 1, ui.linecol);//                                      X_LINE
			} else if (!this.tree[i].track)
				gr.GdiDrawText(this.tree[i].child.length < 1 ? ui.expand : ui.collapse, ui.font, ui.textsymbcol, item_x, item_y, ui.w - item_x - p.r_mg, ui.row_h, p.lc);
			if (ui.node_style || !this.tree[i].track)
				item_x = item_x + ui.symbol_w;
			if (m_i == i) {
				sel_x = item_x - ui.sel;
				sel_w = Math.min(item_w, ui.w - sel_x - 1 - p.r_mg);
				gr.FillSolidRect(sel_x, item_y, sel_w, ui.row_h, ui.backcol_h);
				gr.DrawRect(sel_x, item_y, sel_w, ui.row_h, 1, ui.framecol);
			}
			var txt_c = this.tree[i].sel ? ui.textselcol : m_i == i ? ui.textcol_h : ui.textcol;
			gr.GdiDrawText(nm, ui.font, txt_c, item_x, item_y, ui.w - item_x - p.r_mg, ui.row_h, p.lc);
		}
	}

	this.lbtn_dn = function (x, y) {
		if (y < p.s_h)
			return;
		var ix = this.get_ix(x, y, true, false);
		p.pos = ix;
		if (ix < this.tree.length && ix >= 0) {
			var item = this.tree[ix],
			mode = x > Math.round(ui.pad * item.tr + ui.margin) && x < Math.round(ui.pad * item.tr) + ui.symbol_w + ui.margin ? 0 : this.check_ix(item, x, y, false) ? 1 : 2,
			xp = item.child.length > 0 ? 0 : 1;
			switch (mode) {
			case 0:
				switch (xp) {
				case 0:
					this.clear_child(item);
					break;
				case 1:
					if (auto)
						this.branch_chg(item, false, true);
					var row = Math.round((y - p.s_h - ui.row_h * 0.5) / ui.row_h);
					this.branch(item, !p.base || ix ? false : true, true);
					if (auto)
						ix = item.ix
							if (row + 1 + item.child.length > sbar.rows_drawn) {
								if (item.child.length > (sbar.rows_drawn - 2))
									sbar.check_scroll(ix * ui.row_h);
								else
									sbar.check_scroll(Math.min(ix * ui.row_h, (ix + 1 - sbar.rows_drawn + item.child.length) * ui.row_h));
							}
							break;
				}
				if (sbar.scroll > ix * ui.row_h)
					sbar.check_scroll(ix * ui.row_h);
				break;
			case 1:
				if (!v.k(1))
					this.clear();
				if (!item.sel)
					this.get_selection(ix, item.sel);
				else if (v.k(1))
					this.get_selection(ix, item.sel);
				p.tree_paint();
				break;
			}
			if (this.check_ix(item, x, y, false)) { // on mouse lbn down sel
				/*if (v.k(1))
					this.load(item.item, true, true, false, true);
				else if (v.k(0))
					this.load(this.sel_items, true, false, false, true);
				else
					this.load(item.item, true, false, false, true);*/ // send to pl on left mouse btn
			}
		} else
			this.get_selection(-1);
	}

	this.lbtn_dblclk = function (x, y) {
		if (y < p.s_h)
			return;
		var ix = this.get_ix(x, y, true, false);
		if (ix >= this.tree.length || ix < 0)
			return;
		var item = this.tree[ix];
		if (!this.check_ix(item, x, y, false))
			return;
		var mp = 1;
		if (!dbl_action) {
			if (item.child.length)
				mp = 0;
			switch (mp) {
			case 0:
				this.clear_child(item);
				break;
			case 1:
				if (auto)
					this.branch_chg(item, false, true);
				var row = Math.round((y - p.s_h - ui.row_h * 0.5) / ui.row_h);
				this.branch(item, !p.base || ix ? false : true, true);
				if (auto)
					ix = item.ix
						if (row + 1 + item.child.length > sbar.rows_drawn) {
							if (item.child.length > (sbar.rows_drawn - 2))
								sbar.check_scroll(ix * ui.row_h);
							else
								sbar.check_scroll(Math.min(ix * ui.row_h, (ix + 1 - sbar.rows_drawn + item.child.length) * ui.row_h));
						}
						break;
			}
			if (sbar.scroll > ix * ui.row_h)
				sbar.check_scroll(ix * ui.row_h);
		}
		if (dbl_action || !dbl_action && mp == 1 && !item.child.length) {
			this.load(item.item, true, false, false, true);/// add??? //send to pl on mouse double clk
			var pln = plID(lib_playlist);
			plman.ActivePlaylist = pln;
			var c = (plman.PlaybackOrder == 3 || plman.PlaybackOrder == 4) ? Math.ceil(plman.PlaylistItemCount(pln) * Math.random() - 1) : 0;
			plman.ExecutePlaylistDefaultAction(pln, c);
		}
	}

	this.get_selection = function (idx, state, add, bypass) {
		var sel_type = idx == -1 && !add ? 0 : v.k(0) && last_sel > -1 && !bypass ? 1 : v.k(1) && !bypass ? 2 : !state ? 3 : 0;
		switch (sel_type) {
		case 0:
			this.clear();
			this.sel_items = [];
			break;
		case 1:
			this.sel_items = [];
			var direction = (idx > last_sel) ? 1 : -1;
			if (!v.k(1))
				this.clear();
			for (var i = last_sel; ; i += direction) {
				this.tree[i].sel = true;
				this.sel_items.push.apply(this.sel_items, this.tree[i].item);
				if (i == idx)
					break;
			}
			this.sel_items = uniq(this.sel_items);
			p.tree_paint();
			break;
		case 2:
			this.tree[idx].sel = !this.tree[idx].sel;
			this.tree[idx].sel && this.sel_items.push.apply(this.sel_items, this.tree[idx].item);
			this.sel_items = uniq(this.sel_items);
			last_sel = idx;
			break;
		case 3:
			this.sel_items = [];
			if (!add)
				this.clear();
			if (!add)
				this.tree[idx].sel = true;
			this.sel_items.push.apply(this.sel_items, this.tree[idx].item);
			this.sel_items = uniq(this.sel_items);
			last_sel = idx;
			break;
		}
	}

	this.move = function (x, y) {
		var ix = -1;
		m_i = -1;
		get_pos = -1;
		ix = this.get_ix(x, y, false, false);
		if (ix != -1) {
			m_i = ix;
			get_pos = ix;
			if (p.tooltip && tt_id != ix && Math.round(ui.pad * this.tree[ix].tr + ui.margin) + (!ui.node_style && this.tree[ix].track ? 0 : ui.symbol_w) + this.tree[ix].w - ui.row_h * 0.2 > ui.w - p.r_mg) {
				var row = Math.round((y - p.s_h - ui.row_h * 0.5) / ui.row_h);
				this.activate_tooltip(ix, row);
			}
		} else
			get_pos = this.get_ix(x, y, true, false);
		if (ix == ix_o)
			return;
		tt_id = -1;
		if (p.tooltip && tt.Text)
			this.deactivate_tooltip();
		if (!sbar.draw_timer)
			p.tree_paint();
		ix_o = ix;
	}

	this.get_ix = function (x, y, simple, type) {
		var ix;
		if (y > p.s_h)
			ix = Math.round((y + (simple ? sbar.scroll : sbar.delta) - p.s_h - ui.row_h * 0.5) / ui.row_h);
		else
			ix = -1;
		if (simple)
			return ix;
		if (this.tree.length > ix && ix >= 0 && x < ui.w - 10 && y > p.s_h && this.check_ix(this.tree[ix], x, y, type))
			return ix;
		else
			return -1;
	}

	this.check_ix = function (br, x, y, type) {
		if (!br)
			return false;
		return type ? (x > Math.round(ui.pad * br.tr + ui.margin) && x < Math.round(ui.pad * br.tr + ui.margin) + br.w + ui.symbol_w)
		 : (x > Math.round(ui.pad * br.tr + ui.margin) + (!ui.node_style && br.track ? 0 : ui.symbol_w)) && x < Math.min(Math.round(ui.pad * br.tr + ui.margin) + (!ui.node_style && br.track ? 0 : ui.symbol_w) + br.w, ui.w - Math.max(ui.scr_w, ui.margin));
	}

	this.on_key_down = function (vkey) {
		if (p.s_search)
			return;
		switch (vkey) {
		case v.left:
			if (!(p.pos >= 0) && get_pos != -1)
				p.pos = get_pos 
			else
						p.pos = p.pos + this.tree.length % this.tree.length;
					p.pos = Math.max(Math.min(p.pos, this.tree.length - 1), 0);
			get_pos = -1;
			m_i = -1;
			if (this.tree[p.pos].child.length > 0) {
				var item = this.tree[p.pos];
				this.clear_child(item);
				this.get_selection(item.ix);
				m_i = p.pos = item.ix;
			} else {
				try {
					var item = this.tree[this.tree[p.pos].par];
					this.clear_child(item);
					this.get_selection(item.ix);
					m_i = p.pos = item.ix;
				} catch (e) {
					return;
				};
			}
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			sbar.set_rows(this.tree.length);
			if (sbar.scroll > p.pos * ui.row_h)
				sbar.check_scroll(p.pos * ui.row_h);
			break;
		case v.right:
			if (!(p.pos >= 0) && get_pos != -1)
				p.pos = get_pos 
			else
						p.pos = p.pos + this.tree.length % this.tree.length;
					p.pos = Math.max(Math.min(p.pos, this.tree.length - 1), 0);
			get_pos = -1;
			m_i = -1;
			var item = this.tree[p.pos];
			if (auto)
				this.branch_chg(item, false, true);
			this.branch(item, p.base && p.pos == 0 ? true : false, true);
			this.get_selection(item.ix);
			p.tree_paint();
			m_i = p.pos = item.ix;
			this.load(this.sel_items, true, false, false, true);
			sbar.set_rows(this.tree.length);
			var row = (p.pos * ui.row_h - sbar.scroll) / ui.row_h;
			if (row + item.child.length > sbar.rows_drawn) {
				if (item.child.length > (sbar.rows_drawn - 2))
					sbar.check_scroll(p.pos * ui.row_h);
				else
					sbar.check_scroll(Math.min(p.pos * ui.row_h, (p.pos + 1 - sbar.rows_drawn + item.child.length) * ui.row_h));
			}
			break;
		case v.pgUp:
			if (this.tree.length == 0)
				break;
			p.pos = Math.round(sbar.scroll / ui.row_h + 0.4) - Math.floor(p.rows);
			p.pos = Math.max(!p.base ? 0 : 1, p.pos);
			sbar.wheel(1);
			this.get_selection(this.tree[p.pos].ix);
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			break;
		case v.pgDn:
			if (this.tree.length == 0)
				break;
			p.pos = Math.round(sbar.scroll / ui.row_h + 0.4);
			p.pos = p.pos + Math.floor(p.rows) * 2 - 1;
			p.pos = this.tree.length < p.pos ? this.tree.length - 1 : p.pos;
			sbar.wheel(-1);
			this.get_selection(this.tree[p.pos].ix);
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			break;
		case v.home:
			if (this.tree.length == 0)
				break;
			p.pos = !p.base ? 0 : 1;
			sbar.check_scroll(0);
			this.get_selection(this.tree[p.pos].ix);
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			break;
		case v.end:
			if (this.tree.length == 0)
				break;
			p.pos = this.tree.length - 1;
			sbar.check_scroll((this.tree.length) * ui.row_h);
			this.get_selection(this.tree[p.pos].ix);
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			break;
		case v.enter:
			if (!this.sel_items.length)
				return;
			//this.load = function (list, type, add, send, sort)
			
			/*this.load(this.sel_items, true, false, false, true); /// --->send to pl on enter down
			var pln = plID(lib_playlist);
			plman.ActivePlaylist = pln;
			var c = (plman.PlaybackOrder == 3 || plman.PlaybackOrder == 4) ? Math.ceil(plman.PlaylistItemCount(pln) * Math.random() - 1) : 0;
			plman.ExecutePlaylistDefaultAction(pln, c);*/
			
			                  //list, type, add, send, sort
			this.load(this.sel_items, true, true, false, false); /// --->add to pl on enter down
			var pln = plID(lib_playlist);
			plman.ActivePlaylist = pln;
			//var c = (plman.PlaybackOrder == 3 || plman.PlaybackOrder == 4) ? Math.ceil(plman.PlaylistItemCount(pln) * Math.random() - 1) : 0;
			//plman.ExecutePlaylistDefaultAction(pln, c);
			//p.update;
			fb.RunMainMenuCommand("Edit/Remove Duplicates");
			break;
		case v.dn:
		case v.up:
			if (this.tree.length == 0)
				break;
			if ((p.pos == 0 && get_pos == -1 && vkey == v.up) || (p.pos == this.tree.length - 1 && vkey == v.dn)) {
				this.get_selection(-1);
				break;
			}
			if (get_pos != -1)
				p.pos = get_pos;
			else
				p.pos = p.pos + this.tree.length % this.tree.length;
			get_pos = -1;
			m_i = -1;
			if (vkey == v.dn)
				p.pos++;
			if (vkey == v.up)
				p.pos--;
			p.pos = Math.max(Math.min(p.pos, this.tree.length - 1), 0);
			var row = (p.pos * ui.row_h - sbar.scroll) / ui.row_h;
			if (sbar.rows_drawn - row < 3)
				sbar.check_scroll((p.pos + 3) * ui.row_h - sbar.rows_drawn * ui.row_h);
			else if (row < 2 && vkey == v.up)
				sbar.check_scroll((p.pos - 1) * ui.row_h);
			m_i = p.pos;
			this.get_selection(p.pos);
			p.tree_paint();
			this.load(this.sel_items, true, false, false, true);
			break;
		}
	}
}
var pop = new populate();

function on_size() {
	ui.w = window.Width;
	ui.h = window.Height;
	ww = window.Width;
	wh = window.Height;
	if (!ui.w || !ui.h)
		return;

	// set wallpaper
	if (fb.IsPlaying) {
		g_wallpaperImg = setWallpaperImg(ppt.wallpaperpath, fb.GetNowPlaying());
	};
	else {
		//g_wallpaperImg = null;
		g_wallpaperImg = setWallpaperImg(ppt.wallpaperpath, fb.GetNowPlaying());
	};

	ui.get_font();
	p.on_size();
	pop.create_tooltip();
	if (p.s_show || ui.scrollbar_show)
		but.refresh(true);
	jS.on_size();
}

function searchLibrary() {
	var cx = 0,
	doc = new ActiveXObject('htmlfile'),
	e = 0,
	i = 0,
	lbtn_dn = false,
	lg = [],
	log = [],
	offset = 0,
	s = 0,
	shift = false,
	shift_x = 0,
	txt_w = 0;
	var calc_text = function () {
		var im = gdi.CreateImage(1, 1),
		g = im.GetGraphics();
		txt_w = g.CalcTextWidth(p.s_txt.substr(offset), ui.font);
		im.ReleaseGraphics(g);
		im.Dispose();
	}
	var drawcursor = function (gr) {
		if (p.s_search && p.s_cursor && s == e && cx >= offset) {
			var x1 = p.s_x + get_cursor_x(cx),
			x2 = x1;
			gr.DrawLine(x1, p.s_sp * 0.1, x2, p.s_sp * 0.85, 1, ui.textcol);
		}
	}
	var drawsel = function (gr) {
		if (s == e)
			return;
		var clamp = p.s_x + p.s_w2;
		gr.DrawLine(Math.min(p.s_x + get_cursor_x(s), clamp), p.s_sp / 2, Math.min(p.s_x + get_cursor_x(e), clamp), p.s_sp / 2, ui.row_h - 3, ui.ibeamcol2);
	}
	var get_cursor_pos = function (x) {
		var im = gdi.CreateImage(1, 1),
		g = im.GetGraphics(),
		nx = x - p.s_x,
		pos = 0;
		for (i = offset; i < p.s_txt.length; i++) {
			pos += g.CalcTextWidth(p.s_txt.substr(i, 1), ui.font);
			if (pos >= nx + 3)
				break;
		}
		im.ReleaseGraphics(g);
		im.Dispose();
		return i;
	}
	var get_cursor_x = function (pos) {
		var im = gdi.CreateImage(1, 1),
		g = im.GetGraphics(),
		x = 0;
		if (pos >= offset)
			x = g.CalcTextWidth(p.s_txt.substr(offset, pos - offset), ui.font);
		im.ReleaseGraphics(g);
		im.Dispose();
		return x;
	}
	var get_offset = function (gr) {
		var t = gr.CalcTextWidth(p.s_txt.substr(offset, cx - offset), ui.font);
		while (t >= p.s_w2) {
			offset++;
			t = gr.CalcTextWidth(p.s_txt.substr(offset, cx - offset), ui.font);
		}
	}
	var record = function () {
		lg.push(p.s_txt);
		log = [];
		if (lg.length > 30)
			lg.shift();
	}
	this.clear = function () {
		lib.time.Reset();
		offset = s = e = cx = 0;
		p.s_cursor = false;
		p.s_search = false;
		p.s_txt = "";
		p.search_paint();
		timer.reset(timer.search_cursor, 4);
		lib.rootNodes();
	}
	this.on_key_up = function (vkey) {
		if (!p.s_search)
			return;
		if (vkey == v.shift) {
			shift = false;
			shift_x = cx;
		}
	}
	this.lbtn_up = function (x, y) {
		if (s != e)
			timer.reset(timer.search_cursor, 4);
		lbtn_dn = false;
	}
	this.move = function (x, y) {
		if (y > p.s_h || !lbtn_dn)
			return;
		var t = get_cursor_pos(x),
		t_x = get_cursor_x(t);
		calc_text();
		if (t < s) {
			if (t < e) {
				if (t_x < p.s_x)
					if (offset > 0)
						offset--;
			} else if (t > e) {
				if (t_x + p.s_x > p.s_x + p.s_w2) {
					var l = (txt_w > p.s_w2) ? txt_w - p.s_w2 : 0;
					if (l > 0)
						offset++;
				}
			}
			e = t;
		} else if (t > s) {
			if (t_x + p.s_x > p.s_x + p.s_w2) {
				var l = (txt_w > p.s_w2) ? txt_w - p.s_w2 : 0;
				if (l > 0)
					offset++;
			}
			e = t;
		}
		cx = t;
		p.search_paint();
	}
	this.rbtn_up = function (x, y) {
		men.search_menu(x, y, s, e, doc.parentWindow.clipboardData.getData('text') ? true : false)
	}

	this.lbtn_dn = function (x, y) {
		p.search_paint();
		lbtn_dn = p.s_search = (y < p.s_h && x > ui.margin + ui.row_h * 0.6 && x < p.s_x + p.s_w2);
		if (!lbtn_dn) {
			offset = s = e = cx = 0;
			timer.reset(timer.search_cursor, 4);
			return;
		} else {
			if (shift) {
				s = cx;
				e = cx = get_cursor_pos(x);
			} else {
				cx = get_cursor_pos(x);
				s = e = cx;
			}
			timer.reset(timer.search_cursor, 4);
			p.s_cursor = true;
			timer.search_cursor = window.SetInterval(function () {
					p.s_cursor = !p.s_cursor;
					p.search_paint();
				}, 530);
		}
		p.search_paint();
	}

	this.on_char = function (code, force) {
		var text = String.fromCharCode(code);
		if (force)
			p.s_search = true;
		if (!p.s_search)
			return;
		p.s_cursor = false;
		p.pos = -1;
		switch (code) {
		case v.enter:
			if (p.s_txt.length < 3)
				break;
			var items = fb.GetQueryItems(lib.list, p.s_txt);
			pop.load(items, false, false, false, true);
			items.Dispose();
			break;
		case v.redo:
			lg.push(p.s_txt);
			if (lg.length > 30)
				lg.shift();
			if (log.length > 0) {
				p.s_txt = log.pop() + "";
				cx++
			}
			break;
		case v.undo:
			log.push(p.s_txt);
			if (log.length > 30)
				lg.shift();
			if (lg.length > 0)
				p.s_txt = lg.pop() + "";
			break;
		case v.selAll:
			s = 0;
			e = p.s_txt.length;
			break;
		case v.copy:
			if (s != e)
				doc.parentWindow.clipboardData.setData('text', p.s_txt.substring(s, e));
			break;
		case v.cut:
			if (s != e)
				doc.parentWindow.clipboardData.setData('text', p.s_txt.substring(s, e));
		case v.back:
			record();
			if (s == e) {
				if (cx > 0) {
					p.s_txt = p.s_txt.substr(0, cx - 1) + p.s_txt.substr(cx, p.s_txt.length - cx);
					if (offset > 0)
						offset--;
					cx--;
				}
			} else {
				if (e - s == p.s_txt.length) {
					p.s_txt = "";
					cx = 0;
				} else {
					if (s > 0) {
						var st = s,
						en = e;
						s = Math.min(st, en);
						e = Math.max(st, en);
						p.s_txt = p.s_txt.substring(0, s) + p.s_txt.substring(e, p.s_txt.length);
						cx = s;
					} else {
						p.s_txt = p.s_txt.substring(e, p.s_txt.length);
						cx = s;
					}
				}
			}
			calc_text();
			offset = offset >= e - s ? offset - e + s : 0;
			s = cx;
			e = s;
			break;
		case v.del:
			record();
			if (s == e) {
				if (cx < p.s_txt.length) {
					p.s_txt = p.s_txt.substr(0, cx) + p.s_txt.substr(cx + 1, p.s_txt.length - cx - 1);
				}
			} else {
				if (e - s == p.s_txt.length) {
					p.s_txt = "";
					cx = 0;
				} else {
					if (s > 0) {
						var st = s,
						en = e;
						s = Math.min(st, en);
						e = Math.max(st, en);
						p.s_txt = p.s_txt.substring(0, s) + p.s_txt.substring(e, p.s_txt.length);
						cx = s;
					} else {
						p.s_txt = p.s_txt.substring(e, p.s_txt.length);
						cx = s;
					}
				}
			}
			calc_text();
			offset = offset >= e - s ? offset - e + s : 0;
			s = cx;
			e = s;
			break;
		case v.paste:
			text = doc.parentWindow.clipboardData.getData('text');
		default:
			record();
			if (s == e) {
				p.s_txt = p.s_txt.substring(0, cx) + text + p.s_txt.substring(cx);
				cx += text.length;
				e = s = cx;
			} else {
				p.s_txt = p.s_txt.substring(0, s) + text + p.s_txt.substring(e);
				cx = s + text.length;
				e = s;
			}
			break;
		}
		if (!timer.search_cursor)
			timer.search_cursor = window.SetInterval(function () {
					p.s_cursor = !p.s_cursor;
					p.search_paint();
				}, 530);
		p.search_paint();
		lib.upd_search = true;
		timer.reset(timer.search, 3);
		timer.search = window.SetTimeout(function () {
				lib.time.Reset();
				lib.rootNodes();
				timer.reset(timer.search, 3);
			}, 160);
	}

	this.on_key_down = function (vkey) {
		if (!p.s_search)
			return;
		switch (vkey) {
		case v.left:
		case v.right:
			if (vkey == v.left) {
				if (offset > 0) {
					if (cx <= offset) {
						offset--;
						cx--;
					} else
						cx--;
				} else if (cx > 0)
					cx--;
				s = e = cx
			}
			if (vkey == v.right && cx < p.s_txt.length)
				cx++;
			s = e = cx;
			if (shift) {
				s = Math.min(cx, shift_x);
				e = Math.max(cx, shift_x);
			}
			p.s_cursor = true;
			timer.reset(timer.search_cursor, 4);
			timer.search_cursor = window.SetInterval(function () {
					p.s_cursor = !p.s_cursor;
					p.search_paint();
				}, 530);
			break;
		case v.home:
		case v.end:
			if (vkey == v.home)
				offset = s = e = cx = 0;
			else
				s = e = cx = p.s_txt.length;
			p.s_cursor = true;
			timer.reset(timer.search_cursor, 4);
			timer.search_cursor = window.SetInterval(function () {
					p.s_cursor = !p.s_cursor;
					p.search_paint();
				}, 530);
			break;
		case v.shift:
			shift = true;
			shift_x = cx;
			break;
		case v.del:
			this.on_char(v.del);
			break;
		}
		p.search_paint();
	}

	this.draw = function (gr) {
		s = Math.min(Math.max(s, 0), p.s_txt.length);
		e = Math.min(Math.max(e, 0), p.s_txt.length);
		cx = Math.min(Math.max(cx, 0), p.s_txt.length);
		if (ui.fill)
			gr.FillSolidRect(0, 1, ui.w, ui.row_h - 4, 0x60000000);
		if (ui.pen == 1)
			gr.DrawLine(ui.margin, p.s_sp, p.s_w1, p.s_sp, 1, ui.s_linecol);
		if (ui.pen == 2)
			gr.DrawRoundRect(0, 2, ui.w - 1, ui.row_h - 4, 4, 4, 1, ui.pen_c);
		if (p.s_txt) {
			e = (e < p.s_txt.length) ? e : p.s_txt.length;
			drawsel(gr);
			get_offset(gr);
			gr.GdiDrawText(p.s_txt.substr(offset), ui.font, ui.searchcol, p.s_x, 0, p.s_w2, p.s_sp, p.l);
		} else
			gr.GdiDrawText("Search", ui.s_font, ui.txt_box, p.s_x, 0, p.s_w2, p.s_sp, p.l);
		drawcursor(gr);
		if (p.s_show > 1) {
			var l_x = p.f_x1 - 9,
			l_h = Math.round(p.s_sp / 2);
			gr.gdiDrawText(p.filt[p.filter_by].name, p.f_font, ui.txt_box, p.f_x1, 0, p.f_w[p.filter_by], p.s_sp, p.cc);
			gr.FillGradRect(l_x, 0, 1, l_h, 90, RGBA(0, 0, 0, 0), ui.s_linecol);
			gr.FillGradRect(l_x, l_h, 1, l_h, 90, ui.s_linecol, RGBA(0, 0, 0, 0));
		}
	}
}
if (p.s_show)
	var sL = new searchLibrary();

var j_Search = function () {
	var j_x = 5,
	j_h = 30,
	j_y = 5,
	jSearch = "",
	jump_search = true,
	rs1 = 5,
	rs2 = 4;
	this.on_size = function () {
		j_x = Math.round(ui.w / 2),
		j_h = Math.round(ui.row_h * 1.5),
		j_y = Math.round((ui.h - j_h) / 2);
		rs1 = Math.min(5, j_h / 2);
		rs2 = Math.min(4, (j_h - 2) / 2);
	}

	this.on_char = function (code) {
		var text = String.fromCharCode(code);
		if (!p.s_search) {
			var found = false,
			i = 0,
			pos = -1;
			switch (code) {
			case v.back:
				jSearch = jSearch.substr(0, jSearch.length - 1);
				break;
			case v.enter:
				jSearch = "";
				return;
			default:
				jSearch += text;
				break;
			}
			var l = pop.tree.length;
			for (i = 0; i < l; i++)
				pop.tree[i].sel = false;
			if (!jSearch)
				return;
			pop.sel_items = [];
			jump_search = true;
			window.RepaintRect(0, j_y, ui.w, j_h + 1);
			timer.reset(timer.jsearch, 2);
			timer.jsearch = window.SetTimeout(function () {
					for (i = 0; i < l; i++) {
						if (pop.tree[i].name.substring(0, jSearch.length).toLowerCase() == jSearch.toLowerCase()) {
							found = true;
							pos = i;
							pop.tree[i].sel = true;
							pop.sel_items.push.apply(pop.sel_items, pop.tree[i].item);
							break;
						}
					}
					if (!found)
						jump_search = false;
					p.tree_paint();
					sbar.check_scroll((pos - 5) * ui.row_h);
					timer.reset(timer.jsearch, 2);
				}, 500);

			timer.reset(timer.clear_jsearch, 0);
			timer.clear_jsearch = window.SetTimeout(function () {
					if (found)
						pop.load(pop.sel_items, true, false, false, true);
					jSearch = "";
					window.RepaintRect(0, j_y, ui.w, j_h + 1);
					timer.reset(timer.clear_jsearch, 0);
				}, 5000);//1200 jump search timer
		}
	}

	this.draw = function (gr) {
		if (jSearch) {
			gr.SetSmoothingMode(4);
			var j_w = gr.CalcTextWidth(jSearch, ui.j_font) + 25;
			gr.FillRoundRect(j_x - j_w / 2, j_y, j_w, j_h, rs1, rs1, 0x96000000);
			gr.DrawRoundRect(j_x - j_w / 2, j_y, j_w, j_h, rs1, rs1, 1, 0x64000000);
			gr.DrawRoundRect(j_x - j_w / 2 + 1, j_y + 1, j_w - 2, j_h - 2, rs2, rs2, 1, 0x28ffffff);
			gr.GdiDrawText(jSearch, ui.j_font, RGB(0, 0, 0), j_x - j_w / 2 + 1, j_y + 1, j_w, j_h, p.cc);
			gr.GdiDrawText(jSearch, ui.j_font, jump_search ? 0xfffafafa : 0xffff4646, j_x - j_w / 2, j_y, j_w, j_h, p.cc);
		}
	}
}
var jS = new j_Search();

function on_paint(gr) {
	if (ui.bg)
		gr.FillSolidRect(0, 0, ui.w, ui.h, ui.backcol);

	if (fb.IsPlaying && g_wallpaperImg && ppt.showwallpaper) {
		gr.GdiDrawBitmap(g_wallpaperImg, 0, 0, ww, wh, 0, 0, g_wallpaperImg.Width, g_wallpaperImg.Height);
		gr.FillSolidRect(0, 0, ww, wh, g_color_normal_bg & RGBA(255, 255, 255, ppt.wallpaperalpha));
	};
	else {
		gr.FillSolidRect(0, 0, ww, wh, g_color_normal_bg);
		if (g_wallpaperImg && ppt.showwallpaper) {
			gr.GdiDrawBitmap(g_wallpaperImg, 0, 0, ww, wh, 0, 0, g_wallpaperImg.Width, g_wallpaperImg.Height);
			gr.FillSolidRect(0, 0, ww, wh, g_color_normal_bg & RGBA(255, 255, 255, ppt.wallpaperalpha));
		};
		else {
			gr.FillSolidRect(0, 0, ww, wh, g_color_normal_bg);
		};

	};

	if (lib.upd) {
		lib.refresh();
		lib.upd = false;
		return;
	}
	if (p.s_show)
		sL.draw(gr);
	pop.draw(gr);
	if (p.s_show || ui.scrollbar_show)
		but.draw(gr);
	if (ui.scrollbar_show)
		sbar.draw(gr);
	jS.draw(gr);
}

function button_manager() {
	var b_x,
	b_h,
	but_tt = window.CreateTooltip("Segoe UI", 15, 0),
	bx,
	by,
	bh,
	byDn,
	byUp,
	fw,
	i,
	qx,
	qy,
	qh,
	s_img = [],
	scr = [];
	this.btns = [];
	this.b = null;
	var browser = function (c) {
		if (!run(c))
			fb.ShowPopupMessage("Unable to launch your default browser.", "Library Tree");
	}
	var run = function (c) {
		try {
			var WshShell = new ActiveXObject("WScript.Shell");
			WshShell.Run(c);
			return true;
		} catch (e) {
			return false;
		}
	}
	var tooltip = function (n) {
		if (but_tt.text == n)
			return;
		but_tt.text = n;
		but_tt.activate();
	}
	this.lbtn_dn = function (x, y) {
		if (!this.b)
			return false;
		this.btns[this.b].lbtn_dn(x, y);
		return true;
	}
	this.lbtn_up = function (x, y) {
		if (!this.b)
			return false;
		this.btns[this.b].lbtn_up(x, y);
		return true;
	}
	this.leave = function () {
		if (this.b)
			this.btns[this.b].changestate("normal");
		this.b = null;
		tooltip("");
	}

	this.create_images = function () {
		var c,
		g;
		for (var j = 0; j < 2; j++) {
			c = j ? 0xe4ffffff : 0x99ffffff;
			s_img[j] = gdi.CreateImage(100, 100);
			g = s_img[j].GetGraphics();
			g.SetSmoothingMode(2);
			if (!ui.local) {
				g.DrawLine(69, 71, 88, 90, 12, ui.txt_box & c);
				g.DrawEllipse(8, 11, 67, 67, 10, ui.txt_box & c);
			} else {
				g.DrawLine(69, 71, 88, 90, 12, ui.txt_box);
				g.DrawEllipse(8, 11, 67, 67, 10, ui.txt_box);
			}
			g.FillEllipse(15, 17, 55, 55, 0x0AFAFAFA);
			g.SetSmoothingMode(0);
			s_img[j].ReleaseGraphics(g);
		}
		for (var j = 0; j < 2; j++) {
			scr[j] = gdi.CreateImage(100, 100);
			g = scr[j].GetGraphics();
			g.SetSmoothingMode(2);
			g.FillPolygon(RGBA(200, 200, 200, j ? 192 : 75), 1, [50, 0, 93, 76, 6, 76]);
			g.SetSmoothingMode(0);
			scr[j].ReleaseGraphics(g);
		}
	};
	this.create_images();

	this.draw = function (gr) {
		for (i in this.btns) {
			if ((p.s_show == 1 || p.s_show > 1 && !p.s_txt) && i == "s_img")
				this.btns[i].draw(gr);
			if (p.s_show == 1 && i == "cross1")
				this.btns[i].draw(gr);
			if (p.s_show > 1 && p.s_txt && i == "cross2")
				this.btns[i].draw(gr);
			if (p.s_show > 1 && i == "filter")
				this.btns[i].draw(gr);
			if (i == "scrollUp" || i == "scrollDn")
				this.btns[i].draw(gr);
		}
	}

	this.move = function (x, y) {
		var b = null,
		hand = false;
		for (i in this.btns) {
			if ((p.s_show == 1 || p.s_show > 1 && !p.s_txt) && i == "s_img" && this.btns[i].trace(x, y)) {
				b = i;
				hand = true;
			}
			if (p.s_show == 1 && i == "cross1" && this.btns[i].trace(x, y)) {
				b = i;
				hand = true;
			}
			if (p.s_show > 1 && p.s_txt && i == "cross2" && this.btns[i].trace(x, y)) {
				b = i;
				hand = true;
			}
			if (p.s_show > 1 && i == "filter" && this.btns[i].trace(x, y)) {
				b = i;
				hand = true;
			}
			if ((i == "scrollUp" || i == "scrollDn") && this.btns[i].trace(x, y))
				b = i;
		}
		window.SetCursor(hand ? 32649 : y < p.s_h && p.s_show && x > qx + qh ? 32513 : 32512);
		if (this.b == b)
			return this.b;
		if (b)
			this.btns[b].changestate("hover");
		if (this.b)
			this.btns[this.b].changestate("normal");
		this.b = b;
		if (!this.b)
			tooltip("");
		return this.b;
	}

	var btn = function (x, y, w, h, type, ft, txt, stat, img_src, l_dn, l_up, tooltext) {
		this.draw = function (gr) {
			switch (type) {
			case 3:
				gr.SetInterpolationMode(2);
				if (this.img)
					gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, 0, this.img.Width, this.img.Height);
				gr.SetInterpolationMode(0);
				break;
			case 4:
				gr.DrawLine(Math.round(this.x + bh * 0.67), Math.round(this.y + bh * 0.67), Math.round(this.x + bh * 0.27), Math.round(this.y + bh * 0.27), Math.round(bh / 10), RGBA(136, 136, 136, this.img));
				gr.DrawLine(Math.round(this.x + bh * 0.67), Math.round(this.y + bh * 0.27), Math.round(this.x + bh * 0.27), Math.round(this.y + bh * 0.67), Math.round(bh / 10), RGBA(136, 136, 136, this.img));
				break;
			case 5:
				gr.SetTextRenderingHint(3);
				gr.DrawString(txt, ft, this.img, this.x, this.y - 1, this.w, this.h, StringFormat(2, 1));
				break;
			default:
				if (this.img && sbar.scrollable_lines > 0)
					gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, 0, this.img.Width, this.img.Height, type == 1 ? 0 : 180);
				break;
			}
		}
		this.trace = function (x, y) {
			return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h;
		}
		this.lbtn_dn = function () {
			this.l_dn && this.l_dn(x, y);
		}
		this.lbtn_up = function () {
			this.l_up && this.l_up(x, y);
		}

		this.changestate = function (state) {
			if (state == "hover") {
				this.img = this.img_hover;
				tooltip(this.tooltext);
			} else {
				this.img = this.img_normal;
			}
			try{
			window.RepaintRect(this.x, this.y, this.w, this.h);
			}catch(e){}
		}
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.l_dn = l_dn;
		this.l_up = l_up;
		this.tooltext = tooltext;
		this.img_normal = img_src.normal;
		this.img_hover = img_src.hover || this.img_normal;
		this.img = this.img_normal;
	}

	this.refresh = function (upd) {
		if (upd) {
			bx = p.s_w1 - Math.round(ui.row_h * 0.75);
			bh = ui.row_h;
			by = Math.round((p.s_sp - bh * 0.4) / 2 - bh * 0.27);
			b_x = ui.w - ui.scr_w - 1;
			byUp = p.s_h;
			byDn = sbar.y + sbar.h - ui.scr_w;
			fw = p.f_w[p.filter_by] + p.f_sw + 12;
			qx = ui.margin;
			qy = (p.s_sp - ui.row_h * 0.6) / 2;
			qh = ui.row_h * 0.6;
		}
		if (ui.scrollbar_show) {
			this.btns.scrollUp = new btn(b_x, byUp, ui.scr_w, ui.scr_w, 1, "", "", "", {
					normal : scr[0],
					hover : scr[1]
				}, function () {
					sbar.but(1);
				}, "", "");
			this.btns.scrollDn = new btn(b_x, byDn, ui.scr_w, ui.scr_w, 2, "", "", "", {
					normal : scr[0],
					hover : scr[1]
				}, function () {
					sbar.but(-1);
				}, "", "");
		}
		if (p.s_show) {
			this.btns.s_img = new btn(qx, qy, qh, qh, 3, "", "", "", {
					normal : s_img[0],
					hover : s_img[1]
				}, function () {
					browser("\"" + fb.FoobarPath + "Query Syntax Help.html");
				}, "", "Open Query Syntax Help");
			this.btns.cross1 = new btn(bx, by, bh, bh, 4, "", "", "", {
					normal : "85",
					hover : "192"
				}, "", function () {
					sL.clear();
				}, "Clear Search Text");
			this.btns.cross2 = new btn(qx - bh * 0.2, by, bh, bh, 4, "", "", "", {
					normal : "85",
					hover : "192"
				}, "", function () {
					sL.clear();
				}, "Clear Search Text");
			this.btns.filter = new btn(p.f_x1 - 12, 0, fw, p.s_sp, 5, p.f_but_ft, "Ў", "", {
					normal : !ui.local ? ui.txt_box & 0x99ffffff : ui.txt_box,
					hover : ui.txt_box & 0xe4ffffff
				}, "", function () {
					men.button(p.f_x1, p.s_h);
					but.refresh(true)
				}, "Filter");
		}

	}
}
var but = new button_manager();

function menu_object() {
	var i = 0,
	MenuMap = [],
	MF_GRAYED = 0x00000001,
	MF_POPUP = 0x00000010,
	MF_SEPARATOR = 0x00000800,
	MF_STRING = 0x00000000;
	this.NewMenuItem = function (index, type, value) {
		MenuMap[index] = [{
				type : ""
			}, {
				value : 0
			}
		];
		MenuMap[index].type = type;
		MenuMap[index].value = value;
	}
	this.PlaylistTypeMenu = function (Menu, StartIndex) {
		var Index = StartIndex,
		n = ["Send to Current Playlist", "Add to Current Playlist"];
		for (i = 0; i < 2; i++) {
			this.NewMenuItem(Index, "Playlist", i + 1);
			Menu.AppendMenuItem(MF_STRING, Index, n[i]);
			Index++;
		}
		return Index;
	}
	this.OptionsTypeMenu = function (Menu, StartIndex) {
		var Index = StartIndex,
		mt = p.syncType ? 1 : 0;
		for (i = 0; i < p.menu.length; i++) {
			this.NewMenuItem(Index, "Options", i + 1);
			if (i < p.menu.length - 1 || i == p.menu.length - 1 && v.k(0))
				Menu.AppendMenuItem(MF_STRING, Index, p.menu[i]);
			if (i < p.menu.length - 2 - mt)
				Menu.CheckMenuItem(Index++, p.view_by == i);
			else
				Index++;
			if (i == p.menu.length - 3 - mt || i == p.menu.length - 4 - mt)
				Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
		}
		return Index;
	}

	this.FilterMenu = function (Menu, StartIndex) {
		var Index = StartIndex;
		for (i = 0; i < p.f_menu.length + 1; i++) {
			this.NewMenuItem(Index, "Filter", i + 1);
			Menu.AppendMenuItem(MF_STRING, Index, i != p.f_menu.length ? (!i ? "No " : "") + p.f_menu[i] : "Always Reset Scroll");
			Menu.CheckMenuItem(Index++, i < p.f_menu.length ? i == p.filter_by : p.reset);
			if (i == p.f_menu.length - 1)
				Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
		}
		return Index;
	}

	this.button = function (x, y) {
		var menu = window.CreatePopupMenu(),
		idx,
		Index = 1;
		Index = this.FilterMenu(menu, Index);
		idx = menu.TrackPopupMenu(x, y);
		if (idx >= 1 && idx <= Index) {
			i = MenuMap[idx].value;
			switch (i) {
			case p.f_menu.length + 1:
				p.reset = !p.reset;
				if (p.reset) {
					p.search_paint();
					lib.refresh(true);
				}
				window.SetProperty("SYSTEM.Reset Tree", p.bypass);
				break;
			default:
				p.filter_by = i - 1;
				p.set_statistics_mode();
				p.calc_text();
				p.search_paint();
				lib.refresh(true);
				window.SetProperty("SYSTEM.Filter By", p.filter_by);
				break;
			}
		}
		menu.Dispose();
	}

	this.search = function (Menu, StartIndex, s, e, paste) {
		var Index = StartIndex,
		n = ["Copy", "Cut", "Paste"];
		for (i = 0; i < 3; i++) {
			this.NewMenuItem(Index, "Search", i + 1);
			Menu.AppendMenuItem(s == e && i < 2 || i == 2 && !paste ? MF_GRAYED : MF_STRING, Index, n[i]);
			Index++;
			if (i == 1)
				Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
		}
		return Index;
	}

	this.search_menu = function (x, y, s, e, paste) {
		var menu = window.CreatePopupMenu(),
		idx,
		Index = 1;
		Index = this.search(menu, Index, s, e, paste);
		idx = menu.TrackPopupMenu(x, y);
		if (idx >= 1 && idx <= Index) {
			i = MenuMap[idx].value;
			switch (i) {
			case 1:
				sL.on_char(v.copy);
				break;
			case 2:
				sL.on_char(v.cut);
				break;
			case 3:
				sL.on_char(v.paste, true);
				break;
			}
		}
		menu.Dispose();
	}

	this.rbtn_up = function (x, y) {
		var Context = fb.CreateContextMenuManager(),
		FilterMenu = window.CreatePopupMenu(),
		idx,
		Index = 1,
		menu = window.CreatePopupMenu(),
		new_sel = false,
		OptionsMenu = window.CreatePopupMenu(),
		PlaylistMenu = window.CreatePopupMenu(),
		show_context = false;
		var ix = Math.round((y + sbar.delta - p.s_h - ui.row_h * 0.5) / ui.row_h);
		if (y > p.s_h && pop.tree.length > ix && ix >= 0 && x < p.s_w1 && pop.check_ix(pop.tree[ix], x, y, true)) {
			if (!pop.tree[ix].sel) {
				new_sel = true;
				pop.get_selection(ix, "", true, true);
			}
			Index = this.PlaylistTypeMenu(menu, Index);
			menu.AppendMenuSeparator();
			show_context = true;
		}
		if (show_context) {
			Index = this.OptionsTypeMenu(OptionsMenu, Index);
			OptionsMenu.AppendTo(menu, MF_STRING | MF_POPUP, "Options");
			menu.AppendMenuSeparator();
			var items = p.items();
			for (var l in pop.sel_items)
				items.Add(p.list.Item(pop.sel_items[l]));
			Context.InitContext(items);
			Context.BuildMenu(menu, 5000, -1);
		} else
			Index = this.OptionsTypeMenu(menu, Index);
		idx = menu.TrackPopupMenu(x, y);
		if (idx >= 1 && idx <= Index) {
			i = MenuMap[idx].value;
			switch (MenuMap[idx].type) {
			case "Playlist":
				switch (i) {
				case 1:
					if (new_sel)
						for (var k = 0; k < pop.tree.length; k++)
							pop.tree[k].sel = false;
					pop.tree[ix].sel = true;
					pop.load(pop.sel_items, true, false, true, true);
					p.tree_paint();
					break;
				case 2:
					pop.tree[ix].sel = true;
					pop.load(pop.sel_items, true, true, false, true);
					break;
				}
				break;
			case "Options":
				var mtt = i == p.menu.length - 2 && p.syncType ? 1 : i == p.menu.length - 1 ? 2 : i == p.menu.length ? 3 : 4;
				switch (mtt) {
				case 1:
					window.ShowProperties();
					break;
				case 2:
					p.syncType ? lib.update() : window.ShowProperties();
					break;
				case 3:
					window.ShowConfigure();
					break;
				case 4:
					lib.time.Reset();
					if (p.s_txt)
						lib.upd_search = true;
					p.fields(i < p.grp.length + 1 ? i - 1 : p.view_by, i - 1 < p.grp.length ? p.filter_by : i - 1 - p.grp.length);
					if (i == p.folder_view + 1)
						lib.get_paths = true;
					lib.get_library();
					lib.rootNodes();
					break;
				}
				break;
			}
		}
		if (idx >= 5000 && idx <= 5800) {
			show_context && Context.ExecuteByID(idx - 5000);
		}
		Context.Dispose();
		FilterMenu.Dispose();
		menu.Dispose();
		OptionsMenu.Dispose();
		PlaylistMenu.Dispose();
	}
}
var men = new menu_object();

function timers() {
	var timer_arr = ["clear_jsearch", "init", "jsearch", "search", "search_cursor", "tt", "update"];
	for (var i = 0; i < timer_arr.length; i++)
		this[timer_arr[i]] = false;
	this.reset = function (timer, n) {
		if (timer)
			window.ClearTimeout(timer);
		this[timer_arr[n]] = false;
	}
	this.lib = function () {
		this.init = window.SetTimeout(function () {
				lib.get_library();
				lib.rootNodes();
				timer.reset(timer.init, 1);
			}, 5);
	}
	this.tooltip = function () {
		this.reset(this.tt, 6);
		this.tt = window.SetTimeout(function () {
				pop.deactivate_tooltip();
				timer.reset(timer.tt, 5);
			}, 5000);
	}
	this.lib_update = function () {
		this.reset(this.update, 6);
		this.update = window.SetTimeout(function () {
				lib.update();
				timer.reset(timer.update, 6);
			}, 500);
	}
}
var timer = new timers();
timer.lib();

this.touch_sens = window.GetProperty(" Scroll - Touch Mouse Sensitive: Step", 24);
var lbtn_touch_dn = 0;
var y_start = 0;
var y_end = 0;
var y_delta = 0;

function on_char(code) {
	if (!p.s_show)
		return;
	sL.on_char(code);
	jS.on_char(code)
}
function on_key_down(vkey) {
	pop.on_key_down(vkey);
	if (!p.s_show)
		return;
	sL.on_key_down(vkey);
}
function on_key_up(vkey) {
	if (!p.s_show)
		return;
	sL.on_key_up(vkey)
}
function on_library_items_added() {
	if (p.syncType)
		return;
	timer.lib_update();
}
function on_library_items_removed() {
	if (p.syncType)
		return;
	timer.lib_update();
}
function on_library_items_changed() {
	if (p.syncType || !p.statistics && fb.PlaybackTime > 59 && fb.PlaybackTime < 65)
		return;
	timer.lib_update();
}
function on_mouse_lbtn_dblclk(x, y) {
	but.lbtn_dn(x, y);
	pop.lbtn_dblclk(x, y);
}
function on_mouse_lbtn_down(x, y) {
	lbtn_touch_dn = 1;
	y_start = y;
	if (p.s_show || ui.scrollbar_show)
		but.lbtn_dn(x, y);
	if (p.s_show)
		sL.lbtn_dn(x, y);
	pop.lbtn_dn(x, y);
	sbar.lbtn_dn(x, y);
}
function on_mouse_lbtn_up(x, y) {
	lbtn_touch_dn = 0;
	y_start = y;
	if (p.s_show) {
		sL.lbtn_up();
		but.lbtn_up(x, y);
	}
	sbar.lbtn_up(x, y);
}
function on_mouse_leave() {
	if (p.s_show || ui.scrollbar_show)
		but.leave();
	sbar.leave();
}
function on_mouse_mbtn_down(x, y) {
	pop.mbtn_dn(x, y);
}
function on_mouse_move(x, y) {
	if (p.m_x == x && p.m_y == y)
		return;
	if (p.s_show || ui.scrollbar_show)
		but.move(x, y);
	if (p.s_show)
		sL.move(x, y);
	pop.move(x, y);
	sbar.move(x, y);
	p.m_x = x;
	p.m_y = y;
	if (lbtn_touch_dn) {
		//mouse_drag = false;
		y_end = y;
		y_delta = (y_end - y_start);
		if (x < ww) {

			if (y_delta > ui.h / this.touch_sens) {
				on_mouse_wheel(1);
				y_start = y_end;
			};
			if (y_delta < -ui.h / this.touch_sens) {
				on_mouse_wheel(-1);
				y_start = y_end;
			};

		};
	};
}
function on_mouse_rbtn_up(x, y) {
	if (y < p.s_h && x > p.s_x && x < p.s_x + p.s_w2) {
		sL.rbtn_up(x, y);
		return true;
	} else {
		men.rbtn_up(x, y);
		return true;
	}
}
function on_mouse_wheel(step) {
	if (!v.k(1))
		sbar.wheel(step);
	else
		ui.wheel(step);
}
function RGB(r, g, b) {
	return 0xff000000 | r << 16 | g << 8 | b;
}
function RGBA(r, g, b, a) {
	return a << 24 | r << 16 | g << 8 | b;
}
function StringFormat() {
	var a = arguments,
	h_align = 0,
	v_align = 0,
	trimming = 0,
	flags = 0;
	switch (a.length) {
	case 3:
		trimming = a[2];
	case 2:
		v_align = a[1];
	case 1:
		h_align = a[0];
		break;
	default:
		return 0;
	}
	return (h_align << 28 | v_align << 24 | trimming << 20 | flags);
}
window.SetProperty("_Custom.Colour Filter Line", null);
window.SetProperty("_Custom.Colour Filter Name", null);
window.SetProperty("_Custom.Colour Filter Search Text", null);
window.SetProperty(" DblClick Action: Expand/Collapse-0 Send&Play-1", null);
window.SetProperty(" DblClick: Expand-0 Play-1 Expand&Play-2", null);
window.SetProperty(" Filter Show", null);
window.SetProperty(" Filter Style: Fade-0 Blend-1 Normal-2 Highlight-3", null);
window.SetProperty(" Filter: Line Colour: Grey-0 Blend-1 Text-2", null);

function setWallpaperImg(path, metadb) {
	var fmt_path = fb.TitleFormat(path).Eval(true);
	var fmt_path_arr = utils.Glob(fmt_path).toArray();
	if (fmt_path_arr.length > 0) {
		var final_path = fmt_path_arr[0];
	};
	else {
		var final_path = null;
	};

	if (metadb && ppt.wallpapermode == 0) {
		var tmp_img = utils.GetAlbumArtV2(metadb, ppt.wallpapermode);
	};
	else {
		if (final_path) {
			tmp_img = gdi.Image(final_path);
		};
		else {
			tmp_img = null;
		};
	};
	if (!tmp_img) {
		if (final_path) {
			tmp_img = gdi.Image(final_path);
		};
		else {
			tmp_img = null;
		};
	};

	g_wallpaperImg = null;
	var img = FormatWallpaper(tmp_img, ww, wh, 2, 0, 0, "", true);
	return img;
};

function draw_blurred_image(image, ix, iy, iw, ih, bx, by, bw, bh, blur_value, overlay_color) {
	var blurValue = blur_value;
	var imgA = image.Resize(iw * blurValue / 100, ih * blurValue / 100, 2);
	var imgB = imgA.resize(iw, ih, 2);
	var overlay_color = RGBA(0, 0, 0, ppt.wallpaperoverlayalfa); //50);

	var bbox = gdi.CreateImage(bw, bh);
	// Get graphics interface like "gr" in on_paint
	var gb = bbox.GetGraphics();
	var offset = 90 - blurValue;
	gb.DrawImage(imgB, 0 - offset, 0 - (ih - bh) - offset, iw + offset * 2, ih + offset * 2, 0, 0, imgB.Width, imgB.Height, 0, 255);
	bbox.ReleaseGraphics(gb);

	var newImg = gdi.CreateImage(iw, ih);
	var gb = newImg.GetGraphics();

	if (ix != bx || iy != by || iw != bw || ih != bh) {
		gb.DrawImage(image, ix, iy, iw, ih, 0, 0, image.Width, image.Height, 0, 255);
		gb.FillSolidRect(bx, by, bw, bh, 0xffffffff);
	};
	gb.DrawImage(bbox, bx, by, bw, bh, 0, 0, bbox.Width, bbox.Height, 0, 255);

	// overlay
	if (overlay_color != null) {
		gb.FillSolidRect(bx, by, bw, bh, overlay_color);
	};

	// top border of blur area
	if (ix != bx || iy != by || iw != bw || ih != bh) {
		gb.FillSolidRect(bx, by, bw, 1, 0x22ffffff);
		gb.FillSolidRect(bx, by - 1, bw, 1, 0x22000000);
	};
	newImg.ReleaseGraphics(gb);

	return newImg;
};

function FormatWallpaper(image, iw, ih, interpolation_mode, display_mode, angle, txt, rawBitmap) {
	if (!image || !iw || !ih)
		return image;
	var i,
	j;

	var panel_ratio = iw / ih;
	wpp_img_info.ratio = image.Width / image.Height;
	wpp_img_info.orient = 0;

	if (wpp_img_info.ratio > panel_ratio) {
		wpp_img_info.orient = 1;
		// 1/3 : default image is in landscape mode
		switch (display_mode) {
		case 0: // Filling
			//wpp_img_info.w = iw * wpp_img_info.ratio / panel_ratio;
			wpp_img_info.w = ih * wpp_img_info.ratio;
			wpp_img_info.h = ih;
			wpp_img_info.cut = wpp_img_info.w - iw;
			wpp_img_info.x = 0 - (wpp_img_info.cut / 2);
			wpp_img_info.y = 0;
			break;
		case 1: // Adjust
			wpp_img_info.w = iw;
			wpp_img_info.h = ih / wpp_img_info.ratio * panel_ratio;
			wpp_img_info.cut = ih - wpp_img_info.h;
			wpp_img_info.x = 0;
			wpp_img_info.y = wpp_img_info.cut / 2;
			break;
		case 2: // Stretch
			wpp_img_info.w = iw;
			wpp_img_info.h = ih;
			wpp_img_info.cut = 0;
			wpp_img_info.x = 0;
			wpp_img_info.y = 0;
			break;
		};
	};
	else if (wpp_img_info.ratio < panel_ratio) {
		wpp_img_info.orient = 2;
		// 2/3 : default image is in portrait mode
		switch (display_mode) {
		case 0: // Filling
			wpp_img_info.w = iw;
			//wpp_img_info.h = ih / wpp_img_info.ratio * panel_ratio;
			wpp_img_info.h = iw / wpp_img_info.ratio;
			wpp_img_info.cut = wpp_img_info.h - ih;
			wpp_img_info.x = 0;
			wpp_img_info.y = 0 - (wpp_img_info.cut / 4);
			break;
		case 1: // Adjust
			wpp_img_info.h = ih;
			wpp_img_info.w = iw * wpp_img_info.ratio / panel_ratio;
			wpp_img_info.cut = iw - wpp_img_info.w;
			wpp_img_info.y = 0;
			wpp_img_info.x = wpp_img_info.cut / 2;
			break;
		case 2: // Stretch
			wpp_img_info.w = iw;
			wpp_img_info.h = ih;
			wpp_img_info.cut = 0;
			wpp_img_info.x = 0;
			wpp_img_info.y = 0;
			break;
		};
	};
	else {
		// 3/3 : default image is a square picture, ratio = 1
		wpp_img_info.w = iw;
		wpp_img_info.h = ih;
		wpp_img_info.cut = 0;
		wpp_img_info.x = 0;
		wpp_img_info.y = 0;
	};

	var tmp_img = gdi.CreateImage(iw, ih);
	var gp = tmp_img.GetGraphics();
	gp.SetInterpolationMode(interpolation_mode);
	gp.DrawImage(image, wpp_img_info.x, wpp_img_info.y, wpp_img_info.w, wpp_img_info.h, 0, 0, image.Width, image.Height, angle, ppt.wallpaperalfa); //255);
	tmp_img.ReleaseGraphics(gp);

	// blur it!
	if (ppt.wallpaperblurred) {
		var blur_factor = ppt.wallpaperblurvalue; // [1-90]
		tmp_img = draw_blurred_image(tmp_img, 0, 0, tmp_img.Width, tmp_img.Height, 0, 0, tmp_img.Width, tmp_img.Height, blur_factor, 0x00ffffff);
	};

	CollectGarbage();
	if (rawBitmap) {
		return tmp_img.CreateRawBitmap();
	};
	else {
		return tmp_img;
	};
};

function on_playback_new_track(metadb) {
	g_metadb = metadb;
	if (ppt.showwallpaper) {
		g_wallpaperImg = setWallpaperImg(ppt.wallpaperpath, metadb);
	};
	on_size();
	window.Repaint();
};
function on_notify_data(name, info) {
    if (name == "library" && info == "send_to_pl") {
		on_key_down(v.enter);
		//window.Repaint();
        window.NotifyOthers("lib_btns", "send_to_pl_ok");
    };
};
?
Миниатюры
Нажмите на изображение для увеличения
Название: Без имени-7.jpg
Просмотров: 654
Размер:	67.4 Кб
ID:	44104  

Последний раз редактировалось seriousstas; 28.06.2016 в 18:54.
seriousstas вне форума   Ответить с цитированием
Старый 29.06.2016, 06:53   #1963
seriousstas
Бывалый писикарщик
 
Регистрация: 14.06.2013
Регион: Украина
Машина: Nissan Qashqai+2
Сообщений: 3,424
seriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant future
По умолчанию

duzzy
проверь такой вариант по :
Цитата:
// @author "Wilb"
// @version "0.8"
Если добавить одну или несколько папок треками (без подпапок) -
в режиме View by Folder Structure папок не будет - только треки вперемешку .
seriousstas вне форума   Ответить с цитированием
Старый 29.06.2016, 15:42   #1964
duzzy
Гуру
 
Регистрация: 01.06.2013
Регион: 78, 98
Машина: SUBARU Impreza WRX
Сообщений: 1,766
duzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond repute
По умолчанию

seriousstas
Цитата:
Думал, но ..
Все не так просто - там по линиям ещё несколько параметров,
Ааа... много параметров менять, если разные значения то вариант с Пропертис не подойдет.
Цитата:
Ну хорошо , а как Тебе такой вариант с полупрозрачними "точками" )
Такой вариант уже лучше
Я просто не большой фанат UI элементов, с ними бывают проблемы в скриптах... в скрипты можно подтягивать виндовые кнопки, скролбары, прогрессбары и т.д.
Цитата:
Если добавить одну или несколько папок треками (без подпапок) -
в режиме View by Folder Structure папок не будет - только треки вперемешку .
У меня нормально папки с треками добавляет... как при Add так и при Send
Может я что не так добавляю ?
Я давно с ним езжу пока проблем не было
duzzy вне форума   Ответить с цитированием
Старый 29.06.2016, 15:46   #1965
seriousstas
Бывалый писикарщик
 
Регистрация: 14.06.2013
Регион: Украина
Машина: Nissan Qashqai+2
Сообщений: 3,424
seriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant future
По умолчанию

Цитата:
Сообщение от duzzy Посмотреть сообщение
seriousstas

Ааа... много параметров менять, если разные значения то вариант с Пропертис не подойдет.

Такой вариант уже лучше
Я просто не большой фанат UI элементов, с ними бывают проблемы в скриптах... в скрипты можно подтягивать виндовые кнопки, скролбары, прогрессбары и т.д.

У меня нормально папки с треками добавляет... как при Add так и при Send
Может я что не так добавляю ?
Я давно с ним езжу пока проблем не было
Смотри (я про отображение в самой библиотеке) :
https://hydrogenaud.io/index.php/top...html#msg924563
Пробовал и сборку для crc - она чистая почти со скриптом дефолным.
+ ошибка эта вылазит если попытаться развернуть этот одиночный трек,что на втором скрине (Library Tree 0.9)

Цитата:
Такой вариант уже лучше
Я ещё увеличил - на нём и остановлюсь ..
seriousstas вне форума   Ответить с цитированием
Старый 29.06.2016, 16:27   #1966
duzzy
Гуру
 
Регистрация: 01.06.2013
Регион: 78, 98
Машина: SUBARU Impreza WRX
Сообщений: 1,766
duzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond repute
По умолчанию

seriousstas
Мои папки в экплорере и в скрипте


-------------------------------

Я понял про что ты говоришь, до меня только что дошло...
просто какой смысл отдельные папки добавлять... логично что покажет треки внутри папки отдельно... точно так же работает и Album List
вот смотри скрины...
duzzy вне форума   Ответить с цитированием
Старый 29.06.2016, 16:43   #1967
seriousstas
Бывалый писикарщик
 
Регистрация: 14.06.2013
Регион: Украина
Машина: Nissan Qashqai+2
Сообщений: 3,424
seriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant future
По умолчанию

посмотри скрины добавь просто 2 3 папки с треками
seriousstas вне форума   Ответить с цитированием
Старый 29.06.2016, 16:45   #1968
duzzy
Гуру
 
Регистрация: 01.06.2013
Регион: 78, 98
Машина: SUBARU Impreza WRX
Сообщений: 1,766
duzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond reputeduzzy has a reputation beyond repute
По умолчанию

Цитата:
Сообщение от seriousstas Посмотреть сообщение
посмотри скрины добавь просто 2 3 папки с треками
Я понял про что ты говоришь, до меня только что дошло...
просто какой смысл отдельные папки добавлять... логично что покажет треки внутри папки отдельно... точно так же работает и Album List
вот смотри скрины...


--------------------------

Смысл в том что используешь одну папку как Медиатеку --- допустим Music и поехали дальше...

Например:

Music
|
|--------- CD
|
|---------- FLAC
|
|---------- MP3
...

Либо использовать как общее хранилище для всех форматов и качества...

Music
|--------- AC/DC
|--------- Korn
|--------- ZZ Top

-----------------------------------------------------------------------

По вопросу вылетающей ошибки, можно просто попробовать поставить обход ошибки в этом случае при развороте трека в треке,
таким вот образом...

try{......тут ловишь ошибку, прописываешь ту строку что выбивает..............}catch(error){.......тут на что то меняешь или оставляешь просто пустоту........};

в 0.9 версии строка 472 (0.9 не развернута после сжатия, поэтому ошибку будет проблематично искать)

в 0.8 версии строка 1469

После применения процедуры обхода получится вот такой вариант при развороте трека в треке...


можно еще так сделать и получим пустоту вместо undefined....
Код:
try{
  nU = n.toUpperCase();
     }catch(e){n = "";};

Последний раз редактировалось duzzy; 29.06.2016 в 17:17.
duzzy вне форума   Ответить с цитированием
Старый 29.06.2016, 17:40   #1969
seriousstas
Бывалый писикарщик
 
Регистрация: 14.06.2013
Регион: Украина
Машина: Nissan Qashqai+2
Сообщений: 3,424
seriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant futureseriousstas has a brilliant future
По умолчанию

Ну это типа - мелочь , но неприятно
seriousstas вне форума   Ответить с цитированием
Старый 29.06.2016, 17:52   #1970
vladj
Гуру
 
Аватар для vladj
 
Регистрация: 03.05.2011
Возраст: 73
Город: Верещагино
Регион: 59
Машина: Toyota-Echo
Сообщений: 2,045
vladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond reputevladj has a reputation beyond repute
По умолчанию

[QUOTE=duzzy;363698
Смысл в том что используешь одну папку как Медиатеку --- допустим Music
[/QUOTE]
Пишешь одно , а на скрине в путях три папки, у меня всегда только две прописаны...
Music на харде внутреннем и Music на любой флешке присоединённой в машине.
Дома всегда (как ты и пишешь) только один путь Music.
__________________
DN2800MT, DDR3-4Gb, SSD -30 Gb, Lilliput FA1000 - по HDMI, Win-8 .
vladj вне форума   Ответить с цитированием
Ответ


Здесь присутствуют: 12 (пользователей: 0 , гостей: 12)
 

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.



Часовой пояс GMT +4, время: 03:03.


Работает на vBulletin® версия 3.8.4.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot