if (typeof (RAWA) == 'undefined' || RAWA === null) var RAWA = function() { }
RAWA.Toprawasource = function(rawasource, ancAvatar, imgAvatar, ancrawaTitle, spnrawaDate, spnrawaNewsSource, spnrawaShortNews, imgLeftArrow, imgRightArrow) {
    this.rawasource = rawasource;
    this.ancAvatar = ancAvatar;
    this.imgAvatar = imgAvatar;
    this.ancrawaTitle = ancrawaTitle;
    this.spnrawaDate = spnrawaDate;
    this.spnrawaNewsSource = spnrawaNewsSource;
    this.spnrawaShortNews = spnrawaShortNews;
    this.prevButton = imgLeftArrow;
    this.nextButton = imgRightArrow;
    this.ButtonsPath = 'http://www.rawa.org/rawa/scrolling/';
    this.StaffPath = '';

    this.ButtonsSrc = { prevHover: 'previous_on.gif', prev: 'previous_off.gif', nextHover: 'next_on.gif', next: 'next_off.gif' }
    this.selectedExpertID = 0;
    this.prevButton.observe('mouseover', this.setSrc.bind(this, this.ButtonsSrc.prevHover));
    this.prevButton.observe('mouseout', this.setSrc.bind(this, this.ButtonsSrc.prev));
    this.nextButton.observe('mouseover', this.setSrc.bind(this, this.ButtonsSrc.nextHover));
    this.nextButton.observe('mouseout', this.setSrc.bind(this, this.ButtonsSrc.next));
    this.prevButton.observe('click', this.movePrev.bind(this, false));
    this.nextButton.observe('click', this.moveNext.bind(this, false));
    this.intervalID = window.setInterval(this.moveNext.bind(this, true), 8000);
}

RAWA.Toprawasource.prototype =
{
    render: function() {
        if (this.rawasource == null) return;
        var _rawa = this.rawasource[this.selectedExpertID];
        this.imgAvatar.src = _rawa.avatar;
        this.imgAvatar.alt = _rawa.rawaTitle;
        this.ancrawaTitle.href = _rawa.userUrl;
        this.spnrawaDate.innerHTML = _rawa.rawaDate;
        this.ancrawaTitle.innerHTML = _rawa.rawaTitle;
        this.spnrawaNewsSource.innerHTML = _rawa.rawaNewsSource;
        this.spnrawaShortNews.innerHTML = _rawa.rawaShortNews;
//        this.ancAvatar.href = _rawa.userUrl;
    },
    setSrc: function(src, btn) {
        btn.element().src = this.ButtonsPath + src;
    },
    moveNext: function(isAuto) {
        if (this.rawasource == null) return;
        if (!isAuto)
            window.clearInterval(this.intervalID);
        if (this.selectedExpertID == this.rawasource.length - 1)
            this.selectedExpertID = 0;
        else
            this.selectedExpertID++;
        this.render();
    },
    movePrev: function(isAuto) {
        if (this.rawasource == null) return;
        if (!isAuto)
            window.clearInterval(this.intervalID);
        if (this.selectedExpertID == 0)
            this.selectedExpertID = this.rawasource.length - 1;
        else
            this.selectedExpertID--;
        this.render();
    }
}