// Use jQuery to call the hole highlighting functionality
$(document).ready(function(){
	highlightHole();
});

// If statement on here cause there are two versions of the course card and if they are both on the same page, the js breaks.
// If page name is hole_01.html - 18 then do the following.....
function highlightHole() {
	if(getQueryVariable("holeid") >= 1 && getQueryVariable("holeid") <= 18) {
		// Assume hole_xx.html as page name
		var sHole = getQueryVariable("holeid");
		if (sHole.length == 1){
			sHole = "0" + sHole;
		}

		var nHole = sHole * 1;
		var jsHole = nHole - 1;

		course = "coursecard";
		if (nHole > 9) {
			course = "coursecard2";
			jsHole = jsHole - 9;
		}

		var table = document.getElementById(course);
		var rows  = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');;

		for (var i=0; i<rows.length; i++) {
			rows[i].cells[jsHole].className = "thishole";
		}
	}
}


function getQueryVariable(variable) {
	var myWinLoc = window.location;
	var query = myWinLoc.search.substring(1).toLowerCase();
	var vars = query.split("&");

	//If url doesn't have the page defined in the url, default to highlighting hole 1
	myWinLoc = myWinLoc.toString();

	if(vars == "" && myWinLoc.indexOf("/course/tour/") > 0 ){
		return 1;
	}
	else if (myWinLoc.indexOf("/course/tour/") < 1){
		return 0;
	}

	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}
