/*
 * Creates two borders visually around a selected image.
 *
 * The inner border is a newly created div that becomes the immediate parent of the image  
 * and is given a class defined by the 'innerClass' setting (default = 'lds_inner_wrap')
 * 
 * The outer border is a sibling of the selected image and is given a class defined by the
 * 'outerClass' setting (default = 'lds_outer_wrap')
 *
 * The 'topOffset' and 'leftOffset' settings should be equal in value to the border widths
 * of the 'innerClass' style and the direction of the drop shadow can be set by the 
 * 'innerClass' and using positive or negative pixel values. (positive values give a bottom-
 * right drop shadow.
 *
 * Inspired by http://css-tricks.com/absolutely-position-element-within-a-table-cell/
 *
 * Example CSS:
.lds_inner_wrap { 
	z-index:0;
	position: relative;
	border-bottom: 2px solid #FFFFFF;
	border-right: 2px solid #FFFFFF;
}
.lds_outer_wrap {
	border-bottom: 2px solid #C3C3C3;
	border-right: 2px solid #C3C3C3;
	position: absolute;
	z-index:-1;
}
*/
(function( $ ){

    if (!$(this).length) {
        return this;
    }
   
    $.fn.LayeredDropShadow = function( options ) {
		
		var settings = {
			'innerClass'	:	'lds_inner_wrap',
			'outerClass'	:	'lds_outer_wrap',
			'topOffset'		:	'2px',
			'leftOffset'	:	'2px'
		};

		if ( options ) {
			$.extend( settings, options );
		}
		
		var _lds_counter = 0;
       
        return this.each(function() {
            var $this = $(this);
			var height = $(this).height();
			var width = $(this).width();
			// Create [hopefully] unique id...
			var lds_wrap_id = $this.attr('id') + '_' + $this.closest('[id]').attr('id') + '_lds_wrap' + _lds_counter;
			var inner_wrap = $('<div />', {
				'id'		:	lds_wrap_id,
				'height'	:	height,
				'width'		:	width,
				'class'		:	settings.innerClass
			});
			$this.wrap(inner_wrap);
			var outer_wrap = $('<div />', {
				'class'		:	settings.outerClass,
				'height'	:	height,
				'width'		:	width,
				'css'		:	{
					'top'	:	settings.topOffset,
					'left'	:	settings.leftOffset
				}
			});
			$('#' + lds_wrap_id).append(outer_wrap);
			_lds_counter++;
        });
    }
})( jQuery );
