(function ($) {
	$.fn.insetBorder = function (options) {
		if ((options != undefined) && (options.inset != undefined)) {
			if (options.insetleft == undefined) {
				options.insetleft = options.inset
			}
			if (options.insetright == undefined) {
				options.insetright = options.inset
			}
			if (options.insettop == undefined) {
				options.insettop = options.inset
			}
			if (options.insetbottom == undefined) {
				options.insetbottom = options.inset
			}
		}
		options = $.extend({
			speed: 250,
			insetleft: 10,
			insetright: 10,
			insettop: 10,
			insetbottom: 10,
			borderColor: '#1aace8',
			borderType: "solid",
			outerClass: "ibe_outer",
			innerClass: "ibe_inner"
		},
		options);
		return this.each(function (i) {
			var $el = $(this),
			ibe_height = $el.outerHeight() + 18,
			ibe_width = $el.outerWidth() + 18;
			var wrapper = $("<div />", {
				"class": options.outerClass,
				"css": {
					"width": ibe_width,
					"height": ibe_height,
					"padding-top": 9,
					"position": "relative",
				},
				"mouseenter": function () {
					$el.next().css({
						"visibility": "visible",
					}).animate({
						"top": 0,
						"left": 0,
						"height": (ibe_height - (options.insettop + options.insetbottom)) + "px",
						"width": (ibe_width - (options.insetleft + options.insetright)) + "px",
						"opacity": 0.9
					},
					{
						"duration": options.speed,
						"queue": false
					})
				},
				"mouseleave": function () {
					$el.next().animate({
						"top": "-" + options.insettop + "px",
						"left": "-" + options.insetleft + "px",
						"height": ibe_height,
						"width": ibe_width,
						"opacity": 0
					},
					{
						"duration": options.speed,
						"queue": false,
						"complete": function () {
							$el.next().css("visibility", "hidden")
						}
					})
				}
			}),
			after = $("<div />", {
				"class": options.innerClass,
				"css": {
					"height": (ibe_height - (options.insettop + options.insetbottom)) + "px",
					"width": (ibe_width - (options.insetleft + options.insetright)) + "px",
					"border-left": options.insetleft + "px " + options.borderType + " " + options.borderColor,
					"border-right": options.insetright + "px " + options.borderType + " " + options.borderColor,
					"border-top": options.insettop + "px " + options.borderType + " " + options.borderColor,
					"border-bottom": options.insetbottom + "px " + options.borderType + " " + options.borderColor,
					"position": "absolute",
					"top": 0,
					"opacity": 0,
					"left": 0
				}
			});
			$el.wrap(wrapper).after(after)
		})
	}
})(jQuery);
