$(document).ready(function(){

//### SIDEBAR CHANNEL CALLBACK FUNCTIONS BEGIN #########################

	$("#bookie-dropdown").click(function () {
		
		$("#more-bookies").slideToggle("normal", function(){changeDropDownTxt("bookie");});	
		$("more-bookies").html() == 'Less reviews...'
	});
	
	$("#casino-dropdown").click(function () {
	
		$("#more-casinos").slideToggle("normal", function(){changeDropDownTxt("casino");});	
		$("more-casinos").html() == 'Less reviews...'
	});	
	
	$("#poker-dropdown").click(function () {
	
		$("#more-poker").slideToggle("normal", function(){changeDropDownTxt("poker");});	
		$("more-poker").html() == 'Less reviews...'
	});	
	
	$("#bingo-dropdown").click(function () {
	
		$("#more-bingo").slideToggle("normal", function(){changeDropDownTxt("bingo");});	
		$("more-bingo").html() == 'Less reviews...'
	});		
	
//### SIDEBAR CHANNEL CALLBACK FUNCTIONS END ###########################
	
});


function changeDropDownTxt(channel){

	if($("#"+channel+"-dropdown").html() == 'Less reviews...'){
	
		$("#"+channel+"-dropdown").html('More reviews...');
		
	}else{
	
		$("#"+channel+"-dropdown").html('Less reviews...');
	}	
}


// #### JS handling switching of channels via tab clicks ####

function switchTabs(channelID){
	
	var clickedTab = $("#"+channelID);
	var channelContainer = $('#channelContainer');
	
	//Check if tab clicked is already selected
	if (!clickedTab.hasClass('selectedChannel')){
		
		//remove class identifier from current selected tab
		$('.selectedChannel').removeClass('selectedChannel');
		
		//add class to newly selected tab
		clickedTab.addClass('selectedChannel');
		
		//set HTML contents with new content from hidden divs
		channelContainer.html($('#hidden-'+channelID).html());
	}
}


// ### JS handling switching of review channels ###

function switchReviews(channelID){
	
	if (channelID != 'all'){
	
		var clickedFilter = $("#"+channelID);
		
		if (!clickedFilter.hasClass('currentFilter')){
						
			$('.currentFilter').slideUp('normal', function(){clickedFilter.slideDown("normal");});
			$('.currentFilter').removeClass('currentFilter');
	
			clickedFilter.addClass('currentFilter');	
			
		}else{
		
			if (countOpenFilters() > 1){
			
				$(".channel").each(function() {
				
					$(this).removeClass('currentFilter');
					$(this).hide();
				})
				
				clickedFilter.addClass('currentFilter');
				clickedFilter.show();			
			}		
		}
		
	}else{
		
		$(".channel").each(function() {
		
			$(this).slideDown("normal");
			$(this).addClass('currentFilter');
		})
	}
}

//Counts if more than one review filter is shown in sidebar 
function countOpenFilters(){

	var i = 0;
	
	$(".currentFilter").each(function() {
	
		i++;
	})	
	
	return i;
}


//### FOOTBALL LEAGUE LISTS CALLBACK FUNCTIONS BEGIN ###################

function showFootballLeague(countryID){

	var clickedList = $("#"+countryID);
	var clickedIcon = $("#"+countryID+"-icon");
			
	//Check if tab clicked is already selected
	if (!clickedList.hasClass('open')){
		
		//remove class identifier from current selected tab		
		$('.open').slideUp("normal");
		$('.open').removeClass('open');
				
		$('.open-icon').attr("src", '/images/more.gif');
		$('.open-icon').removeClass('open-icon');
		
		clickedIcon.attr("src", '/images/less.gif');
		clickedIcon.addClass('open-icon');
		
		//add class to newly selected tab
		clickedList.addClass('open');
		clickedList.slideDown('normal');		
	}
}

//### FOOTBALL LEAGUE LISTS CALLBACK FUNCTIONS END #####################