
MyScan = {
	NEXT :true,
	TIME :null,
	COMPTEUR :0,
	scanner:null,
	enable:function(){this.NEXT = true;},
	desable:function(){this.NEXT = false;},
	scan:function(id_preview, myCallbackFunction){
		
		this.scanner = new Instascan.Scanner({ video: document.getElementById(id_preview) });
		this.scanner.addListener('scan', function (content) {
			
			if(MyScan.NEXT)
				myCallbackFunction(content)			
			
		});
		
		// ========================================
		Instascan.Camera.getCameras().then(function (cameras) {

			if (cameras.length > 0) {

			  MyScan.scanner.start(cameras[0]);

			} else {

			  console.error('No cameras found.');

			}

		}).catch(function (e) {

			console.error(e);

		});
	},
	postScan: function(second=10,postCallback){
		this.NEXT = false;
		this.TIME = setInterval(function(){
			MyScan.COMPTEUR++;
			if(MyScan.COMPTEUR>=second){					
				clearTimeout(MyScan.TIME);
				MyScan.NEXT = true;
				MyScan.COMPTEUR = 0;
			}
			postCallback(MyScan.COMPTEUR)
		},1000);
	} 
}

			// var w = parseFloat($('#progress-in').css('width'));
			// $('#span-progress').html( Math.round((w/w1)*100,2) +'%');
			// $('#progress-in').css('width',(w + increment)+'px');
	
				// $('#progress-in').removeClass('progress-bar-primary').addClass('progress-bar-success');
				// $('#span-progress').removeClass('bg-aqua').addClass('bg-green');

	

	  
