/**
 * @fileOverview All JS-code for kch.nl
 * @author name
 * @since 1.0 - 2010-8-6
 * @version 1.0 - 2010-23-11
 */




if (typeof (nl) == "undefined") {
  /**
   * @namespace Top Level kch
   */
  var nl = {}
}
if (typeof(nl.kch) == "undefined") {
  /**
   * @namespace kch name
   */
  nl.kch = {}
}



nl.kch.sitecore = (function() {
  /* START PUBLIC */
  return {
    DetectMode: function(selector) {
      if (document.location.href.indexOf('sc_mode=edit') > 0) {
        jQuery('body').addClass('sc_ModeEdit');
      }
    }
  }
  /* END PUBLIC */
})();



nl.kch.Accordion = (function() {
  /* START PUBLIC */
  return {
    Init: function(selector) {
      // Set list
      jQuery(selector + " dt").addClass("a");
      jQuery(selector + " dd").hide();
      jQuery(selector + " dd:first").slideDown(600)
      jQuery(selector + " dt:first").addClass("active")

      // Set click event
      jQuery(selector + " dt").click(function() {
        jQuery(this).parent().find("> dt").removeClass("active");
        jQuery(this).addClass("active");
        if (jQuery(this).next("dd").is(":hidden")) {
          jQuery(this).parent().find("> dd:visible").slideUp(400);
          jQuery(this).next("dd").slideDown(600);
        }
      })
      
      jQuery('#closeButton').click(function() {
        jQuery(this).css('display', 'none');
        jQuery(this).parent().find('span.open').css('display', 'block');
        jQuery(selector + " dt.active").parent().find("> dd:visible").slideUp(400);
        jQuery(selector + " dt.active").removeClass("active");
      })
      
      jQuery('#openButton').click(function() {
        jQuery(this).css('display', 'none');
        jQuery(this).parent().find('span.close').css('display', 'block');
        jQuery(selector + " dd:first").slideDown(600)
        jQuery(selector + " dt:first").addClass("active")
      })
    }
  }
  /* END PUBLIC */
})();



nl.kch.MainMenuCtrl = (function() {
    /* START PUBLIC */
    return {
        Init: function(selector) {
            var containerMain = jQuery('div.containerMain:first');
            var containerMainRight = Math.round(containerMain.offset().left + containerMain.outerWidth());

            jQuery(selector + " li.level1").each(function() {
                var dropdownBox = jQuery(this).find('div.dropdownContainer');
                if (dropdownBox.length) {
                    // Set up columns
                    jQuery(this).addClass('containsDropdown')
                    var subColumns = dropdownBox.find("ul.level2 li.level2").length;
                    dropdownBox.find("ul.level2").css('width', (subColumns * 180));

                    // Nudge drop down menus to the left if needed.
                    dropdownBox.attr('style', 'display: block');
                    var dropdownBoxRight = Math.round(dropdownBox.offset().left + dropdownBox.innerWidth());
                    dropdownBox.attr('style', '');

                    if ((dropdownBoxRight + 10) > containerMainRight) {
                        dropdownBox.css('margin-left', -(dropdownBoxRight - containerMainRight + 48) + 'px');
                    }
                }
            })
        }
    }
    /* END PUBLIC */
})();



nl.kch.watermark = (function() {
  /* START PUBLIC */
  return {
    Run: function() {
      jQuery('div.watermark').each(function() {
        Estate.Forms.Watermark.Init(jQuery(this).find('textarea'), jQuery(this).find('label').html());
      })
    }
  }
  /* END PUBLIC */
})();



