

/* ------------------------------------------------------
Image Switcher
------------------------------------------------------ */

//	This code adds a z-index to each image for easy switching, good for approx 5000/x rotations, x being total images in rotation.






//	Counter starts here
//	-------------------------------------------
//	n = counter
//	i = interval timer
//	t = timer for switch
//	x = item to switch
//	f = fade time	<- feel free to edit below
// 	e = total elements per node
//	ec = element counoter

function switcher(x, t){
	
	$(x+" img").each(function(){
		var imgeq = $(this).index();
		var zindex = (5000) - (imgeq);
		$(this).css("z-index", zindex);
	});

	var e = $(x+" img").length;
	var ec = 0;
	var f = (t) / (10);
	
	setInterval(function(){	
			if (ec == e){
				ec = 0;
			}		 

		$(x+" img").eq(ec).fadeOut(f);
			var prev = ec - (1);
			if (prev < 0) {var prev = e;}
			var zdx =  $(x+" img").eq(prev).css("z-index");
			var zdxmod = (zdx) - (e + 10);
			$(x+" img").eq(prev).css("z-index", zdxmod).show();
		// element counter reset
			ec++;
	 }, t);
}

//	activeate the switchers, switcher(target, delay);

switcher("#slider", 4250);

