$(document).ready(function() {
    $(function() {
        $("#tabs").tabs( {
            spinner: '<div class="ajaxwait"><img src="/images/soccer_spinner.gif" alt="Bitte warten..."/></div>',
            tabTemplate: '<div class="js-league-scope"></div>'
        });
    });

    $('.js-action-trigger').click(function() {
        var scope = $(this).closest('.js-action-scope');
        $(this).hide();
        scope.find('.js-action-spinner').show();
        $.post(scope.attr('data-post-url'), {}, function() {
            scope.find('.js-action-spinner').hide();
            scope.find('.js-action-done').show();
        });
        return false;
    });

    $('.js-country-details').dialog({  autoOpen: false,
                                    modal: true, title: '',
                                    buttons: { "Yummy!": function() { $(this).dialog("close"); }},
                                    width:800,
                                    height:600,
                                    resizable:false
                                 });
    $(".js-country").click(function() {
        var country = $(this).find('img').attr('alt');
        $('.js-wikiframe').attr('src','http://de.wikipedia.org/wiki/'+country);

        $('.js-country-details').dialog('option', 'title', country);
        $('.js-country-details').dialog('open');
    });

    $('.js-help-details').dialog({  autoOpen: false,
                                 	modal: true,
                                 	buttons: { "Yummy!": function() { $(this).dialog("close"); }},
                                 	width:600,
                                 	height:200,
                                 	resizable:false
                                 });
    $(".js-help").click(function() {
        var title = $(this).attr('title');
        $('.js-help-details').dialog('option', 'title', title);
        $('.js-help-details').dialog('open');
    });

    $('button.delete').click(function() {
        return confirm("Moechten Sie wirklich Ihren Account kuendigen? Alle Daten werden geloescht! Wirklich! In Echt!");
    });

});


function postSoccerMatchDate(scope) {
    scope = $(scope).closest('.js-datetimepicker');
    var date = $(scope).find('input.js-datepicker').val();
    var time = $(scope).find('input.js-timepicker').val();
    var matchUrl = $(scope).closest('.js-match-scope').attr('data-match-url');
    $.post(matchUrl, {method: 'put', startAt: date+" "+time});
}


