
var OTOS = window.OTOS || {};

OTOS.Server = function () {

    return {

        /**
         * Shows the whole server-tree
         *
         * @param   {string}    serverAddress   The address of the server
         */
        showServer: function (serverAddress) {
            var newServer = new Server(serverAddress, $(CONTENT_ELEMENT_ID));
            newServer.show();
        },


        /**
         * Creates or removes the serverInfo -element
         *
         * @param   {String}    serverAddress   The address of the server
         * @param   {boolean}   update          Whether to update the window.location.hash or not
         */
        serverInfo: function (serverAddress, update) {

            var container   = $(CONTENT_ELEMENT_ID),
                newServer   = new Server(serverAddress, container);

            newServer.showInfo();

            if (update) {
                OTOS.Main.updateHash();
            } // if

        },


        /**
         * Shows all servers
         */
        showAllServers: function () {

            var container = $(CONTENT_ELEMENT_ID);

            OTOS.Dom.removeChildNodes(container);
            OTOS.Tree.updateTree();    // update the browser in the navigation
            OTOS.Main.TREEMODE = true;    // set the OTOS.Main.TREEMODE on

            for (var i in OTOS.ElementConfig.SERVERDATA) {
                var myServer = new Server(i, container);
                myServer.create();
            } // for

            OTOS.Statistics.refreshStatistics(null, null, null);
            clearTimeout(OTOS.Camera.TIMER);
            OTOS.Camera.updateCameraImages();

            window.location.hash = '#';

        },


        /**
         * Gets and returns the first server-array from the SERVERDATA-object.
         *
         * @return  The first server-array from the SERVERDATA-object
         * @type    {array}
         */
        getFirstServer: function () {

            var first;

            for (var i in OTOS.ElementConfig.SERVERDATA) {
                first = i;
                break;
            }

            return first;

        },


        /**
         *
         */
        toggleServer: function (server) {
            OTOS.Server.serverInfo(server, true);
            OTOS.ElementManager.setCameraBarHeights($(CONTENT_ELEMENT_ID));
        }

    };

}();
