var selectFoto = 0;
var alphaFoto = 0;

var timerFotoAlpha = null;
var timerFoto = null;

function loadFotos() {
	if (listFoto.length>1) {
		for(i=1; i<listFoto.length; i++) {
			loadImage(listFoto[i]);
		}
	}

	timerFoto=setInterval('smenaFoto();', 4000);
}
function smenaFoto() {
	if (loadImages.length==listFoto.length-1 && document.getElementById('foto1')) {
		alphaFoto=100;
		timerFotoAlpha=setInterval('smenaFotoAlpha(-5);', 30);
	}
}
function smenaFotoAlpha(a) {
	alphaFoto+=a;
	ElementAlpha('foto1', alphaFoto);
	if (alphaFoto<=0) {
		clearInterval(timerFotoAlpha);

		selectFoto++;
		if (selectFoto==listFoto.length) selectFoto=0;

		document.getElementById('foto1').style.background='url('+listFoto[selectFoto]+') no-repeat center center';

		timerFotoAlpha=setInterval('smenaFotoAlpha(5);', 30);
	} else if (alphaFoto>=100) {
		clearInterval(timerFotoAlpha);
	}
}

Browser={
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  };

function ElementAlpha(id, a) {
	d=document.getElementById(id).style;
	af=a>99?1:'.'+(a<10?'0'+a:a);
	if (Browser.Opera) {
		d.opacity=af;
	} else if (Browser.Gecko) {
		d.MozOpacity=af;
	} else if (Browser.WebKit) {
		d.KhtmlOpacity=af;
	} else {
		d.filter='alpha(opacity='+a+')';
	}
}

var loadImages = [];
function loadImage(src, func) {
	u=loadImages.length;
	loadImages[u] = { file: null };
	loadImages[u].file = new Image();
	loadImages[u].file.src = src;
	if (func) loadImages[u].file.onload = func;
}

