/********************************************************************************************************************

jQuery Plugin "imgSqueeze"

Written by : Adam H. Nelson
Version : 1.0
Date : 8.15.11

Notes: 
This plugin creates a faux-border around an image inside of a hyperlink.  Upon rollover, the border squeezes in toward 
the center of the image. Upon rollout, the border expands back to it's usual position.

Parameters (in order):
1) Pass speed in milliseconds ( default is 500 milliseconds or .5 seconds )
2) Pass the rollover color as hexidecimal string ( default is black/#000000 )
3) Pass the rollout color as hexidecimal string ( default is black/#000000 )
4) Pass the ease of the rollover ( default is 'swing' )
5) Pass the ease of the rollout ( default is 'swing' )
* jQuery has, by default, only one type of easing called "swing." To use anything but 'swing' for easing, you'll need 
to use an easing plugin.

Example usage:
$(document).ready(function() {
	$('a.thumb').imgSqueeze ({
		speed     : 250,
		color_on  : '#fff',
		color_off : '#020202',
		ease_on   : 'easeOutQuad',
		ease_off  : 'easeInQuad'
	});
});

********************************************************************************************************************/

(function($) {
		  
	$.fn.imgSqueeze = function( options ) {
		
		var settings = {
			speed     : 250,
			color_on  : '#000',
			color_off : '#000',
			ease_on   : 'swing',
			ease_off  : 'swing'
		};
		
		var options = $.extend( settings, options ); 
		
		return this.each(function() {
			
			$(this).append('<span class="border"></span>');
			
			var hyperlink = this;
			var border = $('span.border', this);
			
			$('img', this).load(function() {
				
				var width = $(this).width();
				var height = $(this).height();
				
				$(this).css('display', 'block');
				
				$(border)
					.css({
						'position' : 'absolute',
						'border'   : '10px solid '+options.color_off,
						'width'    : width - 4,
						'height'   : height - 4,
						'left'     : '-8px',
						'top'      : '-8px'
					});
				
				$(hyperlink)
					.css({
						'width'    : width,
						'height'   : height,
						'display'  : 'block',
						'overflow' : 'hidden',
						'position' : 'relative'
					})
					.hover(function() {
						$(border).css({
							'border-color' : options.color_on
						}).stop(true,false).animate({
							'width'  : width - 20,
							'height' : height - 20,
							'left'   : 0,
							'top'    : 0
						}, options.speed, options.ease_on);
					})
					.mouseout(function() {
						$(border).stop(true,false).animate({
							'width'  : width - 4,
							'height' : height - 4,
							'left'   : '-8px',
							'top'    : '-8px'
						}, options.speed, options.ease_off, function() {
							$(this).css({
								'border-color' : options.color_off
							})
						});
					});
				
			});
		});
	};
})(jQuery);
