function initWorldMap(section) {
	var form = $("worldMapForm");
	var continent_id = parseInt(form.elements["continent_id"].value);
	var city_id = parseInt(form.elements["city_id"].value);
	
	loadCities(continent_id, city_id, section);
}

function getContinent() {
	var form = $("worldMapForm");
	return parseInt(form.elements["continent_id"].value);
}

function getCity() {
	var form = $("worldMapForm");
	return parseInt(form.elements["city_id"].value);
}

function highlightMap(continent_id) {
	var map = $("map" + continent_id);
	
	if (map != null) {
		if (!map.hasClass("highlight" + continent_id))
			map.addClass("highlight" + continent_id);
	}
	
	return false;
}

function lowlightMap(continent_id) {
	var map = $("map" + continent_id);
	
	if (map != null) {
		if (map.hasClass("highlight" + continent_id))
			map.removeClass("highlight" + continent_id);
	}
	
	return false;
}

function highlightContinent(continent_id) {
	var continent = $("continent" + continent_id);
	
	if (continent != null) {
		if (!continent.hasClass("highlight"))
			continent.addClass("highlight");
	}
	
	return false;
}

function lowlightContinent(continent_id) {
	var continent = $("continent" + continent_id);
	
	if (continent != null) {
		if (continent.hasClass("highlight"))
			continent.removeClass("highlight");
	}
	
	return false;
}

function loadCities(continent_id, city_id, section) {
	var form = $("worldMapForm");
	form.elements["continent_id"].value = continent_id;
	
	// list
	var url = DOCUMENT_ROOT + "/misc/scripts/ajax/map_cities.asp?continent=" + continent_id + "&section=" + section;
	/*
	* uncomment to highlight active city
	if (city_id != null)
		url += "&city=" + city_id;
	*/
	var element = "cities_list";
	ajaxRequest(url, element);

	// images
	url = DOCUMENT_ROOT + "/misc/scripts/ajax/map_city_images.asp?continent=" + continent_id;
	element = "city_images";
	ajaxRequest(url, element, "showCity()");
	
	return false;
}

function showCity(city_id) {
	if (city_id == null)
		city_id = getCity();
	
	var image_height = 137;
	var top = 0;
	
	// get all list items
	var list = $("city_images").getChildren()[0];
	var listItems = list.getChildren();

	// calculate top position based on selected city
	for (var i = 1; i < listItems.length; i++) {
		if (listItems[i].getProperty("id") == ("city" + city_id))
			top = i * image_height;
	}
	
	// set top position
	list.setStyle("top", (top * -1));
	
	return false;
}

function hideCity() {
	// reset top position
	$("city_images").getChildren()[0].setStyle("top", 0);
	
	return false;
}

function worldMapSubmit(city_id, section) {	
	var form = $("worldMapForm");
	form.elements["city_id"].value = city_id;
	
	switch(section) {
		case "schedule":
			setWorldMapFormAction();
			break;
	}
	
	form.submit();
}

function setWorldMapFormAction() {
	var form = $("worldMapForm");
	var continent_id = form.elements["continent_id"].value.toInt();
	
	// set form action attribute to path of continent page
	form.setProperty("action", getWorldMapFormAction(continent_id));
}