function change_image(el, to, isLast) {
	$(function () {
	  var img = new Image();
	  
	  // wrap our new image in jQuery, then:
	  $(img).load(function () {
	      $(this).hide();
	      $('#' + el).empty();
	      $('#' + el).append(this);
	      $(this).fadeIn(1200);
	    }).attr('src', to);
	});
	
	if(isLast == true) {
		block++;
		if(block == 4) {
			block = 0;
			setTimeout( function() { startImageSlides(); },6000);
		} else {
			setTimeout( function() { startImageSlides(); },1200);
		}
	}
};
		
var count = 0;
var block = 0;
		
function startImageSlides() {
	count++;
	var next = count + 1;
	if(next == 3) next = 0;
	if(count == 3) {
		count = 0;
		next = 1;
	}
	
	
	//alert(to);
	var pickList = Math.floor(Math.random()*6);
	
	switch (block) {
		case 0:
			var from = imageArray_1[count];
			var to = imageArray_1[next];
		break;
		case 1:
			var from = imageArray_2[count];
			var to = imageArray_2[next];
		break;
		case 2:
			var from = imageArray_3[count];
			var to = imageArray_3[next];
		break;
	}
	
	
	
	n1 = positions[orders[pickList][0]]; //alert("n1" + n1);
								change_image("image_slot_" + block + n1, "gfx/2x2/pic_" + to + n1 + ".png", false);
								
	n2 = positions[orders[pickList][1]]; //alert("n2" + n2);
	setTimeout( function() { 	change_image("image_slot_" + block + n2, "gfx/2x2/pic_" + to + n2 + ".png", false);}, 300);

	n3 = positions[orders[pickList][2]]; //alert("n3" + n3);
	setTimeout( function() { 	change_image("image_slot_" + block + n3, "gfx/2x2/pic_" + to + n3 + ".png", true);}, 600);						
}
