"use strict";
(function ($) {
$.fn.googleMap = function(address, options) {
    var defaults = {
      lat: 52.0347227,
      long: 4.4976745,
      zoom: 15,
      disableDefaultUI: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

  options = $.extend(defaults, options || {});

  var center = new google.maps.LatLng(options.lat, options.long);
  var map = new google.maps.Map(this.get(0), $.extend(options, { center: center }));

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({ address: address }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
        });
      }
    }
  });
};

// custom css expression for a case-insensitive contains()
jQuery.expr[':'].Contains = function(a,i,m){
    return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

function listFilter(header, list) { // header is any element, list is an unordered list
  // create and add the filter form to the header
  var form = $("<form>").attr({"class":"filterform","action":"#"}),
      input = $("<input>").attr({"class":"filterinput","type":"text"});
  $(form).append(input).appendTo(header);

  $(input)
    .change( function () {
      var filter = $(this).val();
      if(filter) {
        // this finds all links in a list that contain the input,
        // and hide the ones not containing the input while showing the ones that do
        $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
        $(list).find("a:Contains(" + filter + ")").parent().slideDown();
      } else {
        $(list).find("li").slideDown();
      }
      return false;
    })
  .keyup( function () {
      // fire the above change event after every letter
      $(this).change();
  });
}



  $(function () {
    // ONLOAD

    if ($(".secondinfo") ) {
      var height1 = $(".secondinfo").outerHeight(),
          height2 = $("#featured").outerHeight() + 20,
          locheight = height1 - height2;

      if (locheight > 0) {
        $(".locationmap").height(locheight);
      } else {
        $(".locationmap").width(620);
      }
    }

    if ($(".city-list")) {
      listFilter($(".listdesc"), $(".city-list"));
    }

    $("#starwrapper").stars({
      inputType: "select",
      split: 2,
      cancelShow: false,
    });
  });
}(jQuery));


