var ImageRotate=function() {
	return {
		timeout: 5000,
		incomplete_tout: 300,
		items: null,
		img_id: "",
		link_id: "",
		c: 0,
	
		runInScope: function(fn, sc){
			var scope = sc || window;
		
			return function() {
				return fn.apply(sc);
			};
		},

		init: function(a, img_id, link_id) {
			this.items=a;
			if (!this.items.length) return 0;
			this.img_id=img_id;	this.link_id=link_id;
			for ( i in a ) {
				this.items[i].img_obj=new Image();
				this.items[i].img_obj.src=this.items[i].img;
			}
			this.rotate();
		},
	
		rotate: function() {
			if (this.items[this.c].img!=="") {
				if (!this.items[this.c].img_obj.complete) {
					setTimeout( this.runInScope(this.rotate, this) , this.incomplete_tout);return;
				}

				var target=document.getElementById(this.img_id);
				if (target) {
					target.src=this.items[this.c].img_obj.src;
				}
			}

			if (this.items[this.c].href!=="") {
				var target_link=document.getElementById(this.link_id);
				if (target_link) {
					target_link.href=this.items[this.c].href;
				}
			}
			this.c=(this.c + 1) % this.items.length;
			setTimeout( this.runInScope(this.rotate, this) , this.timeout);
		}
	}
}

