function change_image(el, to, isLast) {
	$(function () {
		var img = new Image();
	 
		$(img).load(function () {
			$(this).hide();
	    	$('#' + el).find('.image_holder').empty();
			$('#' + el).find('.image_holder').append(this);
			$(this).fadeIn(600);
		}).attr('src', to);
	});
	
	if(isLast == true) {
		block++;
		if(block == 3) {
			block = 0;
			setTimeout( function() { startImageSlides(); },3000);
		} else {
			setTimeout( function() { startImageSlides(); },600);
		}
	}
};
		
var count1 = 0;
var count2 = 0;
var count3 = 0;

var block = 0;
		
function startImageSlides() {
	
	//alert(to);
	var pickList = Math.floor(Math.random()*6);
	
	switch (block) {
		case 0:
		
		count1++;
		var next = count1 + 1;
		if(next == imageArray_1.length) next = 0;
		if(count1 == imageArray_1.length) {
			count1 = 0;
			next = 1;
		}
		
		var from = imageArray_1[count1];
		var to = imageArray_1[next];
		break;
		
		case 1:
		count2++;
		var next = count2 + 1;
		if(next == imageArray_2.length) next = 0;
		if(count2 == imageArray_2.length) {
			count2 = 0;
			next = 1;
		}
		var from = imageArray_2[count2];
		var to = imageArray_2[next];
		break;
		
		case 2:
		count3++;
		var next = count3 + 1;
		if(next == imageArray_3.length) next = 0;
		if(count3 == imageArray_3.length) {
			count3 = 0;
			next = 1;
		}
		var from = imageArray_3[count3];
		var to = imageArray_3[next];
		break;
	}
	
	n1 = positions[orders[pickList][0]]; //alert("n1" + n1);
								change_image("image_slot_" + block + "_" + n1, "admin/uploads/" + n1 + "_" + to, false);
								
	n2 = positions[orders[pickList][1]]; //alert("n2" + n2);
	setTimeout( function() { 	change_image("image_slot_" + block + "_" +  n2, "admin/uploads/" + n2 + "_" + to, false);}, 200);

	n3 = positions[orders[pickList][2]]; //alert("n3" + n3);
	setTimeout( function() { 	change_image("image_slot_" + block + "_" +  n3, "admin/uploads/" + n3 + "_" + to, false);}, 200);	
	
	n4 = positions[orders[pickList][3]]; //alert("n3" + n3);
	setTimeout( function() { 	change_image("image_slot_" + block + "_" +  n4, "admin/uploads/" + n4 + "_" + to, true);}, 400);					
}
