WR.util.namespace('WR.bogushtime');

WR.bogushtime.feedback = {
    popup: null,

    init: function() {
        this.initPopup();
    },

    initPopup: function() {
        this.popup = $('#feedback-panel').appendTo('body');
        //WR.ui.overlay.container = $('.bt-container')[0]; // already set in "common.js"

        // Bind popup to window scroll
        $(window).scroll($.proxy(this, 'scrollPopupIntoView'));

        // Enable popup hide
        WR.ui.overlay.bind('hide', $.proxy(this, 'hidePopup'));
        this.popup.find('.bt-close-btn').click(function(e) {
            e.preventDefault();
            WR.ui.overlay.hide();
        });

        // Enable popup show
        var self = this;
        $('#feedback-open').click(function(e) {
            e.preventDefault();
            WR.ui.overlay.show();
            self.showPopup();
            self.scrollPopupIntoView();
        });
    },

    showPopup: function() {
        this.popup.show();
    },

    hidePopup: function() {
        this.popup.hide();
    },

    scrollPopupIntoView: function() {
        if (this.popup.css('display') == 'block')
            this.popup.stop(true).animate({ top: $(window).scrollTop() + 60 });
    }
};

$(function() {
    WR.bogushtime.feedback.init();
});

