﻿$ = window.$;

var NewsRotator = function (container, template, dataItems, loadbehaviour) {
    this.container = $(container);
    this.container_string = container;
    this.template = $(template);
    this.dataItems = dataItems;

    this._currentIndex = -1;
    this._cache = { data: [], urls: [] };
}

NewsRotator.prototype = {
    "_hasNext": function () {
        return this._currentIndex < this.dataItems.length - 1;
    },

    "Rotate": function () {
        this.container.empty();

        if (this._hasNext()) ++this._currentIndex;
        else this._currentIndex = 0;

        this.template.tmpl(this.dataItems[this._currentIndex]).appendTo(this.container);
        var _hightlightId = this._currentIndex + 1;
        $(this.container_string + ' .news-panel div span').filter('[name=' + _hightlightId + ']').addClass('selected');
    },

    "Setup": function () {
        this.Rotate();
        return this;
    },

    "GetDataItems": function () {
        return this.dataItems;
    },

    "SetDataItems": function (dataItems) {
        this.dataItems = dataItems;
    }
};