nl.kch.searchCtrl = (function() {
    function dropDown(el) {
        var dropdown = jQuery(el);
        
        if(typeof(dropdown[0]) == "undefined") {
			return
        }
        
        if (dropdown[0].tagName.toLowerCase() != "select") {
        } else {
            dropdown.hide();
            dropdown.addClass("init");

            var matOptions = dropdown[0].options;
            var selIndex = dropdown[0].selectedIndex;
            if (selIndex == -1) return;
            var list = "";
            list += "<li class='selected'><a href='#'>" + matOptions[selIndex].innerHTML + "</a></li>";

            for (var i = 0; i < matOptions.length; i++) {
                var item = matOptions[i];
                var active = (i == selIndex) ? "active highlight" : "";
                var last = (i == (matOptions.length - 1)) ? "lastItem" : "";
                list += "<li class='option " + active + " " + last + "'><a href='#'>" + item.innerHTML + "</a></li>";
            }

            dropdown.after("<ul class='filterList'>" + list + "</ul>");

            // IE6 hover fix for styling of hovering over non A-elements
            dropdown.next('ul.filterList').find('li.selected').click(function(e) {
                jQuery("ul.filterList").toggleClass("open");
                e.stopPropagation();
            }).siblings('li').hover(
        function() {
            if (jQuery(this).hasClass('option')) {
                jQuery(this).siblings('.option').removeClass('highlight');
                jQuery(this).addClass('highlight');
            }
        },
        function() {
            jQuery(this).removeClass('highlight').siblings().removeClass('highlight');
            jQuery(this).parent().find('.active').addClass('highlight');
        }
      );

            // Hide open dropdowns when clicked outside the dropdown
            jQuery("body").click(function() {
                jQuery("ul.filterList").removeClass("open");
            });

            // Add click event to styled dropdown options
            dropdown.next('ul').find('li.option').click(function() {
                jQuery(this).siblings().removeClass("active");
                jQuery(this).addClass("active");
                var index = jQuery(this).index() - 1; // -1 because there is a dummy li item which takes index[0]
                dropdown[0].selectedIndex = index;
                dropdown[0].options[index].selected = true;
                jQuery(dropdown[0]).change();
                jQuery(this).siblings(".selected").find("a").text(jQuery(this).text());
                jQuery("ul.filterList").removeClass("open");
                getResults();
            });
        }
    }

    function activeFocus(el) {
        box = jQuery(el);
        box.click(function(e) {
            jQuery(this).addClass("active");
            e.stopPropagation();
        });
        jQuery('body').click(function() {
            box.removeClass("active");
            jQuery('div.autoCompleteContainer').hide();
        });
    }

    function autoComplete(el) {
        input = jQuery(el);
        var val = '';
        var oldVal = '';

        input.keyup(function() {
            val = input.val();
            if (val != oldVal && val.length > 0) {
                getResults();
            }
            oldVal = val;
        });
    }

    function getResults() {
        // Implement AJAX function here
        // URL to call: /components/forward%20search/kch_autocomplete.ashx
        // Keyword: get from input.searchInput value
        // Language: get from cookie 'kch#lang'
        // Category: get from select.categories selectedIndex value
        var url = '/components/forward%20search/kch_autocomplete.ashx';
        var keyword = jQuery('input.searchInput').val();
        var lang = getCookie("kch#lang") || "nl"; // Default nl value
        var cat = jQuery('select.categories').val();
        var data = {
            'keyword': keyword,
            'language': lang,
            'category': cat
        }

        jQuery.ajax({
            'url': url,
            'data': data,
            'success': function(data) {
                showResults(data);
            },
            'error': function(data) {
                var container = jQuery('div.autoCompleteContainer');
                var inner = container.find('div.results');
                inner.empty().append('<p class="error">Error: ' + data.status + ' ' + data.statusText + '</p>');
                container.show();
            }
        });

    }

    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }

    function showResults(result) {

        var resultContainer = jQuery('div.autoCompleteContainer');
        var resultInner = resultContainer.find('div.results');
        resultInner.empty();

        selectedCat = jQuery('div.searchBox select.categories')[0].selectedIndex;
        arrayLength = result.res.length;

        resultInner.append('<ul class="autoCompleteList level1"/>')
        var resultList = jQuery('ul.autoCompleteList');
        if (selectedCat == 0 && arrayLength > 0) {
            // Bouw ul's met categorieen op
            for (var i = 0; i < arrayLength; i++) {
                var catResults = result.res[i].ws;
                var category = '';

                // Begin category
                category += '<li class="level1 category">';

                // Category Title
                category += '<div class="title">';
                category += '<a href="' + result.res[i].u + '">';
                category += result.res[i].cat
                category += '</a>';
                category += '</div>';

                // Begin category list
                category += '<ul class="level2">'

                // Category items
                for (var ii = 0; ii < catResults.length; ii++) {
                    category += '<li class="level2 result">';
                    category += '<a href="' + catResults[ii].u + '">';
                    category += catResults[ii].t;
                    category += '</a>';
                    category += '</li>';
                }

                // End category list
                category += '</ul>';

                // End category
                category += '</li>';

                resultList.append(category)
            }
        } else if (arrayLength == 1) {
            // Bouw ul zonder categorieen
            var category = '';

            // Begin result items
            for (var i = 0; i < result.res[0].ws.length; i++) {
                category += '<li class="level1 result">';
                category += '<a href="' + result.res[0].ws[i].u + '">';
                category += result.res[0].ws[i].t;
                category += '</a>';
                category += '</li>';
            }

            resultList.append(category)
        } else if (arrayLength == 0) {
            if (result.msg) {
                var container = jQuery('div.autoCompleteContainer');
                var inner = container.find('div.results');
                inner.empty().append('<p class="msg">' + result.msg + '</p>');
                container.show();
            }
        }

        resultContainer.show();
    }

    /* START PUBLIC */
    return {
        Init: function(el) {
            selector = jQuery(el);

            activeFocus(selector);

            var dropdown = selector.find("select.categories")
            dropDown(dropdown);

            var input = selector.find("input.searchInput");
            autoComplete(input);
        }
    }
    /* END PUBLIC */
})();



