var WTB = {
  map: null,
  infoWindow: null,
  visibleInfoWindow: false,
  markers: [],
  markersHTML: [],
  markersInfo: []
};
WTB.closeInfoWindow = function() {
	WTB.infoWindow.close();
};
WTB.clickMarker = function(markerNum) {
	if (WTB.visibleInfoWindow != false) {
		WTB.visibleInfoWindow.close();
	}
	WTB.markersInfo[markerNum].open(WTB.map, WTB.markers[markerNum]);
	WTB.visibleInfoWindow = WTB.markersInfo[markerNum];
}
WTB.openInfoWindow = function(infoWindow, marker) {
	return function() {
		if (WTB.visibleInfoWindow != false) {
			WTB.visibleInfoWindow.close();
		}
		infoWindow.open(WTB.map, marker);
		WTB.visibleInfoWindow = infoWindow;
	};
};

WTB.init = function( ) {
	WTB.map = new google.maps.Map( document.getElementById(mapcanvas[0]), {
		zoom: 12,
		center: new google.maps.LatLng(mapcanvas[1], mapcanvas[2]),
		panControl: true,
    	zoomControl: true,
    	scaleControl: true,
    	mapTypeControl:false,
    	mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	WTB.infoWindow = new google.maps.InfoWindow();
	google.maps.event.addListener(WTB.map, 'click', WTB.closeInfoWindow);
	for(var i=0;i<points.length;i++){
		var m = points[i];
		WTB.markers[i] = new google.maps.Marker({
			map: WTB.map,
		  	position: new google.maps.LatLng(m[1],m[2]),
			draggable: false,
			animation: google.maps.Animation.DROP,
			icon: m[3],
			title: m[0]
		});
		WTB.markersInfo[i] = new google.maps.InfoWindow({
        	content: $(".StoreInfo","#Store"+m[4]).html(),
        	size: new google.maps.Size(200, 80)
		});
		$("#Store"+m[4]).css("cursor","pointer").data("markerNum", i ).click(function(el) {
			WTB.clickMarker($(this).data('markerNum'));
		});
		google.maps.event.addListener(WTB.markers[i], 'click', WTB.openInfoWindow(WTB.markersInfo[i], WTB.markers[i]));
	}
};
