
var j = jQuery.noConflict();
j(document).ready(function($){
	
	// Clickable Logo
    $('body').addClickableLogo({
        name: 'Iowa Primary Care Association',
        url: 'http://www.iowapca.org'
    });
    
    // Google Map
	if ($('#google-map').length) {
		
		// Setup variables
		var gmarkers = [];
		var infowindow = new google.maps.InfoWindow();
		var latlng = new google.maps.LatLng(42.025489,-93.62586);
		var geocoder = new google.maps.Geocoder();
		var map = new google.maps.Map(document.getElementById("map-canvas"), { 
			zoom: 7,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.TERRAIN
		});
		
		// Setup Clinic Markers
		var clinicMarker = new google.maps.MarkerImage('/associations/12735/imgs/icon-clinic.png',
			new google.maps.Size(24,21),
			new google.maps.Point(0,0),
			new google.maps.Point(11,11)
		);
		
		// Setup Satellite Markers
		var satelliteMarker = new google.maps.MarkerImage('/associations/12735/imgs/icon-satellite.png',
			new google.maps.Size(16,16),
			new google.maps.Point(0,0),
			new google.maps.Point(7,7)
		);
		
		// Info Window
		var infowindow = new google.maps.InfoWindow({
			maxWidth: 300
		}); 

		// Place Markers
		$('.clinic, .satellite').each(function(){
			var type = $(this).attr('class');
			var title = $(this).children('h3').text();
			var icon = '';
			if (type == 'clinic') {
				icon = clinicMarker;
			} else {
				icon = satelliteMarker;
			}
			
			// Create Info Window
			var info = $(this).html();

			// Place Custom Markers
			var myLatlng = new google.maps.LatLng($(this).attr('geoLat'), $(this).attr('geoLong'));
			var marker = new google.maps.Marker({
				position: myLatlng,
				map: map,
				icon: icon,
				zIndex: 3,
				title: title
			});
			gmarkers.push(marker);
			marker.type = type;
	
			// Popup Bubbles
			google.maps.event.addListener(marker, 'click', function() {
				infowindow.close();
				infowindow.setContent(info);
				infowindow.setPosition(marker.getPosition());
				infowindow.open(map,marker);
			});
		});
	}
						   
});


