function load_trafic() {
	frames["trafic"].location.href = "inc/templates/trafic.html";
}

function load_map() {
	if (GBrowserIsCompatible()) {
		window.initial_Zoom = 6;
		window.map = new google.maps.Map2(document.getElementById("map"));
		window.initial_client_point = new GLatLng(45.891537, 24.906006);
		window.map.setCenter(window.initial_client_point, window.initial_Zoom, G_HYBRID_MAP);
		window.map.addControl(new GSmallZoomControl());
		window.map.enableContinuousZoom();
		window.map.enableScrollWheelZoom();
		window.map_initialized = 1;
		if(window.temp_zonedata && window.temp_coordinates && window.temp_locations && window.temp_images_path && window.temp_texts)
			toggle_on_map(window.temp_zonedata, window.temp_coordinates, window.temp_locations, window.temp_images_path, window.temp_texts);
		if(window.temp_idZone && window.temp_idLocation) show_info_marker(window.temp_idZone, window.temp_idLocation);
	}
}

function loadMaps() {
	google.load("maps", "2", {"callback" : load_map});
}

function initLoader() {
	var script = document.createElement("script");
	script.src = "http://www.google.com/jsapi?key=ABQIAAAAsHbb9mxrkRwviZrhqlzyEBQA85emVUyT5-GowT6n7qha9Irl2xSK_3QI4S-9CttUYyv5zxyFjGpolA&callback=loadMaps";
	script.type = "text/javascript";
	document.getElementsByTagName("head")[0].appendChild(script);
}

function prepare_toggle_on_map(zonedata, coordinates, locations, images_path, texts) {
	window.temp_zonedata = zonedata;
	window.temp_coordinates = coordinates;
	window.temp_locations = locations;
	window.temp_images_path = images_path;
	window.temp_texts = texts;
} // end function prepare_toggle_on_map

function toggle_on_map(zonedata, coordinates, locations, images_path, texts) {
	// load map
	if(window.map_initialized != 1) {
		// in case map is in parent window
		if(!document.getElementById("map") && parent != self) {
			parent.toggle_on_map(zonedata, coordinates, locations, images_path, texts);
			return;
		}

		// else initialize map
		window.temp_zonedata = zonedata;
		window.temp_coordinates = coordinates;
		window.temp_locations = locations;
		window.temp_images_path = images_path;
		window.temp_texts = texts;
		initLoader();
		return; // do not continue the function until the map is loaded, then toggle_on_map is called again from load_map();
	}

	// texts:
	var accommodation_offers = texts[0];
	var offers_in = texts[1];

	// close previous info window
	window.map.closeInfoWindow();
	var idZone = zonedata[0];

	// hide previous displayed markers
	if(window.idZone && window.idZone != idZone) if(window.markerGroups) if(window.markerGroups[window.idZone]) {
		for (var i in window.markerGroups[window.idZone]) {
			window.markerGroups[window.idZone][i].hide();
		}
	}

	window.idZone = idZone;

	if(!window.markerGroups) {
		window.markerGroups = new Array();
	}

	// create markers
	if(!window.markerGroups[idZone]) {
		window.markerGroups[idZone] = new Array();
		if(!window.points) window.points = new Array();
		// display locations
		for (var i = 0; i < coordinates.length; i++) {
			idLocation = coordinates[i][0];
			// create icon
//			var icon = new GIcon(G_DEFAULT_ICON, ""+images_path+"/location_"+i+".8.png");
			var icon = new GIcon(G_DEFAULT_ICON, ""+images_path+"/star.png");
			icon.iconAnchor = new GPoint(11, 4);
			icon.iconSize = new GSize(22, 22);
			icon.shadow = "";
			// create marker and display
			window.points[idLocation] = new GLatLng(coordinates[i][1], coordinates[i][2]);
			var html = "<div class=\"location_txt\">&nbsp;<a class=\"nobold\" href=\""+locations[i][3]+"\"><b>"+locations[i][2]+"</b>: "+locations[i][1]+" "+accommodation_offers+" "+"</a> <span class=\"carta_magenta\">&raquo;</span>";
			window.markerGroups[idZone][idLocation] = createMarker(window.points[idLocation], icon, html);
			window.map.addOverlay(window.markerGroups[idZone][idLocation]);
		}
	}
	// markers already existing, show
	else {
		for (var i in window.markerGroups[window.idZone]) {
			window.markerGroups[window.idZone][i].show();
		}
	}

	// set map zoom to displayed markers
	var number_of_locations = 0;
	for (var i in window.markerGroups[window.idZone]) { // i is idLocation
		number_of_locations++;
	}
	if(number_of_locations > 1) {
		var bounds = new GLatLngBounds;
		for (var i in window.markerGroups[window.idZone]) { // i is idLocation
			bounds.extend(window.markerGroups[window.idZone][i].getLatLng());
		}
		window.map.setZoom(map.getBoundsZoomLevel(bounds));
		window.map.panTo(bounds.getCenter());
	}
	else {
		window.map.setCenter(window.initial_client_point, window.initial_Zoom, G_HYBRID_MAP);
		show_info_marker(window.idZone, locations[0][0]);
	}

	// if prepare has set a permanent info marker
	if(window.permanent_marker_idZone && window.permanent_marker_idLocation) revert_to_permanent_info_marker(0, 0);
} // end function toggle_on_map

