function magnifier() {

  this.magnifyImg = function(ptr, magnification, magnifierSize) {
     //console.log('window.USER_IS_TOUCHING=' + window.USER_IS_TOUCHING + ' window.POINTER_SIZE=' + window.POINTER_SIZE + ' window.USER_CAN_HOVER=' + window.USER_CAN_HOVER);
    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) {

       var zoom_div = $(this).attr('id').replace('image', 'image_zoom');
       //console.log('zoom_div=' + zoom_div + ' checked=' + $('#' + zoom_div + '>input').prop('checked'));
       //console.log('image_zoom9 input=' + $('#image_zoom9>input').prop('checked'));
       // 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 */
          // Only return if USER_IS_TOUCNHING is true
          if (window.USER_IS_TOUCHING == undefined || window.USER_IS_TOUCHING) {
             console.log('returning since device has Touch or Pointer events.\nwindow.USER_IS_TOUCHING=' + window.USER_IS_TOUCHING + ' window.POINTER_SIZE=' + window.POINTER_SIZE + ' window.USER_CAN_HOVER=' + window.USER_CAN_HOVER);
             $('#' + zoom_div + '>input').prop({'checked':false}); // uncheck box when lose maginifier
             return;
          }
       }

       //if (!document.getElementById('test').checked) return;

       //console.log('e.type=' + e.type);

      // Dont show this unless the ui-icon-zoomin clicked
      $(this).css('cursor', $(this).parent().attr('href') ? 'pointer' : 'default');
      HREF = null; // Set to null so click() function below not executed
      if (!$('#' + zoom_div + '>input').prop('checked')) return false;

      $(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
          $('#' + zoom_div + '>input').prop({'checked':false}); // uncheck box when lose maginifier
          //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"); HREF = null; win.focus(); // Make null after using since mouseout event may not get executed if moving around a lot after a click. Place before the opened window gets focus.
            //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();
}
