var currentButton;
var buttonSrc;
var popupDiv;


//add click handler to each image
$(".topicLauncher img").click(function(event){

  /*  $("#wrapper").css("background-color", "#0067ac");*/
  // document.getElementById('wrapper').style.backgroundColor = 'blue';

	// reset the current buttons css
	if(currentButton != undefined) {
		currentButton.attr("src", buttonSrc);
		currentButton.css("border", "3px solid  #fff");
	}

	// find over states and apply style changes
	currentButton = $(this);
	buttonSrc = $(this).attr('src');
	tempOverSrc = buttonSrc.split(".png").join("_bw");
	
	tempVar = buttonSrc.substring(0, buttonSrc.lastIndexOf("_"));
	tempVar = tempVar + ".png"
	finalOverSrc = tempVar;
	$(this).attr("src", finalOverSrc);
	currentButton.css("border", "3px solid  #ef8200");

	// find out what popup to launch
	var popupId = $(this).attr("popup");

	if(popupDiv != undefined) {
		popupDiv.addClass("invisible");
	}
	popupDiv = $("#" + popupId);
	popupDiv.removeClass( "invisible" );

if(popupDiv.data("audio") != undefined && popupDiv.data("audio") != "") {
     loadAudio(popupDiv.data("audio"));
}

	$("#mainText").addClass("invisible"); 

});

function checkBranchProgress() {
	var noCompleted = 0;
	for(var a = 0; a < course.subNodes.length; a++) {
		if(course.subNodes[a].checkProgress == "true") {
			var nodeProgress = checkNodeProgress(course.subNodes[a]);
			if(nodeProgress == 2) {
				noCompleted++;
				if(course.subNodes[a].id == "mk_2_1") {
					$(".branch1 img.btnTick").css({visibility: "visible"});
				} else if (course.subNodes[a].id == "mk_2_2") {
					$(".branch2 img.btnTick").css({visibility: "visible"});
				}
			}
		}
	}
	if(noCompleted == 2) {
		if($("#wrapper").hasClass("controlnav") && currentPage.progress!=2){
			obj.removeClass("controlnav")
			checkRestrictedNav();
		}
	}
}

var isBranchScreen = $("#wrapper").hasClass("branchCheck");
if(isBranchScreen) {
	checkBranchProgress();
} 


// change background color from the wrapper 
/*
$(".topicLauncher img").click(function() {
    $(".AccordionPanelContent span").css("background-color", "white");
    $(this).css("background-color", "red");
});
*/