nl.kch.splitList = (function() {
  
  /* Start public */
  return {

    /**
     * Boiler plate public method
     * @example
     * nl.plcdirect.namespace.PublicMethod()
     */
    Init: function(groupList) {
      jQuery(groupList).each(function(index) {
        var ul = jQuery(this);
        var totalGroups = ul.find("> li").size();
        var rowTotal = Math.ceil(totalGroups/2);
        //var list = jQuery(groupList);
        var currItemNr = 0;
        
        ul.addClass("col2List col2ListFirst");  
        
        ul.children().each(function() {
          if (++currItemNr > rowTotal) {
            var new_list = jQuery("<ul class='listBlock col2List'></ul>").insertAfter(ul);
            ul = new_list;
            currItemNr = 1;
          }
          ul.append(this);
        });
      
        
      });
    }
  }
  /* End public */
  
})();



nl.kch.ambassadeurBar = (function() {
  /* START PUBLIC */
  return {
    Init: function(barSelector) {
      jQuery(barSelector).each(function() {
        
        var currBar = jQuery(this);
        
        jQuery(barSelector + ' li:first-child').addClass('active');
        var photoNr = 0;
        
        currBar.children().each(function() {
          var currItem = jQuery(this);
          currItem.find('div.photoBox').css('margin-left', photoNr*60);
          currItem.find('div.quoteBox div.arrow').css('margin-left', photoNr*60);
          currItem.find('div.photoBox').mouseover(function() {
            jQuery(this).closest('ul').find('li.active').removeClass('active');
            jQuery(this).closest('li').addClass('active');
          })
          
          photoNr++;
        
        });
      });
    }
  }
  /* END PUBLIC */
})();

nl.kch.ambassadeurTweet = (function() {
  /* START PUBLIC */
  return {
    Init: function(spanSelector) {
      jQuery(spanSelector).each(function() {
        var item = jQuery(this);
                var dataUser = item.attr('data-user') || '';
                var dataTag = item.attr('data-tag') || '';
                if (dataUser != '') {
          item.text('');
                    if (dataTag != '') {
                        item.tweet({
                            avatar_size: 32,
                            count: 1,
                            query: "#" + dataTag  + " from:" + dataUser,
                            template: "{text}"
                        })
                    }
                    else {
                        item.tweet({
                            avatar_size: 32,
                            count: 1,
                            username: dataUser,
                            template: "{text}"
                        })                    
                    }
                }
      });
    }
  }
  /* END PUBLIC */
})();






