

var RETINA_NS = 'retina';



$.magnificPopup.registerModule(RETINA_NS, {

	options: {

		replaceSrc: function(item) {

			return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });

		},

		ratio: 1 // Function or number.  Set to 1 to disable.

	},

	proto: {

		initRetina: function() {

			if(window.devicePixelRatio > 1) {



				var st = mfp.st.retina,

					ratio = st.ratio;



				ratio = !isNaN(ratio) ? ratio : ratio();



				if(ratio > 1) {

					_mfpOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {

						item.img.css({

							'max-width': item.img[0].naturalWidth / ratio,

							'width': '100%'

						});

					});

					_mfpOn('ElementParse' + '.' + RETINA_NS, function(e, item) {

						item.src = st.replaceSrc(item, ratio);

					});

				}

			}



		}

	}

});