(function (window, document, $, setTimeout, clearTimeout) {
var currentPlayer;
var lastPlayerState;
var isPositionSliderActive;
function populateChapters(elem, chapters, itemId, runtimeTicks) {
var html = '';
for (var i = 0, length = chapters.length; i < length; i++) {
var chapter = chapters[i];
html += '
';
var imgUrl;
if (chapter.ImageTag) {
imgUrl = ApiClient.getScaledImageUrl(itemId, {
width: 240,
tag: chapter.ImageTag,
type: "Chapter",
index: i
});
} else {
imgUrl = "css/images/items/list/chapter.png";
}
var dataSrc = ' data-src="' + imgUrl + '"';
html += '
';
html += '
';
if (chapter.Name) {
html += "
";
html += chapter.Name;
html += "
";
}
html += "
";
var pct = 100 * (chapter.StartPositionTicks / runtimeTicks);
html += '
';
html += "
";
html += "
";
html += "
";
html += "
";
}
elem.html(html).trigger('create');
}
function selectCurrentChapter(elem, positionTicks) {
var elems = $('.chapterPosterItem', elem).removeClass('currentChapter');
var matches = elems.get().filter(function (i) {
var ticks = i.getAttribute('data-positionticks');
return positionTicks >= ticks;
});
var chapterElem = matches[matches.length - 1];
$(chapterElem).addClass('currentChapter');
chapterElem.scrollIntoView();
elem[0].scrollLeft += 50;
}
function showChapterMenu(page, item, currentPositionTicks) {
$('.chapterMenuOverlay', page).show();
var elem = $('.chapterMenu', page).show();
if (item.Id == elem.attr('data-itemid')) {
selectCurrentChapter(elem, currentPositionTicks);
return;
}
var innerElem = $('.chapterMenuInner', elem);
populateChapters(innerElem, item.Chapters, item.Id, item.RunTimeTicks);
elem.attr('data-itemid', item.Id);
selectCurrentChapter(elem, currentPositionTicks);
}
function hideChapterMenu(page) {
$('.chapterMenuOverlay', page).hide();
$('.chapterMenu', page).hide();
}
function showAudioMenu(page, item, currentIndex) {
var streams = (item.MediaStreams || []).filter(function (i) {
return i.Type == 'Audio';
});
var elem = $('#popupAudioTrackMenu', page);
var html = '