
/* map data */
var markerList = new Array();
var infoWindowList = new Array();
var locationList = [
	{	
		title: 'Webster Lot',
		address: '50 Washington St, Norwalk CT',
		price: '$49',
		hourly: 'Up to 1 hr: $1.00<br/>1-2 hours: $2.00<br/>2-3 hours: $3.00<br/>3-4 hours: $4.00<br/>4-24 hours: $6.00',
		permitURL: 'https://gtechna-norwalk.com/permit/login.xhtml',
		thumbnail: 'common/mapthumbs/Webster_Lot.jpg',
		position:new google.maps.LatLng(41.100035,-73.42095),
		icon: 'common/icons/NPA_01.png'
	},
	{	
		title:	'North Water Street Lot'	,
		address:	'1 North Water Street'	,
		//price:	''	,
		hourly: 'Up to 1 hr: $1.00<br/>1-2 hours: $2.00<br/>2-3 hours: $3.00<br/>3-4 hours: $4.00<br/>4-24 hours: $6.00',
		thumbnail:	'common/mapthumbs/North_Water_St_Lot.jpg'	,
		position:new google.maps.LatLng(41.099397,-73.41573)	,
		icon: 	'common/icons/NPA_02.png'
	},
	{	
		title:	'Maritme Garage'	,
		address:	'11 North Water Street, Norwalk CT'	,
		price:	'24 Hour access $83.33/12 Hour $25.00'	,
		hourly: 'Up to 1 hr: $2.00<br/>1-24 hours: $7.00<br/>Enter Before 9am - $7.00<br/>Enter After 5pm - $1.00',
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/Maritime_Garage.jpg'	,
		position:new google.maps.LatLng(	41.101429	,	-73.417482)	,
		icon: 	'common/icons/NPA_03.png'
	},
	{	
		title:	'Haviland Lot'	,
		address:	'8 Haviland St, Norwalk CT'	,
		price:	'$59'	,
		hourly: 'Up to 1 hr: $1.00<br/>1-2 hours: $2.00<br/>2-3 hours: $3.00<br/>3-4 hours: $4.00<br/>4-24 hours: $6.00',
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/Haviland_Lot.jpg'	,
		position:new google.maps.LatLng( 41.098176,-73.418391 )	,
		icon: 	'common/icons/NPA_04.png'
	},
	
	/* Wall Street Area */
	{	
		title:	'Main Street Lot (High Street Lot)'	,
		address:	'14 Main Street, Norwalk CT'	,
		price:	'$34'	,
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/Main_Ave_Lot.jpg'	,
		position:new google.maps.LatLng( 41.118957,-73.412262 )	,
		icon: 	'common/icons/NPA_05.png'
	},
	{	
		title:	'Wall Street Lot (Mechanic Street Lot)'	,
		address:	'42 Wall St, Norwalk CT'	,
		price:	'$34'	,
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/Mechanic_Street_Lot.jpg'	,
		position:new google.maps.LatLng( 41.118095,-73.412747 )	,
		icon: 	'common/icons/NPA_06.png'
	},
	{	
		title:	'Yankee Doodle Garage'	,
		address:	'3 Burnell Blvd, Norwalk, CT'	,
		price:	'$34'	,
		hourly: 'Up to 1 hr: $0.50<br/>1-2 hours: $1.00<br/>2-3 hours: $1.50<br/>3-24 hours: $3.00',
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/Yankee_Doodle_Garage.jpg'	,
		position:new google.maps.LatLng( 41.118369,-73.414786 )	,
		icon: 	'common/icons/NPA_07.png'
	},
	
	/* railroad stations */
	{	
		title:	'South Norwalk Train Station'	,
		address:	'1 State Street, Norwalk CT'	,
		price:	'$81'	,
		hourly: 'Daily rate: $9.00',
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		thumbnail:	'common/mapthumbs/SoNo_Train_Station.jpg'	,
		position:new google.maps.LatLng(41.0957, -73.42185)	,
		icon: 	'common/icons/NPA_08.png'
	},
	{
		title: 'East Norwalk Railroad Southbound Lot',
		address: '215 East Avenue, Norwalk CT',
		price: '$43',
		permitURL: 'https://gtechna-norwalk.com/permit/login.xhtml',
		thumbnail: 'common/mapthumbs/thumb_eastnorwalk.jpg',
		position:new google.maps.LatLng(41.10444,-73.403746),
		icon: 'common/icons/NPA_09.png'
	},
	{	
		title: 'East Norwalk Railroad Northbound Lot',
		address: '215 East Avenue, Norwalk CT',
		price: '$43',
		permitURL: 'https://gtechna-norwalk.com/permit/login.xhtml',
		thumbnail: 'common/mapthumbs/thumb_eastnorwalk.jpg',
		position:new google.maps.LatLng(41.102699,-73.406605),
		icon: 'common/icons/NPA_10.png'
	},
	{			
		title:	'East Norwalk St. Thomas School Lot'	,
		address:	'208 East Avenue, Norwalk CT'	,
		price:	'$43'	,
		permitURL:	'https://gtechna-norwalk.com/permit/login.xhtml'	,
		//thumbnail:	'common/mapthumbs/.jpg'	,
		position:new google.maps.LatLng(41.105901,-73.404867)	,
		icon: 	'common/icons/NPA_11.png'
	},
	
	/* other */
	{	
		title:	'City Hall Lot'	,
		address:	'125 East Avenue, Norwalk CT'	,
		thumbnail:	'common/mapthumbs/City_Hall_Lot.jpg'	,
		position:new google.maps.LatLng( 41.113423,-73.407598 )	,
		icon: 	'common/icons/NPA_12.png'
	},
	
	
	/* points of interest */
	{
	title:'Stepping Stones Museum for Children'	,
	address:'303 West Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.109672,-73.415443),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'IMAX Maritime Aquarium Norwalk',
	address:'10 North Water Street Norwalk, CT',
	position:new google.maps.LatLng(41.099924,-73.415939),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Norwalk Museum',
	address:'41 North Main Street Norwalk, CT',
	position:new google.maps.LatLng(41.100254,-73.418938),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'South Norwalk Library',
	address:'10 Washington Street Norwalk, CT',
	position:new google.maps.LatLng(41.099114,-73.421695),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Western Connecticut Convention and Visitors Bureau',
	address:'297 West Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.109602,-73.417642),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Lockwood-Mathews Mansion',
	address:'295 West Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.109163,-73.416988),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Center For Contemporary Print'	,
	address:'299 West Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.113827,-73.418026),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Norwalk City Hall'	,
	address:'125 East Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.113233,-73.406889),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Norwalk Public Library'	,
	address:'1 Belden Avenue Norwalk, CT',
	position:new google.maps.LatLng(41.116664,-73.415011),
	icon: 	'common/icons/POI.png'
	},
	{
	title:'Mill Hill Park'	,
	address:'1-7 E wall St, Norwalk CT',
	position:new google.maps.LatLng(41.1175, -73.4095),
	icon: 	'common/icons/POI.png'
	},
	
	/* non-NPA parking */
	
	{	
		title:	'Non-NPA parking'	,
		address:	'Isaac st, Norwalk, CT'	,
		position:new google.maps.LatLng(41.116714,-73.413037)	,
		icon: 	'common/icons/NonNPA.png'
	},
	{	
		title:	'Non-NPA parking'	,
		address:	'174 Washington St, Norwalk, CT'	,
		position:new google.maps.LatLng(41.09891,-73.416454)	,
		icon: 	'common/icons/NonNPA.png'
	},
	{	
		title:	'Non-NPA parking'	,
		address:	'130 Washington St, Norwalk, CT'	,
		position:new google.maps.LatLng(41.098948,-73.417366)	,
		icon: 	'common/icons/NonNPA.png'
	},
	{	
		title:	'Non-NPA parking'	,
		address:	'64 Water St, Norwalk, CT'	,
		position:new google.maps.LatLng(41.098077,-73.416156)	,
		icon: 	'common/icons/NonNPA.png'
	},
	{	
		title:	'Non-NPA parking'	,
		address:	'41 S Main St, Norwalk, CT'	,
		position:new google.maps.LatLng(41.097945,-73.41889)	,
		icon: 	'common/icons/NonNPA.png'
	},
];

