(function($)
{
	Array.prototype.contains = function(predicate)
	{
		if (!$.isFunction(predicate))
		{
			return false;
		}
		
		for (var i = 0; i < this.length; i++)
		{
			if (predicate(this[i]))
			{
				return true;
			}
		}
		
		return false;
	};
	
	$.fn.totalWidth = function()
	{
		$this = $(this);
		var width = $this.width();
		width += getPixelCount($this.css('padding-left')) + getPixelCount($this.css('padding-right'));
		width += getPixelCount($this.css('margin-left')) + getPixelCount($this.css('margin-right'));
		width += getPixelCount($this.css('border-left-width')) + getPixelCount($this.css('border-right-width'));
		return width;
	};
	
	$.fn.totalHeight = function()
	{
		$this = $(this);
		var height = $this.height();
		height += getPixelCount($this.css('padding-top')) + getPixelCount($this.css('padding-bottom'));
		height += getPixelCount($this.css('margin-top')) + getPixelCount($this.css('margin-bottom'));
		height += getPixelCount($this.css('border-top-width')) + getPixelCount($this.css('border-bottom-width'));
		return height;
	}
	
	function getPixelCount(string)
	{
		var match = string.match(/(\d+)px/i);
		return match ? parseInt(match[1]) : 0;
	}
	
	// Filters a list of elements to a single element using an index, selector, jQuery object, or DOM element.
	$.fn.dynamicFilter = function(item)
	{
		$this = $(this);
		switch (typeof item)
		{
			case 'number':
				// Get the item at the specified index.
				item = $this.eq(item);
				break;
			case 'string':
				// Get the items matching the given expression.
				item = $this.filter(item);
				break;
			default:
				// Ensure that the item is a jQuery object.
				item = $(item);
				
				// Check that the item is in the given context.
				if ($this.index(item) < 0)
				{
					item = $([]);
				}
				
				break;
		}
		
		// Make sure there's only one being returned.
		return item.first();
	}
})(jQuery);
