var testa_img = null;
var ImgNew = null;

var agt=navigator.userAgent.toLowerCase();
var is_gecko = (agt.indexOf('gecko') != -1);
var is_ie    = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_opera = (agt.indexOf("opera") != -1);

var count = 1;

function InizializeSlider(){ 
	testa_img = document.getElementById("testa_foto");
	testa_img.src = imgar[0];
	setTimeout('imageChange()', timer);
}

function imageChange()
{
	ImgNew = document.createElement("IMG");
	
	ImgNew.onload = function() { 		
		opacityOff();
	};
	ImgNew.src = imgar[count];
	count++;
	if(count > imgar.length - 1)
		count = 0;
}

function opacityOff()
{
	if((testa_img.style.opacity!=70) && (parseFloat(testa_img.style.opacity)>0.7))
	{
		if (is_ie)
		{
			testa_img.filters[0].opacity=testa_img.filters[0].opacity-3;
		} 
		testa_img.style.opacity=parseFloat(testa_img.style.opacity)-0.03;
		setTimeout('opacityOff()', 1);
	} else {
		setImage();
	}
}

function opacityOn()
{
	if((testa_img.style.opacity!=100) && (parseFloat(testa_img.style.opacity)!=1))
	{
		if (is_ie)
		{
			testa_img.filters[0].opacity=testa_img.filters[0].opacity+3;
		} 
		testa_img.style.opacity=parseFloat(testa_img.style.opacity)+0.03;
		setTimeout('opacityOn()', 1);
	} else {
		ImgNew = null;
		setTimeout('imageChange()', timer);
	}
}

function setImage()
{
	testa_img.src = ImgNew.src;
	opacityOn();
}