jQuery(document).ready(function ($){
								 
	$("#mapIntro").click(function(){
			closeHelp();
		})

	$(".helpIcon").tooltip({ 
	    extraClass: "w200 largeLabel",
		track: true, 
		showURL: false, 
		showBody: " - ",
		delay: 0, 
		opacity: 1,  
		top: -70, 
		left: 10 
	}); 	
	
	
	$(".cbox IMG").tooltip({ 
 	    extraClass: "shortLabel",
		track: true, 
		showURL: false, 
		showBody: " - ",
		delay: 800, 
		opacity: 1,  
		top: 5, 
		left: 15
	}); 		
	
	$(".imgOver")
		.mouseover(function(){
			showOver(this);
		})
		.mouseout(function(){
			showOff(this);
		})
		
		
	$(".dropItem")
		.click(function(){
			checkDrop(this);
		})
		.each(function(){
		    $(this).find("INPUT").attr("checked", true);
			checkDropSet(this);
			checkDropHeight(this); // doesn't work unless drops are visible
		})
		
	$(".mapDropdown")
		.css("visibility","visible")
		.hide();
}
);

function checkDropHeight(wItem) {
	thisItem = $J(wItem);
	thisLabel = thisItem.find(".dropLabel");
	if (thisLabel.height() == 11) { 
		thisLabel.css("top","5px");
	}
}

function checkDrop(wItem) {
	console.log("checkDrop");
	

	thisItem = $J(wItem);
	thisDiv = thisItem.parents(".mapDropdown");
	wCheckbox = thisItem.find("INPUT");
	
	if (thisDiv.hasClass("startDrop")) {
		console.log("firstClick");
		thisDiv.removeClass("startDrop")
		thisShow = 	thisDiv.find(".imapShowAll");
		//console.log(thisShow);
		wCheckbox.addClass("choice");
		thisShow.click();	
		
	}
	else {		
		wCheckbox.click();
	}

	checkDropSet(wItem);
}
function checkDropSet(wItem) {
	
	thisItem = $J(wItem);
	wCheckbox = thisItem.find("INPUT");	
	
	if (wCheckbox.hasClass("choice")) {
		wCheckbox.removeClass("choice");
		wCheckbox.attr("checked", true);
		if (!wCheckbox.hasClass("on")) thisItem.addClass("on");
		return;		
	}
	
	if (wCheckbox.attr("checked")) {
		thisItem.addClass("on");
	}
	else {
		thisItem.removeClass("on");
	}
}

function showOver(wImg) {
	wImg.src = wImg.src.replace("off","over");
	
}

var showHelp = true;
function closeHelp() {
	if (!showHelp) return;
	$J("#mapIntro").slideUp(500);
	showHelp = false;
}

function showOff(wImg) {	
	wImg.src = wImg.src.replace("over","off");
}