nl.kch.alphabetMenu = (function() {
  /* START PUBLIC */
  return {
    Init: function(alphabetList) {
    
      jQuery(alphabetList + ' li:first-child').addClass('active');
      
      jQuery(alphabetList + " li").not('.inActive').each(function() {
        var currItem = jQuery(this);
        currItem.click(function() {
          jQuery(this).closest('ul').find('li.active').removeClass('active');
          jQuery(this).closest('li').addClass('active');
        })
      });
    }
  }
  /* END PUBLIC */
})();



nl.kch.filterCheckList = (function() {
  var dates = '[data-attribute="data-year"], [data-attribute="data-month"]';
  var filteredList;
  var animationSpeed = 500;
  var filterListsRoot;
  var filter;
  
  
  
  // Add class on filter option if active
  function setCheckedClass(el) {
    if (el.attr("checked")) {
      el.closest('li').addClass('selected');
    } else {
      el.closest('li').removeClass('selected');
    }
  }
  
  // When hovering over a filter option this function will grey out elements
  // that will be removed after a click
  function filterPreview(dataKey, dataValue) {
    /*if (dataKey == 'data-date') {
      if (filterListsRoot.find(':checked[data-attribute="data-date"]').size() > 0) {
        return
      }
    }*/
    
    if (filterListsRoot.find(':checked:checkbox[data-attribute="' + dataKey + '"]').size() == 0) {
      if (typeof(dataKey) == 'string' && typeof(dataValue) == 'string') {
        var selectorString = nl.kch.filterCheckList.query.DomQuery(dataKey, dataValue);
        var filteredList = filter.getFilteredList();
        var hideItems = filteredList.find('ul.content > li:visible').not(selectorString);
        hideItems.stop(true, false);
        hideItems.animate(
          {
            opacity: '0.5'
          },
          {
            duration: animationSpeed / 3
          }
        )
      } else {
        var showItems = filter.getFilteredList().find('ul.content > li:visible')
        showItems.stop(true, false);
        showItems.animate(
          {
            opacity: '1'
          },
          {
            duration: animationSpeed
          }
        )
      }
    }
  }
    
  
  
  /* START PUBLIC */
  return {
    /**
     * Inits filter and filtered list
     */
    Init: function(filterList, arg_filteredList) {
      // Show filter block
      filterListsRoot = jQuery(jQuery(filterList)[0]).closest('div.js_contentFilter');
      filterListsRoot.removeClass('noJS')

      filter = new nl.kch.filterCheckList.filter(filterListsRoot, animationSpeed, jQuery(arg_filteredList));
      filter.init();
      
      // Set up filter list
      jQuery(filterList).find("> li").each(function() {
        var listItem = jQuery(this);
        var checkBox = listItem.find(':checkbox');
        
        // Show/hide items on mouse hover over list options
        listItem.bind('mouseenter', function() {
          var item = jQuery(this).find(':checkbox')
          var dataKey = item.attr('data-attribute');
          var dataValue = item.val();
          if (item.attr('data-attribute') == 'data-year') {
            if (filterListsRoot.find(':checked:checkbox[data-attribute="data-year"]').size() > 0) {
              return;
            }
          }
          if (item.attr('data-attribute') == 'data-month') {
            if (filterListsRoot.find(':checked:checkbox[data-attribute="data-month"]').size() > 0) {
              return;
            }
          }
          
          filterPreview(dataKey, dataValue);
        });
        listItem.bind('mouseleave', function() {
          filterPreview();
        }); 
                
        // Run events when filter is clicked
        setCheckedClass(checkBox);
        checkBox.click(function() {
          filter.run();
          setCheckedClass(jQuery(this));
        });
      });
    },
    
    /**
     * Clear filter form
     */
    Clear: function(filterList) {
      jQuery(filterList).find(":checkbox:checked").each(function() {
        var currCheckBox = jQuery(this);
        currCheckBox.attr('checked', false);
        currCheckBox.closest('li').removeClass('selected');
      });
      filter.run();
    }
  }
  /* END PUBLIC */
})();






