var PlayControl = function (parent) { this.Parent = parent; this.Timer = null; this.Startup = function () { $('#prev').on('click', this.ActivePrevImage.bind(this)); $('#next').on('click', this.ActiveNextImage.bind(this)); $('#play').on('click', this.OnPlayButtonClick.bind(this)); $('#pause').on('click', this.OnPauseButtonClick.bind(this)); }; this.ActivePrevImage = function () { var index = parseInt($(".calc-list").attr("index")); var count = parseInt($(".calc-list").attr("count")); var prevIndex = index > 0 ? index - 1 : count - 1; this.Parent.SetActiveImage(prevIndex); }; this.ActiveNextImage = function () { var index = parseInt($(".calc-list").attr("index")); var count = parseInt($(".calc-list").attr("count")); var nextIndex = index < count - 1 ? index + 1 : 0; this.Parent.SetActiveImage(nextIndex); }; this.AutoPlay = function () { this.Timer = setInterval(this.ActiveNextImage.bind(this), 1500); }; this.OnPlayButtonClick = function () { this.AutoPlay(); $('.btn-group div.pause').show(); $('.btn-group div.play').hide(); }; this.OnPauseButtonClick = function () { clearInterval(this.Timer); $('.btn-group div.pause').hide(); $('.btn-group div.play').show(); }; };