var image_act = '';
var image_new = '';
var image_index = 0;
var stop_fade = 0;
var active = 0;
function setImage(id) {
	//alert('image_'+id + ' ' + image_act);
	if ('image_'+id != image_act) {
		for (i=0;i<product_images.length;i++) {
			document.getElementById(product_images[i]).style.display = 'none';
		}
		image_act = 'image_'+id;
		document.getElementById(image_act).style.display = 'inline';
		image_index = getImageIndex();
		clearTimeout(active);
		slide();
	}
}


var waiting = 4000;
var fade_waiting = 30;
var interval = 5;
var counter = 1;

var product_images = new Array();


function getImageIndex() {
	for (i=0;i<product_images.length;i++) {
		if (image_act == product_images[i]) {
			return i;
			break;
		}
	}
	return 0;
}

function slide() {
	if (product_images.length>1) {
		//stop_fade = 0;
		//image_act = product_images[image_index];
		image_new = product_images[image_index+1];
		if (!image_new) {
			image_new = product_images[0];		
		}
		fullView();
		//alert(image_act + ' ' + image_new);
		document.getElementById(image_new).style['zIndex'] = '1';	
		document.getElementById(image_act).style['zIndex'] = '10';
		document.getElementById(image_new).style.display = 'none';
		document.getElementById(image_act).style.display = 'inline';
		//alert(waiting);
		active=window.setTimeout("initFading()",waiting);
	}
}
function initFading() {
	document.getElementById(image_new).style.display = 'inline';
	fadeImages();
}
function fullView() {
	document.getElementById(image_act).style['opacity'] = 1;
	document.getElementById(image_act).style['filter'] = "alpha(opacity=100)";
	document.getElementById(image_new).style['opacity'] = 1;
	document.getElementById(image_new).style['filter'] = "alpha(opacity=100)";
}
function fadeImages() {
	var value = interval / 100 * counter; 
	var value2 = interval * counter;
	var op = 1 - value;
	var op2 = 0 + value;
	var op_ie = 100 - value2;
	var op_ie2 = 0 + value2;
	if (op > 0) {
		//alert(image_act + ' ' + image_new);
		counter ++;
		document.getElementById(image_act).style['opacity'] = op;
		document.getElementById(image_act).style['filter'] = "alpha(opacity="+op_ie+")";
		document.getElementById(image_new).style['opacity'] = op2;
		document.getElementById(image_new).style['filter'] = "alpha(opacity="+op_ie2+")";
		active = window.setTimeout("fadeImages()",fade_waiting);	
	}
	else {
		//alert(image_act);
		document.getElementById(image_act).style['display'] = "none";
		counter = 1;
		image_index ++;
		if (image_index >= product_images.length) {
			image_index = 0;
		}
		image_act = image_new;
		slide();
	}
	//document.getElementById('img_'+part2).style['opacity'] = 0 + value;	
}
function showProductText (id) {
	document.getElementById(id).style['display'] = 'block';	
	document.getElementById(id+'_bg').style['display'] = 'block';	
}
function hideProductText (id) {
	document.getElementById(id).style['display'] = 'none';	
	document.getElementById(id+'_bg').style['display'] = 'none';	
}
