jQuery(document).ready(function(){

    /**
     * autor : CTAPbIu_MABP
     * email : ctapbiumabp@gmail.com
     * url : http://mabp.kiev.ua/2010/08/15/multiple-infowindow/
     */

	/* example 1*/
	var map = new google.maps.Map(document.getElementById("map1"), {
		zoom: 5,
		center: new google.maps.LatLng(50.440951, 30.527181),
		mapTypeId: google.maps.MapTypeId.HYBRID
	});
	var marker = new google.maps.Marker({
		map: map,
		position : new google.maps.LatLng(50.440951, 30.527181),
		draggable : false
	});
	google.maps.event.addListener(marker, "click", function(e){
		map.setCenter(this.getPosition());
		new google.maps.InfoWindow({
			content: this.getPosition().toString()
		}).open(map, this);
	});

	/* example 2*/
	var myMarkerManager1 = new MarkerManager(
		new google.maps.Map(document.getElementById("map2"), {
			zoom: 5,
			center: new google.maps.LatLng(50, 27),
			mapTypeId: google.maps.MapTypeId.HYBRID
		})
	);
	myMarkerManager1.createMarker(new google.maps.LatLng(50.440951, 30.527181));
	myMarkerManager1.createMarker(new google.maps.LatLng(49.836944, 24.005000));

	var windows = [];
	function createInfoWindow(marker){
		var window = new google.maps.InfoWindow({
			content: marker.getPosition().toString()
		})
		google.maps.event.addListener(window, "closeclick", function(e){
			windows.splice(MarkerManager.prototype.inArray(marker, windows), 1);
		});
		window.open(myMarkerManager1.map, marker);
		windows.push(window);
	}
		
	for (var i in myMarkerManager1.markers){
		google.maps.event.addListener(myMarkerManager1.markers[i], "click", function(e){
			myMarkerManager1.map.setCenter(this.getPosition());
			
			for (var i=0, length=windows.length; i<length; i++){
				if (windows[i].getContent()==this.getPosition().toString()) {
					return;
				}
			}
			createInfoWindow(this);
		})
	}

	/* example 3*/
	google.maps.Marker.prototype.openInfoWindow = function(content){
		if (!(this.InfoWindow && this.InfoWindow.getContent() == content)){ 
			this.InfoWindow = new google.maps.InfoWindow({
				content: content
			});
		}
		this.InfoWindow.open(this.map, this);
	}
		
	var myMarkerManager2 = new MarkerManager(
		new google.maps.Map(document.getElementById("map3"), {
			zoom: 5,
			center: new google.maps.LatLng(50, 27),
			mapTypeId: google.maps.MapTypeId.HYBRID
		})
	);

	myMarkerManager2.createMarker(new google.maps.LatLng(50.440951, 30.527181));
	myMarkerManager2.createMarker(new google.maps.LatLng(49.836944, 24.005000));
		
	for (var i in myMarkerManager2.markers){
		google.maps.event.addListener(myMarkerManager2.markers[i], "click", function(e){
			myMarkerManager2.map.setCenter(this.getPosition());
			this.openInfoWindow(this.getPosition().toString());
		});
	}
});
