//<![CDATA[

var cycleimages = []; 

onloadmanager.add('cycleimages_init', cycleimages_Init);



function cycleimages_Init() {
	/* detecteer CSS3 */	
	if(csssupport('transitionProperty') && csssupport('opacity')) {
		cycleimages_InitCSS3();
		return;
	} else {
		cycleimages_InitCSS2();
	}
}	


function cycleimages_InitCSS3() {	
	var all = document.getElementsByTagName("div");
	var i, N = all.length;
	for(i = 0; i < N; i++) {
		if(all[i].className == "cycleimage") {
			cycleimages.push(new cCycleimage_CSS3(all[i]));
		}
	}
}
	

function cycleimages_InitCSS2() {
	var all = document.getElementsByTagName("div");
	var i, N = all.length;
	for(i = 0; i < N; i++) {
		if(all[i].className == "cycleimage") {
			cycleimages.push(new cCycleimage_CSS2(all[i]));
		}
	}
}


function cCycleimage_CSS3(div) {
	this.div = div;	
	this.images = this.div.getElementsByTagName("img");
	this.nof = this.images.length;
	this.images[0].className = "fadein";
	this.index = 1;
	this.interval = setInterval((function(obj) { return function() { obj.cycle.call(obj); }; })(this), 4000);
	this.cycle();
}
cCycleimage_CSS3.prototype.cycle = function() {
	var m = this.index == 0 ? this.nof - 1 : this.index - 1; 
	var r = m == 0 ? this.nof - 1 : m - 1;
	var c = r == 0 ? this.nof - 1 : r - 1;
	
	this.images[c].className = "";	
	this.images[r].className = "reset";	
	this.images[m].className = "moveout";	
	this.images[this.index].className = "fadein";
	this.index++;
	if(this.index >= this.nof) this.index = 0;
};




function cCycleimage_CSS2(div) {
	this.div = div;
	this.images = this.div.getElementsByTagName("img");
	this.nof = this.images.length;

	var i;
	for(i = 1; i < this.nof; i++) {
		this.images[i].style.top = "0px";
		this.images[i].style.opacity = "0";
		this.images[i].style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";	
	} 	

	this.index = 1;
	this.cycle();
}
cCycleimage_CSS2.prototype.cycle = function() {
	this.m = this.index == 0 ? this.nof - 1 : this.index - 1; 
	this.r = this.m == 0 ? this.nof - 1 : this.m - 1;
 	
	this.images[this.r].style.opacity = "0";
	this.images[this.r].style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";	
	this.images[this.r].style.top = "0px"; 	
 	
	this.step = 0;
	clearInterval(this.animation);
	this.animation = setInterval((function(obj) { return function() { obj.animate.call(obj); }; })(this), 20);
}
cCycleimage_CSS2.prototype.animate = function() {
	this.step++;	
	
	// this.images[r].className = "reset";	
	if(this.step < 32) {
		this.images[this.m].style.top = this.step + "px";
	}
	if(this.step > 30) {	
		this.images[this.index].style.opacity = (this.step - 30) / 25;
		this.images[this.index].style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + (this.step - 30) * 4 + ")";
	}
	
	if(this.step == 55) {
		this.index++;
		if(this.index >= this.nof) this.index = 0;
		clearInterval(this.animation);
		setTimeout((function(obj) { return function() { obj.cycle.call(obj); }; })(this), 2000);
	}
};

//]]>
