
var fadingOut = 0;
var fadingIn = 0;
var timer;

function switchClass(activeID,photo){	
    setPhoto(photo);
	moveArrow(activeID);	
}

function setPhoto(photo) {		
    if(currentPhoto != photo){
    	if((fadingOut == 0)&&(fadingIn == 0)){
    		fadingOut = 1;
	    	$("#homeFoto").fadeTo('normal',0, function(){	    		
		        document.getElementById('homeFoto').src="/site_files/uploads/mediabank/images/" + photo ;
		        currentPhoto = photo;
		        fadingOut = 0;
		        fadingIn = 1;
		        clearTimeout(timer);
		        $("#homeFoto").fadeTo('normal',1, function(){fadingIn = 0; doAnimation();return true;}); 
	        });
    	}else{
    		$("#homeFoto").stop();    		
    		if((fadingIn == 1)){
    			currentPhoto = photo;
    			document.getElementById('homeFoto').src="/site_files/uploads/mediabank/images/" + photo ;
    			clearTimeout(timer);
    			$("#homeFoto").fadeIn('normal', function(){fadingIn = 0; doAnimation(); return true;}); 
    		}
    		if((fadingOut == 1)){
    			$("#homeFoto").fadeTo(0,0, function(){	    		
			        document.getElementById('homeFoto').src="/site_files/uploads/mediabank/images/" + photo ;
			        currentPhoto = photo;
			        fadingOut = 0;
			        fadingIn = 1;
			        clearTimeout(timer);
			        $("#homeFoto").fadeTo('normal',1, function(){fadingIn = 0;doAnimation();return true;}); 
		        });
    		}
    	}
    }    
}

function doAnimation(){	
	$("#homeFoto").stop();	
	index = findIndex(images2, currentPhoto);
	index++;		
	if(index ==  5){index = 0;	}
	index2=index + 1 ;
	timer = setTimeout( "switchClass(index2,images2[index])", 5000 );	
}


function moveArrow(activeID){
	document.getElementById('firstElement').className='homeFotoKeuzeOptieOff';
	document.getElementById('secondElement').className='homeFotoKeuzeOptieOff';
	document.getElementById('thirdElement').className='homeFotoKeuzeOptieOff';
	document.getElementById('forthElement').className='homeFotoKeuzeOptieOff';
	document.getElementById('fifthElement').className='homeFotoKeuzeOptieOff';
	document.getElementById('sixthElement').className='homeFotoKeuzeOptieOffArc';

	if(activeID == 1){
		document.getElementById('homeFoto').style.height='290px';
		document.getElementById('firstElement').className='homeFotoKeuzeOptieOn';
	}
	if(activeID == 2){
		document.getElementById('homeFoto').style.height='290px';
		document.getElementById('secondElement').className='homeFotoKeuzeOptieOn';
	}
	if(activeID == 3){
		document.getElementById('homeFoto').style.height='290px';
		document.getElementById('thirdElement').className='homeFotoKeuzeOptieOn';
	}
	if(activeID == 4){
		document.getElementById('homeFoto').style.height='290px';
		document.getElementById('forthElement').className='homeFotoKeuzeOptieOn';
	}	
	if(activeID == 5){
		document.getElementById('homeFoto').style.height='290px';
		document.getElementById('fifthElement').className='homeFotoKeuzeOptieOn';
	}
}

function findIndex(array,value){
	var ctr = "";
	for (var i=0; i < array.length; i++) {
		// use === to check for Matches. ie., identical (===), ;
		if (array[i] == value) {
			return i;
		}
	}
	return ctr;
};