
	function title_image_swapper(ref, claim, inst) {
		this.items = new Array();
		this.ref = ref;
		this.claim = claim;
		this.refb = null;
		this.inst = inst;
		
		this.step = null;
		this.loader = null;
		this.timeout = null;
		this.interval = 4000;
		
		this.fade_k = 0;
		this.fade_timeout = null;
	}
	
	title_image_swapper.prototype.add_image = function(src, title) {
		var nd = new Array();
		nd["src"] = src;
		nd["title"] = title;
		
		this.items[this.items.length] = nd;
	}
	
	title_image_swapper.prototype.construct = function(random, initial_step) {
		this.step = typeof initial_step == 'undefined' ? -1 : initial_step;
		if (random) this.step = Math.round(Math.random() * (this.items.length - 1));
		this.loader = document.createElement("IMG");
		this.goto_step(true);
		
		var self = this;
	}
	
	title_image_swapper.prototype.goto = function(index) {
		if (index >= 0 && index < this.items.length && index != this.step) {
			this.step = index;
			var self = this;
			
			this.loader.onload = function() { self.evt_goto(); }
			this.loader.src = this.items[this.step]["src"];
			
			if (this.claim != null) this.claim.innerHTML = "<p>" + this.items[this.step]["title"] + "<p>";
		}
	}
	
	title_image_swapper.prototype.evt_goto = function() {
		this.loader.onload = null;
		
		if (this.refb == null) {
			this.refb = document.createElement("IMG");
			this.ref.parentNode.appendChild(this.refb);
		}
		this.refb.src = this.loader.src;
		
		var tmp = this.refb;
		this.refb = this.ref;
		this.ref = tmp;
		
		if (this.fade_timeout != null) clearTimeout(this.fade_timeout);
		this.fade_k = 0;
		
		if (document.all) {
			this.ref.style.filter = "alpha(opacity=0)";
			this.refb.style.filter = "alpha(opacity=100)";
		} else {
			this.ref.style.opacity = "0.0";
			this.refb.style.opacity = "1.0";
		}
		
		this.ref.style.display = "block";
		this.refb.style.display = "block";
		
		this.fade_step();
	}
	
	title_image_swapper.prototype.goto_step = function(wait) {
		if (!wait && this.items.length > 1) {
            var nStep = this.step;
            if (nStep == -1) nStep = 0;
            
            var left, right;
            
            do {
                left = this.items[nStep]["src"].substr(this.items[nStep]["src"].lastIndexOf("/") + 1);
                right = this.ref.src.substr(this.ref.src.lastIndexOf("/") + 1);
                
                if (left == right) {
                    nStep++;
                    if (nStep >= this.items.length) nStep = 0;
                }
            } while (left == right);
            
            this.goto(nStep);
        }
		this.timeout = setTimeout(this.inst + ".goto_step()", this.interval);
	}
	
	title_image_swapper.prototype.fade_step = function() {
		if (this.fade_k < 100) {
			this.fade_k += 10;
			if (this.fade_k >= 100) {
				if (document.all) {
					this.ref.style.filter = "alpha(opacity=100)";
				} else {
					this.ref.style.opacity = "1.0";
				}
				
				this.refb.style.display = "none";
				
			} else {
				if (document.all) {
					this.ref.style.filter = "alpha(opacity=" + Math.round(this.fade_k) + ")";
					this.refb.style.filter = "alpha(opacity=" + Math.round(100 - this.fade_k) + ")";
					
				} else {
					this.ref.style.opacity = (this.fade_k / 100);
					this.refb.style.opacity = (100 - this.fade_k) / 100;
				}
			}
			
			this.fade_timeout = setTimeout(this.inst + ".fade_step()", 50);
		}
	}
	
	title_image_swapper.prototype.force_goto_step = function() {
		if (this.timeout != null) {
			clearTimeout(this.timeout);
			this.goto_step();
		}
	}
	
