
;(function( $ ){
	
	var shadowCount = 0;
	
	jQuery.fn.shadow = function(img, size)
	{
		this.prepend('<div class="shadow ' + shadowCount + '" /><div class="shadow ' + (shadowCount + 1) + '" /><div class="shadow ' + (shadowCount + 2) + '" /><div class="shadow ' + (shadowCount + 3) + '" />');
		
		var width = this.width();
		var height = this.height();
		
		
		var leftWidth = Math.floor(width / 2) + 'px';
		var rightWidth = Math.ceil(width / 2) + 'px';
		
		var topHeight = Math.floor(height / 2) + 'px';
		var bottomHeight = Math.ceil(height / 2) + 'px';
		
		var tl = $('.shadow.' + shadowCount);
		var tr = $('.shadow.' + (shadowCount + 1));
		var br = $('.shadow.' + (shadowCount + 2));
		var bl = $('.shadow.' + (shadowCount + 3));
		
		tl.css('position', 'absolute');
		tl.css('left', -size + 'px');
		tl.css('top', -size + 'px');
		tl.css('width', leftWidth);
		tl.css('height', topHeight);
		tl.css('padding-right', size + 'px');
		tl.css('padding-bottom', size + 'px');
		tl.css('background', 'transparent url(' + img + ') 0 0');
		
		tr.css('position', 'absolute');
		tr.css('right', -size + 'px');
		tr.css('top', -size + 'px');
		tr.css('width', rightWidth);
		tr.css('height', topHeight);
		tr.css('padding-left', size + 'px');
		tr.css('padding-bottom', size + 'px');
		tr.css('background', 'transparent url(' + img + ') right 0');
		
		br.css('position', 'absolute');
		br.css('right', -size + 'px');
		br.css('bottom', -size + 'px');
		br.css('width', rightWidth);
		br.css('height', bottomHeight);
		br.css('padding-left', size + 'px');
		br.css('padding-top', size + 'px');
		br.css('background', 'transparent url(' + img + ') right bottom');
		
		bl.css('position', 'absolute');
		bl.css('left', -size + 'px');
		bl.css('bottom', -size + 'px');
		bl.css('width', leftWidth);
		bl.css('height', bottomHeight);
		bl.css('padding-right', size + 'px');
		bl.css('padding-top', size + 'px');
		bl.css('background', 'transparent url(' + img + ') 0 bottom');
				
		shadowCount += 4;
	}

})( jQuery );