/**
 * @author Vizua
 */
$(document).ready(function(){
	
    //table style
    $('.league_table tr:odd,.league_statistics table.goals tbody tr:even,'+
	'.league_statistics table.yellow tbody tr:even,.league_statistics table.red tbody tr:even').css('background-color', '#fff');
    //	$('#league_main tbody tr:nth-child(1)').css('background-color', '#4a9429');
    //	$('#league_main tbody tr:nth-child(1) td').css('color', '#fff');
    //	$('#league_main tbody tr:nth-child(2)').css('background-color', '#4a9429');
    //	$('#league_main tbody tr:nth-child(2) td').css('color', '#fff');
    
    $('.league_table select').change(function(){
        var round = $(this).val();
        var league = $('.league_table').attr('id');
        $('#content').html('<div id="loader"><img src="'+base+'img/waiting.gif" /></div>');
        $('#content').load(base + 'league/table/' + league + '/' + round);
        $.address.value('league/table/' + league + '/' + round);
    });
    
    $('.league_teams').delegate('.team .more', 'click', function(){
        var next = $(this).parent().parent().parent().parent().next();
        if (next.css('display') == 'none') {
            next.slideDown('slow');
			$(this).parent().css('margin-bottom', '0px');
        } else {
            next.slideUp('slow');
			$(this).parent().css('margin-bottom', '4px');
        }
    });
	
	$('.league_statistics select').change(function(){
        var team = $(this).val();
        var league = $('.league_statistics').attr('id');
        $('#content').html('<div id="loader"><img src="'+base+'img/waiting.gif" /></div>');
        $('#content').load(base + 'league/statistics/' + league + '/' + team);
        $.address.value('league/statistics/' + league + '/' + team);
    });
	
	$('.league_results .basic').hover(function() {
		if($(this).next().hasClass('players')) {
			$(this).css('cursor', 'pointer');
		}
	}, function() {
		$(this).css('cursor', 'default');
	});
	
	
	$('.league_results').delegate('div.basic', 'click', function() {
        var next = $(this).next();
        if (next.css('display') == 'none') {
            next.slideDown('slow');
        } else {
            next.slideUp('slow');
        }
    });
	
	$('.league_results a.expand').click(function() {
		var id = $(this).attr('id');
		var text = $(this).html();
		//$('.league_results .'+id).click();
		var main = $(this).parent().find('.main');
		
		if ($(this).html() == 'rozbaliť') {
			main.each(function() {
				var players = $(this).find('.players');
				if (players.is(':hidden')) {
					players.prev().click();
				}
			});
			$(this).html('zbaliť');
		} else {
			main.each(function(){
				var players = $(this).find('.players');
				if (players.is(':visible')) {
					players.prev().click();
				}
			});
			$(this).html('rozbaliť');
		}
		return false;
	});
    
});

