var flash_loaded = false;

function expand_desc() {
	var full = $('hidden_desc').innerHTML;
	$('desc').innerHTML = full;
}

function seedMarker(){
 	var myImage = new YImage();
  	myImage.src = "/images/seed.png";
 	myImage.size = new YSize(20,20);
	myImage.offset = new YCoordPoint(-10, 0);
  	myImage.offsetSmartWindow = new YCoordPoint(9,10);
	return myImage;
}

function congregationMarker(){
 	var myImage = new YImage();
  	myImage.src = "/images/congregation.png";
 	myImage.size = new YSize(20,20);
	myImage.offset = new YCoordPoint(-10, 0);
  	myImage.offsetSmartWindow = new YCoordPoint(9,10);
	return myImage;
}

function affiliatedMarker(){
 	var myImage = new YImage();
  	myImage.src = "/images/affiliated.png";
 	myImage.size = new YSize(20,20);
	myImage.offset = new YCoordPoint(-10, 0);
  	myImage.offsetSmartWindow = new YCoordPoint(9,10);
	return myImage;
}

function markerCapture(newMarker, markerMarkup) {
	if (markerMarkup != null) {
		YEvent.Capture(newMarker, EventsList.MouseClick, 
			function(){
				newMarker.openSmartWindow(markerMarkup);
			});
	}
}

function church_marker_info(id) {
	tag = "church_toggle_" + id;
	new Effect.toggle(document.getElementById(tag), 'blind', {duration:0.5});
}

function changeMap(t) {
	if (t == 'region') {
		if (!flash_loaded) {
			writeRegionMap();
		}
		$('map').show();
		$('real_map').hide();
		$('region_tab').addClassName('selected');
		$('church_tab').removeClassName('selected');
		$('scout_tab').removeClassName('selected');
		$('region_opts').show();
		$('church_opts').hide();
		$('conc_box').checked = false;
		$('city_box').checked = false;
	} else if (t == 'churches') {
		toggleChurches();
		toggleAllScouts(false);
		$('map').hide();
		$('real_map').show();
		$('church_select_wrap').show();
		//$('church_type').focus();
		$('region_tab').removeClassName('selected');
		$('church_tab').addClassName('selected');
		$('scout_tab').removeClassName('selected');
		$('region_opts').hide();
		$('church_opts').show();
	} else {
		$('map').hide();
		$('real_map').show();
		$('region_tab').removeClassName('selected');
		$('church_tab').removeClassName('selected');
		$('scout_tab').addClassName('selected');
		$('region_opts').hide();
		$('church_select_wrap').hide();
		$('church_opts').show();
		_toggleChurches(church_markers, false);
		toggleAllScouts(true);
	}
}

function draw_map(geo_search, zoomlevel, list) {
	if (zoomlevel == null)
		zoomlevel = 6;
	if (geo_search.toLowerCase() == 'canada')
		map.drawZoomAndCenter("-90.0322, 54.0525", 14);
	else if (geo_search != null)
		map.drawZoomAndCenter(geo_search + ' CANADA', zoomlevel);
	else 
		map.drawZoomAndCenter("-90.0322, 54.0525", 14);
}

function toggleConc() {
	$('mapswf').concentrationToggle();
}

function toggleCity() {
	$('mapswf').cityToggle();
}

function toggleSeeds(box) {
	if (box.checked) {
		seed_markers.each(function(m) {
			m.unhide();
		});
	} else {
		seed_markers.each(function(m) {
			m.hide();
		});
	}
}

function toggleChurches() {
	var val = $F('church_type');
	switch(val) {
		case '1':
			_toggleChurches(church_markers, true);
			break;
		case '2':
			_toggleChurches(church_markers, false);
			_toggleChurches(aff_markers, true);	
			break;
		case '3':
			_toggleChurches(church_markers, false);
			_toggleChurches(cong_markers, true);
			break;
		case '4':
			_toggleChurches(church_markers, false);
			_toggleChurches(seed_markers, true);
			break;
		case '5':
			_toggleChurches(church_markers, false);
			_toggleChurches(noobs, true);
			break;
	}
}

function _toggleChurches(array, on) {
	if (on) {
		array.each(function(m) {
			m.unhide();
		});
	} else {
		array.each(function(m) {
			m.hide();
		});
	}
}

function toggleAllScouts(on) {
	if (on) {
		scout_markers.each(function(m) {
			m.unhide();
		});
	} else {
		scout_markers.each(function(m) {
			m.hide();
		});
	}
}

function toggleCong(box) {
	if (box.checked) {
		cong_markers.each(function(m) {
			m.unhide();
		});
	} else {
		cong_markers.each(function(m) {
			m.hide();
		});
	}
}

function toggleAff(box) {
	if (box.checked) {
		aff_markers.each(function(m) {
			m.unhide();
		});
	} else {
		aff_markers.each(function(m) {
			m.hide();
		});
	}
}

function writeRegionMap() {
	var swf = new SWFObject("/swfs/map.swf?gadgsa", "mapswf", "960", "440", "8", "#7C694F");
	swf.addParam("allowScriptAccess", "always");
	swf.write("map");
}
