jQuery.fn.innerGlow = function(o) {
	// src         - path to images; %d replaced with piece number (required)
	// size        - array of t,r,b,l dimensions of images (required, defaults as margin, padding, etc.)
	// offset      - array of t,r,b,l offsets of images (default to size for outer glow, 0 for inner glow)
	
	this.each(function() {
		
		var size = typeof o.size == "array" ? o.size : String(o.size).split(/\s+/);
		if(size.length < 2) size[1] = size[0];
		if(size.length < 3) size[2] = size[0];
		if(size.length < 4) size[3] = size[1];
		
		if(!o.offset) o.offset = 0;
		var offset = typeof o.offset == "array" ? o.offset : String(o.offset).split(/\s+/);
		if(offset.length < 2) offset[1] = offset[0];
		if(offset.length < 3) offset[2] = offset[0];
		if(offset.length < 4) offset[3] = offset[1];
			
		var self = this;
		if(jQuery(this).css('position') != 'absolute' && this != document.body) jQuery(this).css('position', 'relative');
		jQuery(this).children().each(function() {
			if(jQuery(this).css('position') != 'absolute') jQuery(this).css('position', 'relative');
			});
		
		add(2, null, size[0], -offset[0], size[1]-offset[1], null, size[3]-offset[3], 'x');
		add(6, null, size[2], null, size[1]-offset[1], -offset[2], size[3]-offset[3], 'x', 1);
		add(4, size[1], null, size[0]-offset[0], -offset[1], size[2]-offset[2], null, 'y', 1);
		add(8, size[3], null, size[0]-offset[0], null, size[2]-offset[2], -offset[3], 'y');
		
		add(1, size[3], size[0], -offset[0], null, null, -offset[3]);
		add(3, size[1], size[0], -offset[0], -offset[1], null, null);
		add(5, size[1], size[2], null, -offset[1], -offset[2], null);
		add(7, size[3], size[2], null, null, -offset[2], -offset[3]);
		
		function add(num, w, h, t, r, b, l, rep, br) {
			var pos = br ? ' bottom right' : ' top left';
			rep = rep ? 'repeat-'+rep : 'no-repeat';
			var e = jQuery('<div></div>');
			e.css('position', self == document.body ? 'fixed' : 'absolute');
			if(w!==null) e.width(w+'px');
			if(h!==null) e.height(h+'px');
			if(t!==null) e.css('top', t+'px');
			if(r!==null) e.css('right', r+'px');
			if(b!==null) e.css('bottom', b+'px');
			if(l!==null) e.css('left', l+'px');
			// if(zIndex) e.css('zIndex', 0);
			if(jQuery.browser.msie) {
				e.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+o.src.replace(/%d/, num)+"',sizingMethod='scale')");
				}
			else {
				e.css('background', 'url('+o.src.replace(/%d/, num)+') '+rep+pos);
				}
			jQuery(self).prepend(e[0]);
			}
	
		});
	};

jQuery.fn.glow = jQuery.fn.outerGlow = function(o) {
	o = jQuery.extend({ 'offset' : o.size }, o||{});
	this.innerGlow(o);
	};
