function Picture() {	this.source = "";	this.index = -1;	this.bib = "";	this.lastName = "";	this.firstName = "";	this.unid = "";	this.timeStamp = "";	this.team = "";	this.overallPos = "";		}function RandomPicture() {		this.HttpURL = "";		this.ClientId = "";		this.RaceId = "";		this.maxpicture = -1;		this.pictures = new Hash();		this.currentpictureidx = 0;				this.cache = new Array();		this.cacheCount = 0;		this.cacheRetrieve = 0;		this.parentObjectName = "";				this.getCurrentPictureIndex = function () {			return this.currentpictureidx;		}				this.createTitle = function (picture) {					if (picture.bib == "") return "";						var pos = picture.overallPos;						if ((pos == "0") | (pos=="")) {				pos = "";			} else {				pos = " (" +  pos  + ".)"			}						return "<div onclick=\"" + this.parentObjectName + ".openResult('" + picture.unid + "')\" style=\"cursor:pointer\">" + (picture.team!=""?picture.team + "<br>" + picture.bib + " - " + picture.lastName:picture.bib + " - " + picture.lastName + pos) + "</div>";		}						this.changePicture = function () {					if ((this.maxpicture != -1) && (this.pictures.length >= this.maxpicture) && (this.maxpicture > 160)) {							var i= parseInt(Math.random() * this.pictures.length) ;				var pic = document.getElementById("randompic");						var caption = document.getElementById("randompictitle");							if ((pic != null) && (this.pictures[new String(i)])) {					pic.src =this.HttpURL + this.pictures[new String(i)].source();					this.currentpictureidx = this.pictures[new String(i)].index;					if (caption) {								caption.innerHTML = this.createTitle(this.pictures[new String(i)]);					}					return;				}							}						if (this.cacheRetrieve < this.cacheCount) {				this.cacheRetrieve++;				var pic = document.getElementById("randompic");				var caption = document.getElementById("randompictitle");								var picturecache = this.cache[this.cacheRetrieve];				if (picturecache) {						var picture = this.pictures[new String(picturecache)]						if (picture) {							if (pic) {																						pic.src =this.HttpURL+picture.source;									this.currentpictureidx = picture.index;									if (caption) {										caption.innerHTML = this.createTitle(picture);									}											return;							}																}				}							}			var url =  this.HttpURL + "showrndpicture?Open&clientid=" + this.ClientId + "&raceid=" + this.RaceId;									try {							new Ajax.Request(url, { method:'get',							  encoding: 'iso-8859-2',							  onSuccess: function(transport, json){												  	var json = transport.responseText.evalJSON();							     if (Object.inspect(json)) {							     	this.cache = new Array();							     	this.cacheRetrieve = 0;							     	this.cacheCount = 0;							     								     	var pic = document.getElementById("randompic");									var caption = document.getElementById("randompictitle");									for (var i = 0; i < json.Pictures.length; i++) { 											var rnd = json.Pictures[i];											var thumb = new Picture();											thumb.source = rnd.source;											this.maxpicture = rnd.count;											thumb.index = rnd.index;											thumb.bib = rnd.bib;											thumb.timeStamp = rnd.timeStamp;											thumb.lastName = rnd.lastName;											thumb.unid = rnd.unid;											thumb.team = rnd.team;											thumb.overallPos = rnd.overallPos											this.pictures[new String(thumb.index)] = thumb;																						if (i == 0) {												if (pic) {																										pic.src =this.HttpURL+thumb.source;													this.currentpictureidx = thumb.index;												}												if (caption) {													caption.innerHTML = this.createTitle(thumb);												}											} else {												this.cache[i-1] = thumb.index;												this.cacheCount++;											}																				}								 }							    }.bind(this)						  });				} catch (e) {				}		}		this.start = function () {			window.setTimeout(function () { this.changePicture(); this.start(); }.bind(this), 10000) ;	}		this.stop = function () {		window.clearTimeout() ;	}}
