var swap = new image_swap();

function image_reg(id, over_src, img) {
	swap.register(id, over_src, img);
}

function image_sticky(id) {
	swap.sticky(id);
}

function image_over(id) {
  swap.over(id);
}

function image_out() {
  swap.out();
}

// ImageSwap Object
function image_swap() {
  this.active_img = 0;
  this.sticky_id = 0;
  this.images = Array();
  this.image_obj = new Image();
  
  this.over = image_swap_over;
  this.out = image_swap_out;
  this.new_image = image_swap_new_image;
  this.register = image_swap_register;
  this.sticky = image_swap_sticky;
}

function image_swap_over(id) {
	if(this.sticky_id != id) {
	  this.active_img = id;
  	this.images[id][0].src = this.images[id][2];
 	}
}

function image_swap_out() {
	if(this.active_img != 0 && this.active_img != this.sticky_id) {
	  this.images[this.active_img][0].src = this.images[this.active_img][1];
  	this.active_img = 0;
 	}
}

function image_swap_new_image(id, over_src, img) {
	var im = Array();
	im[0] = img;
	im[1] = img.src;
	im[2] = over_src;
	this.images[id] = im;
  this.image_obj.src = im[2];
}

function image_swap_register(id, over_src, img) {
	img.onload = "";
	this.new_image(id, over_src, img);
}

function image_swap_sticky(id) {
	if(this.sticky_id != id) {
		if(this.sticky_id != 0) this.images[this.sticky_id][0].src = this.images[this.sticky_id][1];
		this.sticky_id = id;
		if(id != 0) this.images[id][0].src = this.images[id][2];
	}
}