(function($){
  $.extend({
    isBoolean: function(variable){
      return typeof variable == 'boolean';
    },
    
    isBool: function(variable){
      return $.isBoolean(variable);
    },

    isNumber: function(variable){
      return typeof variable == 'number';
    },

    isString: function(variable){
      return typeof variable == 'string';
    },

    isObject: function(variable){
      return typeof variable == 'object';
    },

    isUndefined: function(variable){
      return typeof variable == 'undefined';
    },

    isSet: function(variable){
      return ! $.isUndefined(variable) && variable != null;
    },

    isEmpty: function(variable){
      return ! $.isSet(variable) || ! variable;
    },
    
    isJQuery: function(variable){
      return $.isSet(variable) && $.isSet(variable.jquery);
    },

    /**
     * Escape string for usage in regular expression.
     * @param string str
     * @return string
     */  
    regExpEscape: function(str){
      var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
      return str.replace(specials, "\\$&");
    }
  })
  
  /**
   * Get elements maximal z-index.
   * Maximal z-index is maximum of z-indexes of element and it's parents
   * @param object elem
   * @return integer
   **/
  $.fn.elemZIndex = function (elem){
    var zIndex = parseInt($(this).css('z-index'));
    zIndex = isNaN(zIndex) ? 0 : zIndex;
    $(this).parents().each(function(){
      var parentZIndex = parseInt($(this).css('z-index'));
      if( ! isNaN(parentZIndex) && parentZIndex > zIndex) {
        zIndex = parentZIndex;
      }
    });
    return zIndex;
  }
})(jQuery);
