var checkcount=0;

function js_toggle( chkboxname, iname ) {
	document.getElementById(chkboxname).checked = !document.getElementById(chkboxname).checked;
	js_set_icon( chkboxname, iname );
}

function js_set_icon( chkboxname, iname ) {
	jQuery("#chkbx_" + chkboxname + " .chkimage").toggle();
	
	if( document.getElementById(chkboxname).checked ) {
		checkcount++;
		document.getElementById("button_search_refine").className="focus";
		// latch the icon(s)
		try
		{
			if( chkboxname == "facility_4" ) {
				// latch all the other ones too
				document.getElementById("icon_11").className="latched";
				document.getElementById("icon_12").className="latched";
			} else if( chkboxname == "facility_24" ) {
				// latch all Childrens Play Area
				document.getElementById("icon_19").className="latched";
				document.getElementById("icon_20").className="latched";
				document.getElementById("icon_21").className="latched";
				document.getElementById("icon_22").className="latched";
			} else if( chkboxname == "facility_37" ) {
				document.getElementById("icon_28").className="latched";
				document.getElementById("icon_31").className="latched";
			} else {
				document.getElementById(iname).className = "latched";
			}
		}
		catch(e){}
	} else {
		checkcount--;
		if (checkcount==0)
		{
			document.getElementById("button_search_refine").className="";
		}
		// unlatch the icon(s)
		try
		{
			if( chkboxname == "facility_4" ) {
				// unlatch all Adults Only
				document.getElementById("icon_11").className="";
				document.getElementById("icon_12").className="";
			} else if( chkboxname == "facility_24" ) {
				// unlatch all Childrens Play Area
				document.getElementById("icon_19").className="";
				document.getElementById("icon_20").className="";
				document.getElementById("icon_21").className="";
				document.getElementById("icon_22").className="";
			} else if( chkboxname == "facility_37" ) {
				document.getElementById("icon_28").className="";
				document.getElementById("icon_31").className="";
			} else {
				document.getElementById(iname).className = "";
			}
		}
		catch(e){}
	}
}

jQuery(function($){ //on document.ready
//Apply tooltip to links with class="addspeech", plus look inside 'speechdata.txt' for the tooltip markups
$('a.addspeech').speechbubble();
});