/**
 * Contains static methods for building queries
 */
nl.kch.filterCheckList.query = (function() {
  return {
    /**
     * Builds DOM selector based on the data key and data value of filter item.
     */
    DomQuery: function(dataKey, dataValue) {
      return '[' + dataKey + '*="[' + dataValue + ']"]';
    },
    
    /**
     * Builds get query
     */
    GetQuery: function(arg_dataKey, dataValue) {
      var dataKey = arg_dataKey;
      var dataKey = dataKey.replace('data-', '');
      return '&' + dataKey + '=' + dataValue;
    }
  }
})();






/**
 * Creates filtered search result
 */
nl.kch.filterCheckList.filter = function(arg_filterListsRoot, arg_animationSpeed, arg_filteredList) {
  var datasource = 'dom';
  if (arg_filteredList.hasClass('js_filteredListAjax') > 0) {
    datasource = 'ajax';
  }
  var oFilteredList = new nl.kch.filterCheckList.filteredList(datasource, arg_filteredList, arg_filterListsRoot, arg_animationSpeed);
  var filterListsRoot = arg_filterListsRoot;
  var animationSpeed = arg_animationSpeed;
  var filteredList;
  
  
  // Removes current filtered list (if any) and then runs filter
  function resetList() {
    if (typeof(filteredList) != "undefined") {
      filteredList.fadeOut(
        animationSpeed / 2,
        function() {
          oFilteredList.clearList(runFilter);
        }
      );
    } else {
      runFilter();
    }
  }
  
  // Creates new filtered list
  function runFilter(init) {
    var items_per_page = 6;
    var show_first_last = false;
    var selectorString = '';
    
    // Create new list
    filteredList = oFilteredList.buildList(init);

    // Show message if no results were found    
    if (filteredList.find('ul.content > li').size() == 0) {
      filteredList.html('Er zijn geen resultaten gevonden')
    }
    
    // Create paging if needed
    if (datasource == 'dom') {
      if(!filteredList.hasClass('noPage')) {
        if (filteredList.find('ul.content > li').size() > items_per_page) {
          if ((filteredList.find('ul.content > li').size() / items_per_page) > 20) {
            show_first_last = true;
          }
          filteredList.pajinate(
            {
              items_per_page: items_per_page,
              nav_label_first: '‹‹',
              nav_label_last: '››',
              show_first_last: show_first_last,
              num_page_links_to_display: 10
            }
          );
        }
      }
    }
    
      
    
    // Show new list
    filteredList.fadeIn(animationSpeed / 2);
  }

  
  this.init = function() {
    oFilteredList.clearList(function() { runFilter(true) });
    return filteredList;
  }

  this.run = function() {
    resetList();
    return filteredList;
  }

  this.getFilteredList = function() {
    return oFilteredList.getList();
  }
}






