/*** Functions used on Athletes page ***/
$(document).ready(function() {
	setBGImgs();
	$('#athleteThumbGrid a').hover( thumbOver, thumbOut );
	$('#athleteList a').hover( listOver, listOut );
});

/*** Sets background img of thumbnail anchors in image grid to colour version of thumb. The anchor id is used to form the url e.g. img/anchorIdCol.jpg ***/
function setBGImgs(){
	$('#athleteThumbGrid a').each(
		function(){
			bgURL = "url(" + $(this).attr("id") + ")";
			$(this).css("background-image", bgURL);
		}
	)
}

/*** On mouse over thumbnail anchor, fade out bw img to reveal colour img in bg. Also, animate in text span pop-up ***/
function thumbOver(){
	setListSel( $(this).attr("href") );
	$(this).find(".athletePopup").animate({top: "76px"});
	$(this).find("img").animate({opacity: 0});
}

/*** On mouse out thumbnail anchor, fade in bw img. Also, animate out text span pop-up ***/
function thumbOut(){
	setListSel("");
	$(this).find(".athletePopup").animate({top: "116px"});
	$(this).find("img").animate({opacity: 1});
}

/*** On mouse over athleteList anchor, animate in text span pop-up on corresponding athleteThumbGrid thumb ***/
function listOver(){
	ref = $(this).attr("href");
	thumb = $('#athleteThumbGrid a[href="'+ref+'"]');
	thumb.find(".athletePopup").animate({top: "76px"});
	thumb.find("img").animate({opacity: 0});
}

/*** On mouse out athleteList anchor, animate out text span pop-up on corresponding athleteThumbGrid thumb ***/
function listOut(){
	ref = $(this).attr("href");
	thumb = $('#athleteThumbGrid a[href="'+ref+'"]');
	thumb.find(".athletePopup").animate({top: "116px"});
	thumb.find("img").animate({opacity: 1});
}

/*** Deselects all athleteList entries, then selects specifed entry (based on href of anchor matching href of entry) ***/
function setListSel( ref ){
	$('#athleteList a').removeClass("selected");
	if( ref != "" ) $('#athleteList a[href="'+ref+'"]').addClass("selected");
}
