var running = true;
var count = 0;
var busy = 0;

function start_slide1(id, start, end, sec, timebetween){
	if (running) {
		// aantal images
			var aantal = document.getElementById("aantal_slides").value;
			
			// id
			var id = "image"+count;
			var restart = aantal-1;
			// begin met infaden als timer verlopen is
			changeimg(id,start,end,sec,'inzoomen');
			fadeout = setTimeout("changeimg('" + id + "','" + end + "','" + start + "','" + sec + "','uitzoomen')",timebetween);
			count++;
			if(count==aantal) count=0;
			starter = setTimeout("start_slide1('" + id + "','" + start + "','" + end + "','" + sec + "','" + timebetween + "')",timebetween);
		}
	}
function start_slide2(id, start, end, sec, timebetween){
	if (running) {
		// aantal images
			var aantal = document.getElementById("aantal_slides").value;
			
			// id
			var id = "image"+count;
			var restart = aantal-1;
			// begin met infaden als timer verlopen is
			changeimg(id,start,end,sec,'inzoomen');
			fadeout = setTimeout("changeimg('" + id + "','" + end + "','" + start + "','" + sec + "','uitzoomen')",timebetween);
			count++;
			if(count==aantal) count=0;
			starter = setTimeout("start_slide2('" + id + "','" + start + "','" + end + "','" + sec + "','" + timebetween + "')",timebetween);
		}
	}
	
function start_slide3(id, start, end, sec, timebetween){
	if (running) {
		// aantal images
			var aantal = document.getElementById("aantal_slides1").value;
			
			// id
			var id = "portal"+count;
			var restart = aantal-1;
			// begin met infaden als timer verlopen is
			changeimg(id,start,end,sec,'inzoomen');
			fadeout = setTimeout("changeimg('" + id + "','" + end + "','" + start + "','" + sec + "','uitzoomen')",timebetween);
			count++;
			if(count==aantal) count=0;
			starter = setTimeout("start_slide3('" + id + "','" + start + "','" + end + "','" + sec + "','" + timebetween + "')",timebetween);
		}
	}
	
function StopStartTimer(id,start,end,sec,timebetween,i) {
   if (running) {
      running=false;
			clearTimeout(fadeout);
			clearTimeout(starter);
   }
   else{
      running=true;
			clearTimeout(starter);
			starter = setTimeout("start_slide1('" + id + "','" + start + "','" + end + "','" + sec + "','" + timebetween + "')",timebetween);
	 }
}

	
function changeimg(naam,start,end,time,mode){
	// verander opacity
		opacity(naam,start,end,time);
		if(mode=='inzoomen'){
			document.getElementById(naam).style.zIndex = "1";
		}
		if(mode=='uitzoomen'){
			//alert("ik zet z-index van "+naam+" op nul");
			document.getElementById(naam).style.zIndex = "0";
		}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
}
