var $ = require('jQuery');
var onReady = require('kwf/on-ready');
var gmapLoader = require('kwf/google-map/loader');
var gmapMap = require('kwf/google-map/map');



var renderedMaps = [];

var renderMap = function(map) {
    if ($.inArray(map, renderedMaps) != -1) return;
    renderedMaps.push(map);

    var cfg = map.find(".options", true);
    if (!cfg.length) return;
    cfg = $.parseJSON(cfg.val());

    var text = map.find("div.text");
    cfg.mapContainer = map;
    if (!cfg.markers) {
        cfg.markers = {
            longitude : cfg.longitude,
            latitude  : cfg.latitude,
            autoOpenInfoWindow: cfg.autoOpenInfoWindow
        };
        if (text.length) cfg.markers.infoHtml = text.html();
    }

    var cls = eval(cfg.mapClass) || gmapMap;
    var myMap = new cls(cfg);
    map.map = myMap;

    gmapLoader(function() {
        this.show();
    }, myMap);

    return myMap;
};

onReady.onRender('.kwcClass', function(map) {
    if (!map.get('gmapObject') && !map.is(':hidden')) {
        map.data('gmapObject', renderMap(map));
    }
}, { checkVisibility: true });

onReady.onRender('.kwcClass', function (el) {
    var mobileOverlayOpen = el.find('.mobileOverlayOpen');
    var mobileOverlayClose = el.find('.mobileOverlayClose');

    mobileOverlayOpen.click(function (ev) {
        if ($(this).is(':visible')) {
            var newEl = $(this).parent();
            newEl.addClass('navigate');
            $('html, body').animate({
                scrollTop: newEl.offset().top
            }, 400, function() {
                google.maps.event.trigger(newEl.data('gmapObject').gmap, 'resize');
            });
        }
    });

    mobileOverlayClose.on('touchstart click', function (ev) {
        if ($(this).is(':visible')) {
            var newEl = $(this).parent();
            newEl.removeClass('navigate');
            $('html, body').animate({
                scrollTop: newEl.offset().top - (($(window).innerHeight() - newEl.height()) / 2)
            });
        }
    });
});

@@ -156,18 +156,16 @@
 map');%0A%0A
-%0A%0A
 var rend
@@ -197,35 +197,34 @@
 rMap = function(
-map
+el
 ) %7B%0A    if ($.in
@@ -229,19 +229,18 @@
 inArray(
-map
+el
 , render
@@ -284,19 +284,18 @@
 ps.push(
-map
+el
 );%0A%0A    
@@ -304,19 +304,18 @@
 r cfg = 
-map
+el
 .find(%22.
@@ -410,19 +410,18 @@
  text = 
-map
+el
 .find(%22d
@@ -454,19 +454,18 @@
 ainer = 
-map
+el
 ;%0A    if
@@ -796,19 +796,18 @@
 g);%0A    
-map
+el
 .map = m
@@ -939,19 +939,18 @@
 unction(
-map
+el
 ) %7B%0A    
@@ -954,19 +954,18 @@
    if (!
-map
+el
 .get('gm
@@ -979,19 +979,18 @@
 t') && !
-map
+el
 .is(':hi
@@ -1007,19 +1007,18 @@
         
-map
+el
 .data('g
@@ -1039,19 +1039,18 @@
 nderMap(
-map
+el
 ));%0A    

Rename map to el to make clear what it is