function imgLoader_Engine() {
	this.imgPreload = new Image();

	this.body = null;

  this.lock = new Array();
	this.cContainer = null;
	this.cImage		= null;
	this.cPreloader	= null;
};

imgLoader_Engine.prototype = {

	register: function(evnt, func, o) {
		if ( typeof(func) != 'function' )
			return false;

		if ( typeof(o) == 'undefined' )
			o = window;

		if (o.addEventListener) {
			o.addEventListener(evnt, func, false);

		} else if (o.attachEvent) {
			if (!o._listeners)
				o._listeners = new Array();

			if (!o._listeners[evnt])
				o._listeners[evnt] = new Array();

			var workaroundFunc = function() {
				func.apply(o, new Array());
			}

			o._listeners[evnt][func] = workaroundFunc;

			o.attachEvent('on' + evnt, workaroundFunc);
		}
	},

	unregister : function(evnt, func, o) {
		if ( typeof(func) != 'function' )
			return false;

		if ( typeof(o) == 'undefined' )
			o = window;

		if (o.removeEventListener) {
			o.removeEventListener(evnt, func, false);

		} else if (o.detachEvent) {
			if (o._listeners && o._listeners[evnt] && o._listeners[evnt][func]) {
				o.detachEvent('on' + evnt, o._listeners[evnt][func]);
			}

		}
	},

	createImage: function(obj, width, height, url, lockid) {
    cImage = document.getElementById(obj);

		this.register('load', function(){imgLoader.imgLoaded(obj, lockid)}, cImage);

		this.setOpacity(cImage, 0);

    cImage.width    = width;
		cImage.height   = height;
		cImage.src      = url;

	},

	show: function(obj, i) {
		var imageURL	= i[0];
		var imageWidth  = i[1];
		var imageHeight	= i[2];

        if (i[3]) {
            lockid = i[3];
        } else {
            lockid = 0;
        }

        if (this.lock[lockid]) {
            return;
        }

        this.lock[lockid] = 1

        this.createImage(obj, imageWidth, imageHeight, imageURL, lockid);

	},

	imgLoaded: function(obj, lockid) {

    cImage = document.getElementById(obj);

		cImage.onload = function(){}; // wipe
		this.unregister('load', cImage);

		setTimeout('imgLoader.imgFade(\''+obj+'\', 1, '+lockid+')', 1);
	},

	imgFade: function(obj, opacity, lockid) {

    cImage = document.getElementById(obj);

		if (!cImage)
			return false;

		this.setOpacity(cImage, Math.exp(opacity));

		if (Math.exp(opacity) < 100) {
			opacity += 0.45;
        } else {
            this.lock[lockid] = 0;
			return;
        }

		setTimeout('imgLoader.imgFade(\''+obj+'\', '+opacity+', '+lockid+')', 1);
	},

	setOpacity: function(o, opacity) {
		o.style.opacity = (opacity / 100);
		o.style.MozOpacity = (opacity / 100);
		o.style.KhtmlOpacity = (opacity / 100);
		o.style.filter = "alpha(opacity=" + opacity + ")";
	}

}