nl.kch.filterCheckList.filteredList = function(arg_datasource, arg_filteredList, arg_filterListsRoot, arg_animationSpeed) {
  var animationSpeed = arg_animationSpeed;
  var dates = '[data-attribute="data-year"], [data-attribute="data-month"]';
  var filteredList = arg_filteredList;
  var filterListsRoot = arg_filterListsRoot;
  var datasource = arg_datasource;
  var selectorString;
  var selectedCats;
  var previousDataKey;
  var filteredItems;
  var matchQuery;
  if (datasource == 'dom') {
    var filteredListSource = arg_filteredList;
    var filteredListSourceClone = filteredListSource.clone(true);
    filteredListSource.addClass('source');
  }
  
  // Show only selected items
  function domFilter(arg_filteredList) {
    if (filterListsRoot.find(':checkbox:checked').not(dates).size()) {
      selectorString = '';
      selectedCats = 0;
      previousDataKey = '';
      filteredItems = jQuery([]);
      matchQuery = '';
      var size = filterListsRoot.find(':checkbox:checked').not(dates).size();
      arg_filteredList.find('ul.content > li').attr('data-matchLevel', '')
      filterListsRoot.find(':checkbox:checked').not(dates).each(function(index) {
        var item = jQuery(this);
        var dataKey = item.attr('data-attribute');
        var dataValue = item.val();
        if (previousDataKey == dataKey) {
          if (selectorString != '') {
            selectorString += ', '
          }
        }
        
        selectorString += nl.kch.filterCheckList.query.DomQuery(dataKey, dataValue);

        if (previousDataKey != dataKey || size == (index+1)) {
          filteredItems = arg_filteredList.find('ul.content > li').filter(selectorString);
          matchQuery += '[data-matchLevel*="' + dataKey + '"]';
          filteredItems.attr('data-matchLevel', filteredItems.attr('data-matchLevel') + '[' + dataKey + ']')
        }

        previousDataKey = dataKey;
      });
      var showItems = arg_filteredList.find('ul.content > li').not(matchQuery);
      showItems.remove();
    }
    /* ES_TODO: zijn er nog plekken waar data voorkomt?
    if (filterListsRoot.find(':checkbox:checked').filter(dates).size()) {
      selectorString = '';
      filterListsRoot.find(':checkbox:checked').filter(dates).each(function() {
        var item = jQuery(this);
        var dataKey = item.attr('data-attribute');
        var dataValue = item.val();
        if (selectorString != '') {
          selectorString += ',';
        }
        selectorString += nl.kch.filterCheckList.query.DomQuery(dataKey, dataValue);
      });
      var showItems = arg_filteredList.find('ul.content > li').not(selectorString);
      showItems.remove();
    }
    */
  }
  
  function getFilter() {
    var getQuery = '';
    var previousKey = '';
    var dataKey = '';
    var dataValue = '';
    var checkedSize = 0;
    
    if (filterListsRoot.find(':checkbox:checked').size()) {
      checkedSize = filterListsRoot.find(':checkbox:checked').size();
      filterListsRoot.find(':checkbox:checked').each(function(index) {
        var item = jQuery(this);

        dataKey = item.attr('data-attribute');

        if (previousKey != dataKey && previousKey != '') {
          getQuery += nl.kch.filterCheckList.query.GetQuery(previousKey, dataValue);
        }

        if (previousKey == dataKey) {
          dataValue += ',' + encodeURIComponent(item.val());;
        } else {
          dataValue = encodeURIComponent(item.val());
        }
        
        previousKey = dataKey;

        if (previousKey == dataKey && checkedSize == (index+1)) {
          getQuery += nl.kch.filterCheckList.query.GetQuery(dataKey, dataValue);
        }
      });
    }
    /*
    if (filterListsRoot.find(':checkbox:checked').filter(dates).size()) {
      filterListsRoot.find(':checkbox:checked').filter(dates).each(function() {
        var item = jQuery(this);
        var dataKey = item.attr('data-attribute');
        var dataValue = item.val();
        if (getQuery != '') {
          getQuery += ',';
        }
        getQuery += nl.kch.filterCheckList.query.GetQuery(dataKey, dataValue);
      });
    }*/
    
    return getQuery;
  }
  
  function setEventsPagerAjax(callback) {
    filteredList.find('div.pager a').click(function(event) {
      event.stopPropagation();
      event.preventDefault();
      var page = Estate.StringTools.GetQueryString('pagina', jQuery(this).attr('href'));
      page = 'pagina=' + page;
      if (page.indexOf('javascript:') == -1) {
        filteredList.fadeOut(
          animationSpeed / 2,
          function() {
            _clearList(callback, page);
          }
        );
      }
    });
  }
  
  function _clearList(callback, page) {
    if (datasource == 'dom') {
      callback();
    } else {
      filteredList.html('Ophalen data...');
      
      var url = document.location.href + '?aoc=1' + getFilter();
      if (page) {
        url += '&' + page;
      }
      
      jQuery.ajax({
        url: url,
        success: function( html ) {
          filteredList.html(jQuery(html).find('div.js_filteredListAjax').html());
          setEventsPagerAjax(callback);
          callback();
        }
      });
    }
  }

  this.getList = function() {
    if (datasource == 'dom') {
      return filteredListSource.next();
    } else {
      return filteredList;
    }
  }
  
  this.clearList = function(callback) {
    _clearList(callback)
  }
  
  this.buildList = function(init) {
    if (datasource == 'dom') {
      filteredListSource.after(filteredListSourceClone.clone(true));
      filteredListSource.addClass('source');
      filteredListSource.hide();
      domFilter(filteredListSource.next());
      filteredListSource.parent().find('div.js_filteredList:hidden').not('.source').remove();
      return filteredListSource.next();
    } else {
      return filteredList;
    }
  }
}






