function imageEngine() {
    this.temp_img = '';
	this.container = '';
	this.popup = '';
	this.images = new Array();
}



imageEngine.prototype = {


	//Onclick esemény beállítása
	setPopup: function( str ) {
		this.popup = str;
	},
	//Közepes kép tárolására való container beállítása
	setContainer: function( str ) {
		this.container = str;
	},

	//Betöltőkép beállítása
	setTempImage: function( str ) {
		this.temp_img = str;
	},

	//Új kép hozzáadása
	addImage: function( id, img_path ) {
		this.images[ id ] = new Array();
		this.images[ id ]['img'] = img_path;		
		this.images[ id ]['args'] = arguments;

	},

	//Kép előtöltése
	preLoad: function( img_url ) {
		img_pre = new Image();
		img_pre.src = img_url;
		return img_pre;
	},

	//Onclick esemény fordítása
	preparePopup: function( from, args, type ) {
		if ( type == 2 ) {
			for (i = 0; i < args.length; i++) {
				from = from.replace( '%%p'+i+'%%', args[i+1] );
			}
		} else {
			for (i = 0; i < args.length; i++) {
				from = from.replace( '%%p'+i+'%%', args[i] );
			}
		}
		return from;
	},

	changeImg2: function( id, preloaded ) {
		var container_obj = document.getElementById( this.container );
		
		//Konténer ürítése
		container_obj.innerHTML = '';


		if (preloaded) {
			img_pre = this.preLoad( this.images[id]['img'] );
			img_pre.popup = popup_event;
			img_pre.onclick = function() {
					eval(this.popup);
				}
			container_obj.appendChild(img_pre);

		} else {

			img_tmp = document.createElement('IMG');
			img_tmp.src = this.temp_img;
			container_obj.appendChild(img_tmp);

			var popup_event;

			img_pre = this.preLoad( this.images[id]['img'] );

			popup_event = this.preparePopup(this.popup, this.images[id]['args'], 2);

			img_pre.container_name=this.container;
			img_pre.popup = popup_event;
			img_pre.onclick = function() {
					eval(this.popup);
				}

			img_pre.onload = function() {
				container_obj = document.getElementById( this.container_name );
				container_obj.innerHTML = '';
				container_obj.appendChild(this);
			}
		}
	}

}