﻿var previousSpot = null;

function toggleEuropeMap() {
    $("#startMap").hide();
    $("#europeselector").show();
}

function toggleSouthAmericaMap() {
    $("#startMap").hide();
    $("#southamericaselector").show();
}

function toggleWorldMap() {
    $("#europeselector").hide();
    $("#southamericaselector").hide();

    $("#startMap").show();
}

$(
// world map behaviors		
			function() {
			    $("#europeselector").show();

			    $("#map .spot").mouseover(
				    function() {
				        if (previousSpot != null) {
				            previousSpot.parent().removeClass("hover");
				            previousSpot.hide();
				        }

				        $(".label", this).show();
					}
			    );

			    $("#map .spot").mouseout(
				    function() {
				        $(".label", this).hide();
				    }
			    );

			    $("#toEuropeMap").click(
					function() {
					    toggleEuropeMap();
					}
				);

			    $("#toSouthAmericaMap").click(
					function() {
					    toggleSouthAmericaMap();
					}
				);

			    // europe map behaviors
			    $(":input[name=countryThemeList], :input[name=europeList], :input[name=southAmericaList]").change(
					function() {
					    $val = $.trim($(this).val());

					    if ($val == "backToWorldMap") {
					        toggleWorldMap();
					    } else {
					        if ($val != "") {
					            document.location = $val;
					        }
					    }
					}
				);

			    // country list behavior
			    $(":input[name=countryList]").change(
					function() {
					    $val = this.options[this.selectedIndex].getAttribute("title");

					    if (previousSpot != null) {
					        previousSpot.hide();
					        previousSpot.parent().removeClass("hover");
					        previousSpot = null;
					    }

					    $("#" + $val).show();

					    previousSpot = $("#" + $val);
					    previousSpot.parent().addClass("hover");

					}
				);

			    $("#send").click(
					function() {
					    $val = $(":input[name=countryList]").val();
					    if ($val != "backToWorldMap" && $val != "") {
					        //alert($val);
					        document.location = $val;
					    }
					}
				);

			    $(":input[name=continentList]").change(
					function() {
					    $val = $(this).val();

					    switch ($val) {
					        case "europe":
					            toggleEuropeMap();
					            break;
					        case "southamerica":
					            toggleSouthAmericaMap();
					            break;
					    }
					}
				)
			}
		)
