// 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, link) {
		this.objects[this.length] = new Obj(this.length, img, title, link);
		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, link) {
	
	this.id = id;
	this.img = img;
	this.title = title;
	this.link = link;

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

}

//imgWatcher word uitgevoerd elke keer dat de tijd interval verstreken is
function newHomeWatcher() {
	
	var imgObj = $('img_1');
	var imgTitle = $('title_1');
	var imgLink = $('link_1');
	//var readMoreLink = $('rLink_1');
	
	if(imgObj && imgTitle ) {
		var inf = pre.getAutomated();			
		
		imgObj.src = images['pre_'+ inf.id].src;
		imgTitle.innerHTML = inf.title;
		
		if(inf.link){
			imgLink.style.display = "block";
			imgLink.href = inf.link;
		}else{
			imgLink.style.display = "none";
		}

		
		
	}	
}

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

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