// JavaScript Document

//watcher voor de time invterval voordat de plaatjes worden aangepast
var watcher = null;

//pre een class die de images opslaat
function Pre() {
	
	this.counter = 0;
	
	this.length = 0;
	
	this.objects = new Array();
	
	this.add = function(img, title, description) {
		this.objects[this.length] = new Obj(this.length, img, title, description);
		this.length++;
	}
	
	this.get = function(id) {
		if(this.objects[id]) {
			return this.objects[id];
		}
		return null;
	}
	
	this.getAutomated = function() {
		var obj = this.get(this.counter);
		
		this.counter++;
		if(this.counter >= this.length) {
			this.counter = 0;
		}
		
		return obj;
	}
	
}

//class die informatie van een plaatje bijhoud
function Obj(id, img, title, description) {
	
	this.id = id;
	this.img = img;
	this.title = title;
	this.description = description;

	preloadImage('pre_'+ this.id, this.img);

}

//imgWatcher word uitgevoerd elke keer dat de tijd interval verstreken is
function imgWatcher() {
	
	for(var i = 0; i < 4; i++) {
		var imgObj = $('img'+ i);
		var imgDes = $('desc'+ i);
		
		if(imgObj && imgDes) {
			var inf = pre.getAutomated();			
			
			imgObj.src = images['pre_'+ inf.id].src;
			imgDes.innerHTML = inf.description;
		}

	}
	
}

//start de watcher
initPre = function doInitPre() {
	imgWatcher();
	var watcher = setInterval("imgWatcher()", 6000);
}

//na body onload de watcher uitvoeren
addLoadEvent(initPre);