// ==PREPROCESSOR==
// @name "Playback Order Button (Popup Menu)"
// @author "marc2003"
// @import "%fb2k_component_path%docs\flags.txt"
// @import "%fb2k_component_path%docs\helpers.txt"
// ==/PREPROCESSOR==

var tooltip = window.CreateTooltip();
// buttons is defined in docs\helpers.txt
var b = new buttons();
var PBOArray = ['Default', 'Repeat (Playlist)', 'Repeat (Track)', 'Random', 'Shuffle (tracks)', 'Shuffle (albums)', 'Shuffle (folders)'];
on_playback_order_changed();

function on_playback_order_changed() {
	// button is defined in docs\helpers.txt
	// arguments are x, y, w, h, {normal image, hover image is optional}, function, tooltip
	b.buttons.pbo = new button(5, 5, 18, 9, {normal : fb.ComponentPath + 'samples\\basic\\images\\' + PBOArray[plman.PlaybackOrder] + '.png'}, function () {
		pbo_menu();
	}, 'Playback Order');
	window.RepaintRect(b.buttons.pbo.x, b.buttons.pbo.y, b.buttons.pbo.w, b.buttons.pbo.h);
}

function on_paint(gr) {
	// RGB function is defined in docs\helpers.txt
	gr.FillGradRect(0, 0, window.Width, window.Height, 270, RGB(25, 40, 51), RGB(38, 60, 76))
	b.paint(gr);
}

function on_mouse_move(x, y) {
	b.move(x, y);
}

function on_mouse_lbtn_up(x, y) {
	b.lbtn_up(x, y);
}

function on_mouse_leave(x, y) {
	b.leave();
}

function pbo_menu() {
	var m = window.CreatePopupMenu();
	for (var i = 0; i < PBOArray.length; i++) {
		// MF_STRING is defined in docs\flags.txt
		m.AppendMenuItem(MF_STRING, i + 1, PBOArray[i]);
	}
	m.CheckMenuRadioItem(1, 8, plman.PlaybackOrder + 1);
	var idx = m.TrackPopupMenu(b.buttons.pbo.x, b.buttons.pbo.y);
	if (idx > 0) {
		plman.PlaybackOrder = idx - 1;
	}
	m.Dispose();
}
