(function($){
    $.fn.MapWizard = function(trail_id, trail_name)
    {
        var wizard = new wizardMaker(this);
        wizard.setData('trail_map', {'trail_name' : trail_name});

        wizard.addSlide('trail_map');
        wizard.setInitialSlide('trail_map');
        wizard.setSlideOptions('trail_map', {
            'action' : 'slides/trail_map',
            'width' : 900,
            'height' : 700,
            'dataNeeded' : 'trail_map',
            'onLoad' : trailMapLoad
        });

/*********************************LOADS*******************************************************/

       function trailMapLoad()
       {
           var map = new GMap2($('#wizard_trail_map .map').get(0));
           map.setUIToDefault();

           $.post(absoluteFilepath('actions/getEncodedTrail'),
           {'trail_id' : trail_id},
           function(results){
              var trailhead = new GLatLng(Number(results['trailhead']['latitude']), Number(results['trailhead']['longitude']));

              map.setCenter(trailhead);
              map.setZoom(16);

              var unselected_icon_image = "/images/trailhead_post_green_glow.png";
              var unselected_icon = new GIcon(G_DEFAULT_ICON);
              unselected_icon.iconSize = new GSize(20);
              unselected_icon.image = unselected_icon_image;
              unselected_icon.iconAnchor = new GPoint(8, 16);
              unselected_icon.shadowSize = new GSize(0, 0);
			
			

              var marker = new GMarker(trailhead , {
                'icon' : unselected_icon
              });
              map.addOverlay(marker);
              
              var polyline = new GPolyline.fromEncoded({
                                color: "#ff0000",
                                weight: 3,
                                opacity: 0.8,
                                points: results['trail_encoded']['Points'],
                                levels: results['trail_encoded']['Levels'],
                                zoomFactor: results['trail_encoded']['ZoomFactor'],
                                numLevels: results['trail_encoded']['NumLevels']
                            });

              map.addOverlay(polyline);

            },
           'json');
       }
    }
})(jQuery);



