//NuvuZoom - 2011 - A jQuery Plugin. NRC Studios - http://nuvuzoom.nrcstudios.info written by: Nolan R Campbell - nuvuscripts@gmail.com
(function($){
       $.fn.nuvuzoom = function( options ) {
         //default options
		options = $.extend({
             magnifier : 2,
             outSpeed: 500,
             easing: 'swing',
             grow: 'false',
             growPercent: 1.5,
             growSpeed: 2000,
		}, options);
     //return each targeted div
    return this.each(function() {
       var $this = $(this);
        var o = $.metadata ? $.extend({}, options, $this.metadata()) : options;
        var dh = $this.height();
        var dw = $this.width();
        var origl = $this.find('img').position().left;
        var origt = $this.find('img').position().top;
     //when div hovered do...
    $this.hover(function(e){
     //if grow equals true then animate div
   if(o.grow === 'true') {$(this).stop().animate({'height' : (dh*o.growPercent), 'width' : (dw*o.growPercent)},{duration: o.growSpeed, easing: o.easing, queue: 'false'});};
        var cx =  $(this).outerWidth();
        var cy =  $(this).outerHeight();
        //if grow option  set size for image
    if(o.grow === 'true') {$(this).find('img').stop().css({'height' : ((cy*o.growPercent) * (o.magnifier + 1)), 'width' : ((cx*o.growPercent) * (o.magnifier + 1))});}
    else {$(this).find('img').stop().css({'height' : (cy * (o.magnifier + 1)), 'width' : (cx * (o.magnifier + 1))});};

       $(this).mousemove(function(e){
                     var x =   e.pageX - $(this).offset().left;
                     var y = e.pageY - $(this).offset().top;
                     var xRate = Math.round((x/cx)* 100)/100;
                     var yRate = Math.round((y/cy)* 100)/100;
                     //set magnification size
                        $(this).find('img').css ({'left' : (cx/cx) - (x*o.magnifier) },{duration : 1});
                        $(this).find('img').css({'top' : (cy/cy) - (y*o.magnifier)},{duration : 1});

                                    });
      }, function(){
             // hover out set image to original size
           $(this).find('img').stop().animate({'height' : dh, 'width' : dw, 'left' : '0px', 'top' : '0px'},{duration : o.outSpeed, easing: o.easing});
           //if grow option set to true animate div to original size
           if(o.grow === 'true') { $(this).stop().animate({'height' : dh, 'width' : dw},{duration: o.outSpeed, easing: o.easing, queue: 'false'}); };
         });
});
};//end each

})(jQuery)


