
$(document).ready(function() {
    
    var $arrEntries = $("div table.tab_tabello tr");
    var $hdlEntries = $arrEntries[0];
    var $posEntry = "";
    var $selectOptions = new Array;
    var $getURL = "";
    
    this.generateDropdown = function(data) {
        $($arrEntries).each(function (i, entry) {
            if (i != 0) {
                $posEntry = $("td:first", entry).text();
                if (!$selectOptions.inArray($posEntry)) 
                    $selectOptions.push($posEntry);
            }
        });
        $("#select").prepend("<label>" + data + "</label>");
        for (var i=0; i< $selectOptions.length; i++)
            if ($selectOptions[i] != "x") {
                //$("#select select").append("<option>"+$selectOptions[i]+". " + data + "</option>");
                var tempOption = new Option($selectOptions[i] + ". " + data, $selectOptions[i]);
                $("#select select").get(0).options[i] = tempOption;
            }
    }
    
    this.prooveParam = function(data) {
        if (data <= $selectOptions.length && data != "" && data != null) 
            this.showFirst(data);
        else 
            this.showFirst("1");
    }
    this.showFirst = function(data) {
        $($arrEntries).hide();
        $($hdlEntries).show();
        $("th:first", $hdlEntries).hide();
        $($arrEntries).each(function (i, entry) {
            $("td:first", entry).hide();
            if (data == $("td:first", entry).text())
                $(entry).show();
        });
        $("#select select option").each(function (i) {
            if (($(this).text().split("."))[0] == data) {
                $(this).attr("selected", "selected");
                $("#select p.spieltag").text($(this).text());
            }
        });
        
    }
    
    $("#select select").change(function () {
        var selPosition = ($("#select select option:selected").text().split("."))[0];
        $($arrEntries).hide();
        $($hdlEntries).show();
        $($arrEntries).each(function (i, entry) {
            $("td:first", entry).hide();
            if (selPosition == $("td:first", entry).text())
                $(entry).show();
        });    
        $("#select p.spieltag").text($("#select select option:selected").text());
    });
    
    Array.prototype.inArray = function(x) {
        for(var i=0; i < this.length; i++) if(this[i] === x) return true;
        return false;
    }
 });