// -*- mode: javascript; coding: utf-8 -*-
//
// Copyright 2011 Andrej A Antonov <polymorphm@gmail.com>.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

(function ($) {
    'use strict'
    
    var HAS_ONLINE_OPERATORS_URL = '/webim/has_online_operators.php'
    
    function has_online_operators (callback) {
        $.post(HAS_ONLINE_OPERATORS_URL, {}, (function (data) {
            if (!data.errors) {
                callback(data.is_online)
            }
        }))
    }
    
    $(function () {
        has_online_operators(function (is_online) {
            if (is_online) {
                // if operator is online -- begin button show-animation
                
                var webim_client = $('.WebimClientObject')
                
                webim_client.css({
                    display: 'block',
                    position: 'fixed',
                    right: '0',
                    bottom: '0',
                    zIndex: '100',
                    height: '0',
                    overflow: 'hidden',
                })
                
                webim_client.animate({
                    height: '90px',
                }, 2000)
            }
        })
    })
})(jQuery)

