let count = 21,
	act_slides = []
for (n=1; n<=count; n++){
	act_slides.push(`${n.toString().padStart(2, '0')}.jpg`)
}

// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
function actusSlider( target, args ){
	target = target || '#actus-slider'
	args = args || {}
	let mode 			= args.mode 	|| 'random'
	let motion			= args.motion 	|| 'random'
	let transitionTime 	= args.transitionTime || 5	// seconds
	let duration		= args.duration 	  || 25	// seconds
	let durationOff		= args.durationOff 	  || 20	// percentage
	let path = 'img/slides/'
	
	let motionTypes = ['zoom', 'l-r', 'r-l']
	
	let $slider = $( target )
	if ( ! $slider.length ) return;
	if ( !act_slides || ! act_slides.length ) return;
	
	
	let current = -1;
	let $current,
		$allSlides;
	
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	createSlides()
	setTimeout( start, 3000)
	
	
	
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	function createSlides(){
		$allSlides =
			$('<div id="all-slides">').appendTo( $slider )
		act_slides.forEach((src,idx)=>{
			let slide = $('<img>')
				.addClass('slide-'+idx)
				.attr('src', path+src)
				.css('opacity', 0)
				.css('transition', `${transitionTime}s opacity, ${duration}s transform linear`)
				.appendTo( $allSlides )
		})
	}
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	function start(){
		new Slide()
	}
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	function getNext(){
		let next
		if ( mode == 'random' ) {
			next =
				Math.floor(Math.random() * act_slides.length);
		} else {
			next++
			if (next > act_slides.length) next = 0
		}
		if (next == current) next = getNext()
		
		current = next
		
		return next;
	}
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	function Slide(){
		let idx = getNext()
		let $slide = $('#all-slides .slide-'+idx)
			.clone()
			.appendTo( $slider )
		
		
		
		// set motion type
		let motionType;
		if ( motion == 'random' )
			motionType = motionTypes[ Math.floor(Math.random() * motionTypes.length) ]
		else motionType = motion
		
		// set motion beginning
		if ( motionType == 'l-r' )
			$slide.css('transform', 'translate3d(-50%,0,0)')
		if ( motionType == 'r-l' )
			$slide.css('transform', 'translate3d(50%,0,0)')
		if ( motionType == 'zoom' )
			$slide.css('transform', 'scale(0.7)')
		
		
		
		
		// IN
		// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅
		setTimeout(r =>{
			// fade in
			$slide.css('opacity', 0.6)
		}, 50)
		
		
		
		// MOTION
		// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅
		setTimeout(r =>{
			if ( motionType == 'l-r' )
				$slide.css('transform', 'translate3d(50%,0,0)')
			if ( motionType == 'r-l' )
				$slide.css('transform', 'translate3d(-50%,0,0)')
			if ( motionType == 'zoom' )
				$slide.css('transform', 'scale(1.25)')
		}, 40)

		
		
		// OUT
		// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅
		setTimeout(r =>{
			
			// fade out
			$slide.css('opacity', 0)

			// remove slide
			setTimeout(r =>{
				$slide.remove();
			}, (transitionTime * 1000) + 100 )

			// next Slide
			setTimeout(rr =>{
				new Slide()
			}, 100)
			

		}, (duration - transitionTime) * 1000)
		
		
	}
	function slideIn( $slide ){
		setTimeout(r =>{
			// fade in
			$slide.css('opacity', 1)
		}, 1)
	}
	function slideOut( $slide ){
		
		// fade out
		$slide.css('opacity', 0)
		
		// remove slide
		setTimeout(r =>{
			$slide.remove();
		}, (transitionTime * 1000) + 100 )
	}
	
	// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
	function playback(){
		
	}
	
}





// ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
actusSlider('#actus-slider');