var img_service = new image_service();

function image_service() {
	
	this.pre_images     = new Array();
	this.b_img          = new Array();
	this.img_cnt        = 0;
	this.img_cnt_prefix = '_image_id_counter_prefix';
	
	this.preload = function() {
		var i, a = this.preload.arguments;
		for (i=0; i < a.length; i++) {
			this.pre_images[a[i][0]] = new Image;
			this.pre_images[a[i][0]].src = a[i][1];
		}
	}
	
	this.get_image = function(sName) {
		if (this.pre_images[sName]) return this.pre_images[sName].src;
		else return false;
	}
	
	this.over = function(oImg, sName) {
		if (typeof(oImg) == 'string') oImg = document.getElementById(oImg);
		if (this.pre_images[sName]){
			if (!oImg.id) {
				oImg.id = this.img_cnt_prefix + this.img_cnt++;
			}
			this.b_img[oImg.id] = oImg.src;
			oImg.src = this.pre_images[sName].src;
		}
	}
	
	this.restore = function(oImg) {
		if (typeof(oImg) == 'string') oImg = document.getElementById(oImg);
		if (this.b_img[oImg.id]){
			oImg.src = this.b_img[oImg.id];
			this.b_img.splice(oImg.id, 1);
		}
	}
	
	this.swap = function(oImg, sName) {
		if (typeof(oImg) == 'string') oImg = document.getElementById(oImg);
		if (this.pre_images[sName]){
			oImg.src = this.pre_images[sName].src;
		}	
	}
}
