var slides = 0;
var pos = 1;
$(document).ready(function(){
	
	$('.pi-bewerken').click(function(){
		var iid = $(this).attr("iid");
		$('#upload-div').load("inc/ws.php",{m:'getThisPersoneelsImage', id:iid});
		
	});

	$('.pi-verwijderen').click(function(){
		var id = $(this).attr('iid');
		var ans = confirm("weet u zeker dat u deze foto wilt verwijderen?");
		
		if(ans == 1){
			$.post("inc/ws.php",{m:'delPersoneelsImage', id:id},function(){
				alert("De afbeelding is verwijderd, de pagina word nu herladen.");			
				window.location.href = 'controlemployeeimages.php';
				window.location.reload;
			});
		}
		else{
			return false;
		}
	});
	
	$('.bewerken').click(function(){
		var me = $(this).attr("me");
		$('#upload-div').html('<form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form">'+
								'<input name="image_upload_box" type="file" id="image_upload_box" size="40" />'+
								'<input type="submit" name="submit" value="Upload image" />'+
								'<input name="me" type="hidden" value="'+ me +'" />'+
								'<input name="m" type="hidden" value="addHeader" />'+
								'<input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" />'+
								'</form>');
	});
	
	$('.verwijderen').click(function(){
		var me = $(this).attr("me");
		$('body').load('submit.php',{me:me, m:'delHeader'});
		
	});
	$('#slider-content img').each(function(){
		slides++;
	});
	
	$('#header-image-slider img:first').attr('src',$('#slider-content img:nth-child(1)').attr('src'));

	$('.gallery a').lightBox();
	
	setInterval ( "nextHeaderImage()", 7000 );
	
});

function nextHeaderImage(){
	pos++;
	var total = $('#slider-content').attr('total');
	if(pos <= total){
		$('#header-image-slider img:first').animate({opacity: '0.1'},500,function(){
			$('#header-image-slider img:first').attr('src',$('#slider-content img:nth-child('+pos+')').attr('src')).animate({opacity: '1'},500);
		});
	/* 
		$('#header-image-slider img:first').attr('src',$('#slider-content img:nth-child('+pos+')').attr('src'));
		$('#header-image-slider img:first').fadeIn("fast");*/
	} 
	else{
		$('#header-image-slider img:first').attr('src',$('#slider-content img:nth-child(1)').attr('src'));
		pos = 1;
	}
	
}
























