
jQuery(document).ready(function(){ //Start script when ready
    if (document.getElementById("map_canvas")) {//Checks to see that the page element exists and to prevent conflict with other maps
	
		// Create our "tiny" marker icon
		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.image = "images/map_marker.png";
		blueIcon.iconSize = new GSize(25, 25);
		blueIcon.shadowSize = new GSize(40, 26);
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };

        //Default map center location
        var defaultLat = 30.38;
        var defaultLon = -97.75;
        var markers = new Array(); // For Lat & Long use http://itouchmap.com/latlong.html

markers[0] = new Array(new GMarker(new GLatLng(30.26883,-97.757152),markerOptions), "Austin", "<strong>TownLake Branch</strong><br />1100 W. Cesar Chavez<br />Austin, TX 78703<br /><strong>(P)</strong> 512-542-9622<br /><a href='http://www.austinymca.org/branches/loc.php?loc=1'>Branch Website</a><a href='http://maps.google.com/maps?q=1100+W.+Cesar+Chavez+Austin+TX+78703' target='_blank'>Get Directions to Branch</a>");

markers[1] = new Array(new GMarker(new GLatLng(30.291928,-97.662591),markerOptions), "East Austin", "<strong>East Communities Branch</strong><br />5315 Ed Bluestein<br />Austin, TX 78723<br /><strong>(P)</strong> 512-933-9622<br /><a href='http://www.austinymca.org/branches/loc.php?loc=7'>Branch Website</a><a href='http://maps.google.com/maps?q=5315+Ed+Bluestein+Austin+TX+78723' target='_blank'>Get Directions to Branch</a>");

markers[2] = new Array(new GMarker(new GLatLng(30.366636,-97.695794),markerOptions), "North Austin", "<strong>North Park Branch</strong><br />9616 N. Lamar Blvd,<br />Ste. 130<br />Austin, TX 78753<br /><strong>(P)</strong> 512-973-9622<br /><a href='http://www.austinymca.org/branches/loc.php?loc=8'>Branch Website</a><a href='http://maps.google.com/maps?q=9616+N+Lamar+blvd+Austin+TX+78753' target='_blank'>Get Directions to Branch</a>");

markers[3] = new Array(new GMarker(new GLatLng(30.446271,-97.734174),markerOptions), "Northwest Austin", "<strong>Northwest Family Branch</strong><br />5807 McNeil Dr.<br />Austin, TX 78729<br /><strong>(P)</strong> 512-335-9622<br /><a href='http://www.austinymca.org/branches/loc.php?loc=4'>Branch Website</a><a href='http://maps.google.com/maps?q=5807+McNeil+Dr+Austin+TX+78729' target='_blank'>Get Directions to Branch</a>");

markers[4] = new Array(new GMarker(new GLatLng(30.236324,-97.853689),markerOptions), "Southwest Austin", "<strong>Southwest Branch</strong><br />6219 Oakclaire Dr.<br />Austin, TX 78735<br /><strong>(P)</strong> 512-891-9622<br /><a href='http://www.austinymca.org/branches/loc.php?loc=6'>Branch Website</a><a href='http://maps.google.com/maps?q=6219+Oakclaire+Dr+Austin+TX+78735' target='_blank'>Get Directions to Branch</a>");

markers[5] = new Array(new GMarker(new GLatLng(30.100231,-97.879986),markerOptions), "Buda / Kyle", "<strong>Hays Communities Family Branch</strong><br />465 Buda Sportsplex Dr.<br />Buda, TX 78610<br /><strong>(P)</strong> 512-523-0099<br /><a href='http://www.austinymca.org/branches/loc.php?loc=5'>Branch Website</a><a href='http://maps.google.com/maps?q=465+Buda+Sportsplex+Dr.+Buda+TX+78610' target='_blank'>Get Directions to Branch</a>");

markers[6] = new Array(new GMarker(new GLatLng(30.494951,-97.809563),markerOptions), "Cedar Park", "<strong>Twin Lakes Family YMCA</strong><br />204 E. Little Elm Trl.,<br />Cedar Park, TX 78613<br /><strong>(P)</strong> 512-250-9622<br /><a href='http://www.ymcagwc.org/branch.php?loc=5'>Branch Website</a><a href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Twin+Lakes+Ymca+Texas&sll=30.583698,-97.412358&sspn=0.006484,0.012907&g=30.583698,-97.412358&ie=UTF8&hq=Twin+Lakes+Ymca&hnear=Texas&z=8&iwloc=A' target='_blank'>Get Directions to Branch</a>");	

markers[7] = new Array(new GMarker(new GLatLng(30.183434,-98.085733),markerOptions), "Dripping Springs", "<strong>Springs Family Branch</strong><br />27216 Ranch Rd. 12<br />Dripping Springs, TX 78620<br /><strong>(P)</strong> 512-894-3309<br /><a href='http://www.austinymca.org/branches/loc.php?loc=11'>Branch Website</a><a href='http://maps.google.com/maps?q=27216+Ranch+Rd.+12+Dripping Springs+TX+78620' target='_blank'>Get Directions to Branch</a>");

markers[8] = new Array(new GMarker(new GLatLng(30.543744,-97.544225),markerOptions), "Hutto", "<strong>Hutto Family YMCA</strong><br />101 Anthony St.,<br />Hutto, TX 78634<br /><strong>(P)</strong> 512-846-2360<br /><a href='http://www.ymcagwc.org/branch.php?loc=7'>Branch Website</a><a href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=30.583698,-97.412358&sll=30.526106,-97.686918&sspn=3.836995,4.762573&ie=UTF8&z=17&iwloc=r4' target='_blank'>Get Directions to Branch</a>");	   

markers[9] = new Array(new GMarker(new GLatLng(30.526106,-97.686918),markerOptions), "Round Rock", "<strong>CHASCO Family YMCA</strong><br />1812 N. Mays St.,<br />Round Rock, TX 78664<br /><strong>(P)</strong> 512-246-9622<br /><a href='http://www.ymcagwc.org/branch.php?loc=3'>Branch Website</a><a href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=chasco+ymca+texas&sll=33.346393,-111.829662&sspn=0.013981,0.022187&ie=UTF8&hq=chasco+ymca&hnear=Texas&z=8&iwloc=A' target='_blank'>Get Directions to Branch</a>");

markers[10] = new Array(new GMarker(new GLatLng(30.583698,-97.412358),markerOptions), "Taylor", "<strong>Taylor Family YMCA</strong><br />106 W. Lake Dr.,<br />Taylor, TX 76574<br /><strong>(P)</strong> 512-365-9622<br /><a href='http://www.ymcagwc.org/branch.php?loc=4'>Branch Website</a><a href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=101+Anthony+St.+Hutto,+TX+78634&sll=37.0625,-95.677068&sspn=49.891082,68.90625&ie=UTF8&hq=&hnear=101+Anthony+St,+Hutto,+Williamson,+Texas+78634&ll=30.543743,-97.544225&spn=0.001693,0.002578&t=h&z=19&iwloc=A' target='_blank'>Get Directions to Branch</a>");
	   	   

	   
	   
	   
        var map = new google.maps.Map2(jQuery("#map_canvas").get(0));//Initialise google maps
		map.setMapType(G_NORMAL_MAP);
        map.setCenter(new GLatLng(defaultLat, defaultLon), 10);//Set location to the default and zoom level to 8
		var mapControl = new GMapTypeControl();
			map.addControl(mapControl);
		map.addControl(new GLargeMapControl());

        jQuery(markers).each(function(i,marker){
           map.addOverlay(marker[0]);
            jQuery("<li />")
                .html(markers[i][1])//Use list item label from array
                .click(function(){
                    displayPoint(marker[0], i);
                    setActive(this);//Show active state
                    if (jQuery('#map_message').is(':hidden')) {//Allow toggling of active state
                        setActive();
                    }
                })
                .appendTo("#map_list");
            
            GEvent.addListener(marker[0], "click", function(){
                displayPoint(marker[0], i);
                setActive(i);//Show active location
                if (jQuery('#map_message').is(':hidden')) {//Allow toggling of active state
                    setActive();
                }
            });
        });
        
        jQuery("#map_list").css("opacity","0.2").animate({opacity: 1}, 1100);//Fade in menu
        jQuery("#map_message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
                        
        function displayPoint(marker, index){
            if (jQuery('#map_message').is(':hidden')) {//Allow toggling of markers
                jQuery('#map_message').fadeIn();
            }
            else{//Remove all .active classes and hide markers
                jQuery('#map_message').hide();
                jQuery(".active").removeClass();
            }
            //jQuery("#map_message").hide();//Default behaviour, doesn't allow toggling
            
            var moveEnd = GEvent.addListener(map, "moveend", function(){
                var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
                jQuery("#map_message")
                    .html(markers[index][2])//Use information from array
                    .fadeIn()
                    .css({ top:markerOffset.y, left:markerOffset.x });
            GEvent.removeListener(moveEnd);
            });
            map.panTo(marker.getLatLng());
			//map.setZoom(10);
        }	
        
        function setActive(el){
            jQuery("#map_list").find('li').eq(el).addClass('active');//Find list element equal to index number and set active
            jQuery(el).addClass('active');//Set active if list element clicked directly
        }
    }//End if map_canvas exists
}); //End onReady

