﻿if (typeof (Fixya) == 'undefined' || Fixya === null) var Fixya = function() { }
Fixya.TopExperts = function(experts, ancAvatar, imgAvatar, ancUserName, spnMemberSince, imgRank, spnRank, spnRating, spnSolutions, spnExperience, imgLeftArrow, imgRightArrow, imgBadge, spnBrand, ancRating, ancSolutons) {
    this.experts = experts;
    this.ancAvatar = ancAvatar;
    this.imgAvatar = imgAvatar;
    this.ancUserName = ancUserName;
    this.ancRating = ancRating;
    this.ancSolutons = ancSolutons;
    this.spnMemberSince = spnMemberSince;
    this.imgRank = imgRank;
    this.spnRank = spnRank;
    this.spnRating = spnRating;
    this.spnSolutions = spnSolutions;
    this.spnExperience = spnExperience;
    this.prevButton = imgLeftArrow;
    this.nextButton = imgRightArrow;
    this.imgBadge = imgBadge;
    this.spnBrand = spnBrand;
    this.ButtonsPath = '/images/icons/';
    this.StaffPath = '/images/icons/icon_staffBadge.gif';
    this.BrandType =
    {
        Nothing: 0,
        Staff: 1,
        BrandExpert: 2
    }
    this.ButtonsSrc = { prevHover: 'button_previous_on.gif', prev: 'button_previous_off.gif', nextHover: 'button_next_on.gif', next: 'button_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), 10000);
}
Fixya.TopExperts.prototype =
{
    render: function() {
        if (this.experts == null) return;
        var _expert = this.experts[this.selectedExpertID];
        this.ancAvatar.href = _expert.userUrl;
        this.imgAvatar.src = _expert.avatar;
        this.imgAvatar.alt = _expert.userName;
        this.ancUserName.href = this.ancRating.href = this.ancSolutons.href = _expert.userUrl;
        this.spnMemberSince.innerHTML = _expert.memberSince;
        this.ancUserName.innerHTML = _expert.userName;
        this.imgRank.src = _expert.rankImage;
        this.imgRank.alt = _expert.rankName;
        this.spnRank.innerHTML = _expert.rankName;
        this.spnRating.innerHTML = _expert.rating;
        this.spnSolutions.innerHTML = _expert.solutions;
        this.spnExperience.innerHTML = _expert.experience;
        if (_expert.brandType != this.BrandType.Nothing) {
            this.imgBadge.style.display = '';
            if (_expert.brandType == this.BrandType.Staff)
                this.imgBadge.src = this.StaffPath;
            else {
                if (_expert.brandIcon == '')
                    this.imgBadge.style.display = 'none';
                this.imgBadge.src = BRAND_ICONS_DIRECTORY.replace(/\{0\}/g, _expert.brandIcon);
            }
            this.imgBadge.alt = _expert.brandName;
            this.spnBrand.innerHTML = _expert.brandName;
        } else if (this.imgBadge != null) {
            this.imgBadge.style.display = 'none';
            this.spnBrand.innerHTML = '';
            this.imgBadge.src = "/Images/pxl.gif";
        }

        if (typeof (floatingChatBoxEffect) == "function") {
            floatingChatBox_immediate();
        }
    },
    setSrc: function(src, btn) {
        btn.element().src = this.ButtonsPath + src;
    },
    moveNext: function(isAuto) {
        if (this.experts == null) return;
        if (!isAuto)
            window.clearInterval(this.intervalID);
        if (this.selectedExpertID == this.experts.length - 1)
            this.selectedExpertID = 0;
        else
            this.selectedExpertID++;
        this.render();
    },
    movePrev: function(isAuto) {
        if (this.experts == null) return;
        if (!isAuto)
            window.clearInterval(this.intervalID);
        if (this.selectedExpertID == 0)
            this.selectedExpertID = this.experts.length - 1;
        else
            this.selectedExpertID--;
        this.render();
    }
}