/**
 * Javascript File
 * Component: Scoreboard
 * 
 * @author Jan Byška <www.svofrcomputers.cz>
 * @copyright All right reserved
 * @version 2.0
 */
function switchLeague(league){
	// reset values
	current_league = league;
	time = 15;
	$('.ref_time').html('ref.<br>'+time+'s');
	
	// hide all
	//$('.league-center').hide(300);
	$('.league-name').removeClass('selected');
	//$('.league-center').removeClass('selected');
	$('.scoreboard-matches').hide(0);
	
	// show
	//$('#'+league+'_center').fadeIn(500);
	$('#'+league).addClass('selected');
	//$('#'+league+'_center').addClass('selected');
	$('#matches_'+league).fadeIn(0);
}

// show/hide links
function showLinks(league,index){
	$('#'+league+'_result_'+index).css('backgroundColor','#999');
}
function hideLinks(league,index){
	$('#'+league+'_result_'+index).css('backgroundColor','#fff');
}

//stop/start countdown
function stopTime(){countdownAllowed=false;}
function startTime(){countdownAllowed=true;}

function countdown(){
	setTimeout('countdown()',1000);
	if(countdownAllowed) time--;
	if(time <= 0){
		for(var i in leagues){
			if(leagues[i] == current_league){
				if(parseInt(i)+1 >= leagues.length){
					switchLeague(leagues[0]);				
				}else{
					switchLeague(leagues[parseInt(i)+1]);
				}
				break;
			}
		}
		time = 15;
	}
	$('.ref_time').html('ref.<br>'+time+'s');
}

// shift to the new matches
function shift(league,direction){	
	switch(direction){
		case "left":
			if(match_shift > 1){
				document.getElementById(league+'_right').src="components/Scoreboard/right.jpg";
				if(match_shift==2) 
					document.getElementById(league+'_left').src="components/Scoreboard/left_inactive.jpg";
				$('#'+league+"_match_"+(match_shift+7)).fadeOut(0, function() {
					$('#'+league+"_match_"+(match_shift-1)).fadeIn(0,function(){
						match_shift--;
					});
				});
			}
			break;
		case "right":
			if(8+match_shift <= count[current_league]){
				document.getElementById(league+'_left').src="components/Scoreboard/left.jpg";
				if(8+match_shift == count[current_league])
					document.getElementById(league+'_right').src="components/Scoreboard/right_inactive.jpg";
				$('#'+league+"_match_"+(match_shift)).fadeOut(0, function() {
						$('#'+league+"_match_"+(match_shift+8)).fadeIn(0,function(){
							match_shift++;
						});
				 });
			}
			break;
	}
}
