﻿
/* Creates the div element */

var FBKToolbar = {
    getGames: function () {
        var result = [
            {
                Title: "Another Spacegame",
                Url: "http://www.anotherspacegame.de",
                MyGame: true
            },
            {
                Title: "Jungfrauenspiel",
                Url: "http://www.jungfrauenspiel.de",
                MyGame: true
            },
            {
                Title: "Brückenbauer",
                Url: "http://brueckenbauer.depon.net",
                MyGame: true
            },
            {
                Title: "Wichtel-Mine",
                Url: "http://www.wichtel-mine.de",
                MyGame: false
            }
        ];

        return result;
    },
    onSelect: function () {
        var value = $('#fbk_toolbar_select').val();
        if (value == undefined || value == 'None') {
            // Do Nothing
            $("#fbk_toolbar_select").get(0).selectedIndex = 0;
            return;
        }

        var url = FBKToolbar.getGames()[value].Url;
        document.location.href = url;
    }
};

$(document).ready(function () {

    var div = $("<div id='fbk_toolbar'><div id='fbk_toolbar_logo' /><div id='fbk_toolbar_homepage'><a href='http://depon.net/'>Depon.Net</a></div><div id='fbk_toolbar_games'>Weitere Spiele </div></div>");
    $("body").append(div);

    var games = FBKToolbar.getGames();
    var inputElement = $("<select id='fbk_toolbar_select' onchange='FBKToolbar.onSelect(); return false;'/>");

    // Default entries
    inputElement.append($("<option value='None'>auswählen</option>"));
    inputElement.append($("<option value='None' class='fbk_toolbar_gamecategory'>Eigene Spiele:</option>"));

    // Create entries
    for (var gameIndex in games) {
        var game = games[gameIndex];
        if (!game.MyGame) {
            continue;
        }

        var option = $("<option />").html("&nbsp;&nbsp;&nbsp;" + game.Title);
        option.attr('value', gameIndex);
        inputElement.append(option);
    }

    inputElement.append($("<option class='fbk_toolbar_gamecategory' value='None'>Partnerspiele:</option>"));

    // Create entries
    for (var gameIndex in games) {
        var game = games[gameIndex];
        if (game.MyGame) {
            continue;
        }

        var option = $("<option />").html("&nbsp;&nbsp;&nbsp;" + game.Title);
        option.attr('value', gameIndex);
        inputElement.append(option);
    }
    $("#fbk_toolbar_games").append(inputElement);
});
