function magnifier() {

  this.magnifyImg = function(ptr, magnification, magnifierSize) {
    var $pointer;
    var HREF = null; //make HREF global var set in hover() so can retrieve in click()
    //console.log('0HREF=' + HREF);
    //console.log('ptr=' + ptr.attr('id'));
    if (typeof ptr == "string") {
      $pointer = $(ptr);
    } else if (typeof ptr == "object") {
      $pointer = ptr;
    }
    
    if(!($pointer.is('img'))) {
      console.log('Object must be image. $pointer=' + $pointer);
      console.log('$pointer.length=' + $pointer.length);
      return false;
    }

    magnification = +(magnification);

    $pointer.hover(function(e) {

       // Dont allow on touch devices since no hover and get mag glass on click
       // https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
       if (('ontouchstart' in window) ||
           (navigator.maxTouchPoints > 0) ||
           (navigator.msMaxTouchPoints > 0)) {
          /* browser with either Touch Events of Pointer Events
             running on touch-capable device */
          return;
       }

       //console.log('e.type=' + e.type);
      $(this).css('cursor', 'none');
      $('.magnify').show();
      //Setting some variables for later use
      var width = $(this).width();
      var height = $(this).height();
      var src = $(this).attr('src');
      HREF = $(this).parent().attr('href');
      //console.log('1HREF=' + HREF);
      var imagePos = $(this).offset();
      var image = $(this);

      if (magnifierSize == undefined) {
        magnifierSize = '150px';
      }

      $('.magnify').css({
        'background-size': width * magnification + 'px ' + height * magnification + "px",
        'background-image': 'url("' + src + '")',
        'width': magnifierSize,
        'height': magnifierSize
      });

      //Setting a few more...
      var magnifyOffset = +($('.magnify').width() / 2);
      var rightSide = +(imagePos.left + $(this).width());
      var bottomSide = +(imagePos.top + $(this).height());

      $(document).mousemove(function(e) {
        if (e.pageX < +(imagePos.left - magnifyOffset / 6) || e.pageX > +(rightSide + magnifyOffset / 6) || e.pageY < +(imagePos.top - magnifyOffset / 6) || e.pageY > +(bottomSide + magnifyOffset / 6)) {
          $('.magnify').hide();
          $(document).unbind('mousemove');
          HREF = null; // Set to null so click() function below not executed
          //console.log('3HREF=' + HREF);
        }
        var backgroundPos = "" - ((e.pageX - imagePos.left) * magnification - magnifyOffset) + "px " + -((e.pageY - imagePos.top) * magnification - magnifyOffset) + "px";
        $('.magnify').css({
          'left': e.pageX - magnifyOffset,
          'top': e.pageY - magnifyOffset,
          'background-position': backgroundPos
        });
      });

      // Allow HREF
      $(document).click(function(e) {
         if (HREF) {
            //console.log('4HREF=' + HREF);
            //console.log('HREF=' + HREF);
            var win=window.open(HREF,"viewer","resizable=0,width=820,height=770,scrollbars=yes,status=yes");win.focus();
            HREF = null; // Make null after using since mouseout event may not get executed if moving around a lot after a click
            //console.log('5HREF=' + HREF);
            if (win) {
               //Browser has allowed it to be opened
               win.focus();
            } else {
               //Browser has blocked it
               alert('Please allow popups for this website');
            }
         }
      });

    }, function() {

    });

  };

  this.init = function() {
    $('body').prepend('<div class="magnify"></div>');
  }

  return this.init();
}