nl.kch.addPrivacyLink = (function() {
  /* START PUBLIC */
  return {
    Init: function(targetSpan, link) {
        jQuery(targetSpan).append('<span class="privacyLink"><a href="'+link+'" class="meerInfo">Privacy</a></span>');
    }
  }
  /* END PUBLIC */
})();






nl.kch.gmap = (function() {
  /* START PUBLIC */
  return {
    Init: function() {
      jQuery(window).load(function() {
        jQuery('div.map').each(function() {
          var mapBlock = jQuery(this).closest('*.mapBlock');
          mapBlock.find(':input, :submit').focus(function() {
              jQuery(this).closest('span.controls').addClass('active');
          });
          mapBlock.find(':input, :submit').blur(function() {
              jQuery(this).closest('span.controls').removeClass('active');
          });
          var gmap = new Estate.gmap3();
          var configLat = jQuery(this).attr('data-lat');
          var configLong = jQuery(this).attr('data-lon');
          gmap.init(
            jQuery(this)[0],
            {
              mapOptions:
              {
                  center: new google.maps.LatLng(configLat, configLong),
                  zoom: 15
              },
              autoWrapMarkers: false
            },
            {
              points:
              [
                { lat: configLat, lng: configLong, markerOptions: {}, infoWIndow: {} }
              ]
            },
            {
              directionsPaneld: mapBlock.find('span.directions_result')[0],
              origin: mapBlock.find('input.direction_origin')[0],
              destination: mapBlock.find('input.direction_destination')[0],
              travelMode: google.maps.DirectionsTravelMode.DRIVING,
              submit: mapBlock.find('input.direction_submit')[0]
            }
          );
        });
      });
    }
  }
  /* END PUBLIC */
})();




jQuery(document).ready(function() {
    if (! ("placeholder" in document.createElement("input"))) {
        jQuery('*[placeholder]').each(function() {
            $this = jQuery(this);
            var placeholder = jQuery(this).attr('placeholder');
            if (jQuery(this).val() === '') {
                $this.val(placeholder);
            }
            $this.bind('focus',
            function() {
                if (jQuery(this).val() === placeholder) {
                    this.plchldr = placeholder;
                    jQuery(this).val('');
                }
            });
            $this.bind('blur',
            function() {
                if (jQuery(this).val() === '' && jQuery(this).val() !== this.plchldr) {
                    jQuery(this).val(this.plchldr);
                }
            });
        });
        jQuery('form#new_mail').bind('submit',
        function() {
            jQuery(this).find('*[placeholder]').each(function() {
                if (jQuery(this).val() === jQuery(this).attr('placeholder')) {
                    jQuery(this).val('');
                }
            });
        });
    }
});




nl.kch.data = {};
