; (function($) {
//    $.extend($.expr[':'], {
//        count: function(node, index, argsString, nodeStack) {
//            var args = eval("([" + argsString[3] + "])");
//            return $(node).find();
//        }
//    });

    $.fn.extend({
        clip: function(clipWidth, clipHeight, mode) {

            var clipData = $(this).data("clip.originalSize");
            if (clipData == null) {
                clipData = {
                    width: $(this).width(),
                    height: $(this).height()
                };
                $(this).data("clip.originalSize", clipData);
            }

            var width = clipData.width;
            var height = clipData.height;

            if (clipWidth == null) {
                clipWidth = width;
            }
            if (clipHeight == null) {
                clipHeight = height;
            }
            if (mode == null) {
                mode = "top left";
            }

            var clipHeightMargin = height - clipHeight;
            var clipWidthMargin = width - clipWidth;

            var top = clipHeightMargin / 2;
            var left = clipWidthMargin / 2;

            $.each(mode.split(" "), function(index, element) {
                switch (element) {
                    case "left":
                        left = 0;
                        break;

                    case "right":
                        left = clipWidthMargin;
                        break;

                    case "top":
                        top = 0;
                        break;

                    case "bottom":
                        top = clipHeightMargin;
                        break;
                }
            });

            var bottom = top + clipHeight;
            var right = left + clipWidth;

            var clipRect = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";

            return $(this).css("clip", clipRect);
        },
        clipHeight: function(height) {
            return $(this).clip(null, height);
        },
        clipWidth: function(width) {
            return $(this).clip(width, null);
        }
    });
})(jQuery);
