$(document).ready(function() {
        $(function() {
            $('a[rel=tipsyBack]').tipsy( {fade: true, gravity: 's', action:"hover"} );
            $('a[rel=tipsyLay]').tipsy( {fade: true, gravity: 's', action:"hover"} );
        });
});

//Get tournaments list for left menu
function sportTournamentsLeftShow(id)
{    
    if ($('#sportCategoryTournaments_'+id).is(':hidden'))
    {
        if ($('#sportCategoryTournaments_'+id).html()=="")
        {
            $('#sportCategoryTournaments_'+id).show();
            $('#sportCategoryTournaments_'+id).html('<div class="preloadersmall"><img src="/../images/components/preloader.gif" border="0" alt="Please Wait, Loading" title="Please Wait, Loading" /><br/><br/>L O A D I N G</div>');
            url = '/index.php/bets/tournamentLeftMenu/?category_id='+id;
            $.post(url, function(data) {
                    $('#sportCategoryTournaments_'+id).html(data);                    
            });
        }
        else
        {
            $('#sportCategoryTournaments_'+id).show();
        }
    }
    else
    {
        $('#sportCategoryTournaments_'+id).hide();
    }
}

//Get games list
function sportTournamentGamesShow(tournament_id, category_id)
{
    $('#main_content').html('<div class="preloader"><img src="/../images/components/preloader.gif" border="0" alt="Please Wait, Loading" title="Please Wait, Loading" /><br/><br/>L O A D I N G</div>');
    url = '/index.php/bets/getGamesList/?category_id='+category_id+'&tournament_id='+tournament_id;
    $.post(url, function(data) {
            $('#main_content').html(data);
    });        
}

//Get games list
function sportGamesQuestionsShow(id, tournament_id, category_id)
{
    if ($('#games_question_list_'+id).is(':hidden'))
    {
        $('#games_question_list_'+id).show();
        $('#games_question_list_'+id).html('<div class="preloader"><img src="/../images/components/preloader.gif" border="0" alt="Please Wait, Loading" title="Please Wait, Loading" /><br/><br/>L O A D I N G</div>');
        
        url = '/index.php/bets/getQuestionsList/?category_id='+category_id+'&tournament_id='+tournament_id+'&bets_list_id='+id;
        $.post(url, function(data) {
                $('#games_question_list_'+id).html(data);                
        });  
    }
    else
    {
        $('#games_question_list_'+id).hide();
    }
           
}

function betMake(answer, question_id, id)
{    
    if (confirm("Are you sure?"))
    {
        $('#games_question_list_'+id).html('<div class="preloader"><img src="/../images/components/preloader.gif" border="0" alt="Please Wait, Loading" title="Please Wait, Loading" /><br/><br/>L O A D I N G</div>');
        var action=(answer=="yes")?"back":"lay";
        url = '/index.php/bets/saveQuestions/';
        $.post(url, { action: action, betId: question_id }, function(data) {
            if (data!="") 
            {
                $('#games_question_list_'+id).html(data);
                url = '/index.php/users/userMoney/';
                $.post(url, {}, function(data) {
                    $('#user_money_balance').html(data);
                });
            }
            else window.location = "/registration/";
        });
    }
}

