(function( $ ){
	$.fn.easePan = function(options){
		
		var $outer_container	= $(this);
		var $contentToPan		= $outer_container.html();
		$outer_container.children().remove();
		
		$outer_container.append('<div class="imagePan"></div>');
		var $imagePan = $(this).find('.imagePan');
		
		$imagePan.append('<div class="container"></div>');
		var $imagePan_container	= $imagePan.find('.container');
		
		$imagePan_container.append($contentToPan);
		var $imagePan_panning	= $imagePan_container.children();
		
		$imagePan.css({
			width:$outer_container.width()+'px',
			height:$outer_container.height()+'px',
			position:'relative',
			overflow:'hidden'
		});
		$imagePan_container.css({
			position:'relative',
			left:0
		});
		
	    $imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
	    var containerWidth		= $imagePan.width();
	    var containerHeight		= $imagePan.height();
	    var totalContentW		= $imagePan_panning.width();
	    var totalContentH		= $imagePan_panning.height();
	    $imagePan_container.css("width",totalContentW).css("height",totalContentH);
	
	    var animateX;
	    if( $imagePan_panning.width() > $outer_container.width() ){
	        animateX = true;
	    }else{
	        animateX = false;
	    }
	
	    var animateY;
	    if( $imagePan_panning.height() > $outer_container.height() ){
	        animateY = true;
	    }else{
	        animateY = false;
	    }
		
		var methods = {
			MouseMove	: function(e){
				var mouseCoordsX=(e.pageX - $imagePan.offset().left);
		        var mouseCoordsY=(e.pageY - $imagePan.offset().top);
		        var mousePercentX=mouseCoordsX/containerWidth;
		        var mousePercentY=mouseCoordsY/containerHeight;
		        var destX=-(((totalContentW-(containerWidth))-containerWidth)*(mousePercentX));
		        var destY=-(((totalContentH-(containerHeight))-containerHeight)*(mousePercentY));
		        var thePosA=mouseCoordsX-destX;
		        var thePosB=destX-mouseCoordsX;
		        var thePosC=mouseCoordsY-destY;
		        var thePosD=destY-mouseCoordsY;
		        var marginL=$imagePan_panning.css("marginLeft").replace("px", "");
		        var marginT=$imagePan_panning.css("marginTop").replace("px", "");
		        var animSpeed=500; //ease amount
		        var easeType="easeOutCirc";
		        if(mouseCoordsX>destX || mouseCoordsY>destY){
		            //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
		            //$imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType); //with easing
		            //animate X & Y
		            if( animateX == true && animateY == true ){
		                $imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType);
		            //animate X
		            }else if( animateX == true && animateY == false ){
		                $imagePan_container.stop().animate({left: -thePosA-marginL}, animSpeed,easeType);
		            //animate Y
		            }else if( animateX == false && animateY == true ){
		                $imagePan_container.stop().animate({top: -thePosC-marginT}, animSpeed,easeType);
		            }
		        } else if(mouseCoordsX<destX || mouseCoordsY<destY){
		            //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
		            //$imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType); //with easing
		            //animate X & Y
		            if( animateX == true && animateY == true ){
		                $imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType);
		            //animate X
		            }else if( animateX == true && animateY == false ){
		                $imagePan_container.stop().animate({left: thePosB-marginL}, animSpeed,easeType);
		            //animate Y
		            }else if( animateX == false && animateY == true ){
		                $imagePan_container.stop().animate({top: thePosD-marginT}, animSpeed,easeType);
		            }
		        } else {
		            $imagePan_container.stop();
		        }
			}
		};
		
		$imagePan.bind("mousemove", function(event){
			methods.MouseMove(event);
		});
		
		/*
		$(window).resize(function() {
		    $imagePan.unbind("mousemove");
		    $imagePan_container.css("top",0).css("left",0);
		    $(window).load();
		});
		*/
		
	};
})(jQuery);