function createMarker(point, icon, html) {
	var marker = new GMarker(point, icon);
	// show info marker on mouseover
	GEvent.addListener(marker, "mouseover", function() {
		marker.openInfoWindowHtml(html)
	});
	return marker;
} // end function createMarker(point)


function show_info_marker(idZone, idLocation) {
	// in case map is in parent window
	if(!document.getElementById("map") && parent != self) {
		parent.show_info_marker(idZone, idLocation);
		return;
	}

	// in case map is not loaded load map
	if(window.map_initialized != 1) {
		window.temp_idZone = idZone;
		window.temp_idLocation = idLocation;
		initLoader();
		return; // do not continue the function until the map is loaded, then show_info_marker is called again from load_map();
	}

	// show info marker
	GEvent.trigger(window.markerGroups[idZone][idLocation], "mouseover");
} // end function show_info_marker

function show_permanent_info_marker(idZone, idLocation) {
	show_info_marker(idZone, idLocation);
	window.permanent_marker_idZone = idZone;
	window.permanent_marker_idLocation = idLocation;
} // end function show_permanent_info_marker

function prepare_permanent_info_marker(idZone, idLocation) {
	window.permanent_marker_idZone = idZone;
	window.permanent_marker_idLocation = idLocation;
} // end function prepare_permanent_info_marker

function revert_to_permanent_info_marker(idZone, idLocation) {
	// in case map is in parent window
	if(!document.getElementById("map") && parent != self) {
		parent.revert_to_permanent_info_marker(idZone, idLocation);
		return;
	}

	if(window.permanent_marker_idZone) GEvent.trigger(window.markerGroups[window.permanent_marker_idZone][window.permanent_marker_idLocation], "mouseover");
} // end function revert_to_permanent_info_marker

function toggle_zone_div(idZone) {
	// hide previous highlighed zone
	if(window.idZoneDiv && window.idZoneDiv != idZone) {
		if(document.getElementById('vertical_navigation_div_'+window.idZoneDiv)) {
			document.getElementById('vertical_navigation_div_'+window.idZoneDiv).className = 'vertical_navigation_div';
		}
	}

	// highlight zone div
	if(document.getElementById('vertical_navigation_div_'+idZone)) {
		document.getElementById('vertical_navigation_div_'+idZone).className = 'selected_vertical_navigation_div';
		window.idZoneDiv = idZone;
	}
} // end function toggle_zone_div


//]]>