/* map functions */

var map;

var lastInfoWindow=null;

function gmap_initialize() {
	var latlng = new google.maps.LatLng(41.109,-73.416395);
	var mapOptions = {
		zoom: 14,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		disableDefaultUI: true,
		scrollwheel: false,
		draggable: true,
		navigationControl: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.SMALL
		}
	};
	
	detectBrowser(mapOptions);
	
	map = new google.maps.Map(document.getElementById("map_canvas"),
			mapOptions);

	for (var i in locationList){
		var loc = locationList[i];
		loc.map = map;
		if(loc.position ==null)
			loc.position = new google.maps.LatLng(loc.latitude, loc.longitude)
		//create marker from title, position, icon
		var marker = new google.maps.Marker(loc);
		markerList.push(marker);

		var thumbnail = '';
		if(loc.thumbnail!=undefined) thumbnail = '<img src="'+loc.thumbnail+'" width="202" height="109" /><br /><br />';
		var pricePermit = '<br />';
		if(loc.price!=undefined)
			pricePermit = '<span style="color:red;display:inline-block;padding-top:8px;"> Monthly permit: '+loc.price+'</span><br />'
			+'Parking permit applications may be obtained<br />'
			+'by <a href="'+loc.permitURL+'" target=map onclick="popup(this)" >clicking here</a><br /><br />';
		var hourlyRates = '';
		if(loc.hourly!=undefined){
			hourlyRates = '<span style="color:red;display:inline-block;padding-top:8px;">Hourly rates: <a href="javascript:void(0)" onClick="popHourlyRates(this);return false;">click here<div class="hiddenBox"><span>'+loc.hourly+'</span></div></a></span><br/>'
		}

		//add info window for this location
		var content = '<div id="content" style="font-size:11px;line-height:12px;">'
				+'<div id="bodyContent" style="overflow:hidden;">'
				+'<b style="font-size:14px;">' + loc.title + '</b><br />'
				+'<b>'+loc.address+'</b><br />'
				+ hourlyRates
				+ pricePermit
				+ thumbnail
				+'<a href="http://maps.google.com/maps?daddr='+escape(loc.address)+'" target=map onclick="popup(this)" >Get Directions</a>'
				+' <a href="http://maps.google.com/maps?http://maps.google.com/maps?q=&Search=Search&near='+escape(loc.address)+'" target=map onclick="popup(this)" >Search Nearby</a>'
				+'<br /><br /></div></div>';
		// (uses "content" propertye
		var infoWindow = new google.maps.InfoWindow({
			content: content
		});

		//tie infoWindow to this marker
		google.maps.event.addListener(marker, 'click',
			(function(infoWindow, marker, map) { return function() {
				
				infoWindow.maxWidth=220;
	  			infoWindow.open(map,marker);
				
				if(lastInfoWindow!=null)
					lastInfoWindow.close();
				lastInfoWindow = infoWindow;
				
				//infoWindow.setContent("hi!");
    		}})(infoWindow, marker, map));

		infoWindowList.push(infoWindow);
	}
}
  
function showLocation(index){
	
	if (index>infoWindowList.length)
		return;
	
	//bail if the same loc is clicked twice
	if (infoWindowList[index-1] == lastInfoWindow)
		return;
	
	infoWindowList[index-1].open(map,markerList[index-1]);
	
	if(lastInfoWindow!=null)
		lastInfoWindow.close();
	lastInfoWindow = infoWindowList[index-1];
}

function popup(linkNode){
	newwindow=window.open(linkNode.href,linkNode.target);
	if (window.focus) {newwindow.focus();}
	return false;
}

function popHourlyRates(linkNode){
	$(linkNode).css('position','relative');
	$(linkNode).children('div').toggle();
	$(linkNode).children('div').css('position','absolute');
	
}


function detectBrowser(mapOptions) {
  var useragent = navigator.userAgent;
  var mapdiv = document.getElementById("map_canvas");
    
  if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
    mapdiv.style.width = '480px';
    mapdiv.style.height = '480px';
	mapOptions.draggable=false;
  } /*else {
    mapdiv.style.width = '600px';
    mapdiv.style.height = '800px';
  } */
}

