/* -- BEGIN: salon finder ----------------------------------------------- */

  SalonFinderMap = Class.create(CustomGoogleMap, {
    extractLocationDataFromDOM : function(element) {
      return {
        // required
        lat : parseFloat(this.getTextValue(element, this.CONFIG['lat_class'])),
        lng : parseFloat(this.getTextValue(element, this.CONFIG['lng_class'])),

        // suggested
        title       : this.getTextValue(element, this.CONFIG['title_class']),
        address     : this.getHTMLValue(element, this.CONFIG['address_class']),
        phone       : this.getHTMLValue(element, this.CONFIG['phone_class']),
        url         : this.getHTMLValue(element, 'website'),
        offers      : this.getHTMLValue(element, 'salon-offers-link'),
        services    : this.getHTMLValue(element, 'salon-services'),
        directions  : this.getHTMLValue(element, 'salon-directions'),
        colorists   : this.getHTMLValue(element, 'colorist-links'),

        icon        : this.determineCustomIconProperties(element)
      };
    }, // END: extractLocationDataFromDOM

    determineCustomIconProperties : function(el) {
      try {
        el = $(el);

        // if we lack a config or a desired attrib, then bail out
        if ( (Object.keys(this.CONFIG['marker_class_properties']).length < 1) || !el) { return null; }

        // get salon type of the element (without the standard classes)
        var salon_type = el.classNames().toArray().without("salon", "vcard", "First").reduce();
        var icon_data = this.CONFIG['marker_class_properties'][salon_type];

        return (salon_type && icon_data) ? icon_data : null;

      } catch(e) {
        return null;
      }
    },

    attachLocationEventListeners : function(location_node) {
      location_node.down('STRONG.Link').observe('click', this.handleLocationClick.bindAsEventListener(this, location_node));
    }
  });

  // extend handleMarkerClick() to track salon views
  SalonFinderMap.prototype.handleMarkerClick = SalonFinderMap.prototype.handleMarkerClick.wrap(
    function(handleMarkerClick_orig, marker) {
      // track the salon 'views' via AJAX call
      new Ajax.Request('/salons/' + marker.data.id + "/track", {
        'method' : 'get'
      });

      // run the original function
      handleMarkerClick_orig(marker);
    }
  );

  fixWebKitInheritanceBug(SalonFinderMap);

  SalonFinderMap.CONFIG = Object.extend(Object.clone(CustomGoogleMap.CONFIG), {
    max_numbered_icons : 5,
    map_center_point_default : new GLatLng(37.0625, -95.677068), // center of the US
    info_window_markup_order : $w('title address phone url directions offers colorists services'),
    info_window_width : 217, // for IE6
    info_window_templates : {
      'title'       : '<div class="Title">#{title}<\/div>',
      'address'     : '<div class="Address">#{address}<\/div>',
      'phone'       : '<div class="Phone">#{phone}<\/div>',
      'url'         : '<div class="Website">#{url}<\/div>',
      'directions'  : '<div class="Directions">#{directions}<\/div>',
      'offers'      : '<div class="Offers">#{offers}<\/div>',
      'services'    : '<ul class="HorizList salon-services">#{services}<\/ul>',
      'colorists'   : '<ul class="HorizList colorists">#{colorists}<\/ul>'
    },
    marker_class_properties : {
      'elite' : {
        icon_img : '/images/icon.map-marker.blue.default.png',
        icon_img_width : 37,
        icon_img_height : 34,
        icon_anchor_x : 18,
        icon_anchor_y : 33,
        icon_win_anchor_x : 28,
        icon_win_anchor_y : 1,
        icon_shadow_img : '/images/icon.map-marker.blue.shadow.png',
        icon_shadow_img_width : 45,
        icon_shadow_img_height : 26
      },
      'regular_c5a' : {
        icon_img : '/images/icon.map-marker.red.default.png',
        icon_img_width : 37,
        icon_img_height : 34,
        icon_anchor_x : 18,
        icon_anchor_y : 33,
        icon_win_anchor_x : 28,
        icon_win_anchor_y : 1,
        icon_shadow_img : '/images/icon.map-marker.red.shadow.png',
        icon_shadow_img_width : 45,
        icon_shadow_img_height : 26
      },
      'regular' : {
        icon_img : '/images/icon.map-marker.black.default.png',
        icon_img_width : 28,
        icon_img_height : 34,
        icon_anchor_x : 13,
        icon_anchor_y : 33,
        icon_win_anchor_x : 13,
        icon_win_anchor_y : 0,
        icon_shadow_img : '/images/icon.map-marker.black.shadow.png',
        icon_shadow_img_width : 40,
        icon_shadow_img_height : 28
      }
    }
  });

/* ------------------------------------------------- END: salon finder -- */
