//var files_path = "./img/anim/";
var img_count = 3;
var img_curent = 0;
var imgs_loaded = 0;

var is_process = false;
var anim_timeout = 6000;

var animImg = null;

function init_animation() {

	if (!files_path) return;
	
	animImg = document.getElementById("animImg");
	
	var eval_str = "";
	for(i = 0; i < img_count; i++) {
		eval_str = "imageObj_" + i + " = new Image();";
		eval(eval_str);
		
		eval_str = "imageObj_" + i + ".src = files_path + i + \".jpg\";";
		eval(eval_str);
		
		eval_str = "imageObj_" + i + ".onLoad = count_loaded_imgs();";
		eval(eval_str);
	}
}

function count_loaded_imgs() {
	imgs_loaded++;
	if (imgs_loaded == img_count) {
		imgages_loaded();
		fade_image();
	}
}

function imgages_loaded() {
	get_image(img_curent);
}

function get_image(step) {

	opacity_value = 10;
	opacity_direction = -1;
	fade_image();
	
	if (img_curent + step >= img_count) {
		img_curent = 0;
	} else {
		img_curent = img_curent + step;
	}
	var eval_string = "imageObj_" + img_curent;
	animImg.src = eval(eval_string + ".src");

	setTimeout("get_image(" + 1 + ")", anim_timeout);

	return false;
}

opacity_value = 10;
opacity_direction = -1;
function fade_image() {
	animImg.style.opacity = opacity_value/10;
	animImg.style.filter = 'alpha(opacity=' + opacity_value*10 + ')';
	if (opacity_direction == -1) {
		opacity_value--;
		if (opacity_value < 0) {
			opacity_direction = 1;
			opacity_value = 0;
		}
	}
	if (opacity_direction == 1) {
		opacity_value++;
		if (opacity_value > 10) {
			//opacity_direction = -1;
			opacity_value = 10;
		}
	}
	//setTimeout("fade_image()", anim_timeout/15);
	setTimeout("fade_image()", 50);
}

//document.onLoad = init_animation();
