/*
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   Precarga de imagenes
   Namespace es.aquataller
   version:  d01-m02-a07
//  -- -- -- -- -- -- -- -- --
//  Mauricio F. Tolezano (www.acuataller.com)
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
// 
*/


es.aquataller.utiles.CargarImagen = function(htmlImg, onCompletado, onCompletadoScope) 
{
	if(htmlImg)
	{
		this.htmlImg 		= htmlImg;
		this.imgObj			= null;
		this.intervalo		= 500;
	
		var _this 			= this;
		this.delegarTimer 	= function(){_this.onEventoTimer()};
		this.onCompletado 	= onCompletado || function(){};
		this.onCompletadoScope 	= onCompletadoScope || this;
	}
}

es.aquataller.utiles.CargarImagen.prototype = {

	cargar: function(url) 
	{
		if(!this.htmlImg||!url) return false;
		
		this.eliminarTimer();		
		imgObj 		= new Image(); 	
		imgObj.src 	= url;		
		
		if (!this.intervaloId) {
			this.intervaloId = window.setInterval(this.delegarTimer, this.intervalo);
		}
	},
	onEventoTimer: function() 
	{
		if(imgObj.complete)
		{
			this.eliminarTimer();			
			this.htmlImg.src = imgObj.src;
			this.onCompletado.call(this.onCompletadoScope);		
		}
	},
	eliminarTimer: function() 
	{
		window.clearInterval(this.intervaloId);
		this.intervaloId = null;

	}
	
}
