var picts = new Array();
var ua = navigator.userAgent;
var porder = new Array(0, 3, 1, 5, 2, 4);
var pcurr = 0;

document.getElementById('homepicts0').style.backgroundImage = 'url(/picts/' + galleries[0][0] + ')';
document.getElementById('homepicts1').style.backgroundImage = 'url(/picts/' + galleries[1][0] + ')';
document.getElementById('homepicts2').style.backgroundImage = 'url(/picts/' + galleries[2][0] + ')';
document.getElementById('homepicts3').style.backgroundImage = 'url(/picts/' + galleries[3][0] + ')';
document.getElementById('homepicts4').style.backgroundImage = 'url(/picts/' + galleries[4][0] + ')';
document.getElementById('homepicts5').style.backgroundImage = 'url(/picts/' + galleries[5][0] + ')';

if (ua.indexOf('Gecko') > 0) {	
	for (var g = 0; g < 6; g++) {
		var canvas = document.createElement('canvas');
		canvas.setAttribute('id', 'canvas' + g);
		canvas.setAttribute('width', '66');
		canvas.setAttribute('height', '66');
		document.getElementById('homepicts' + g).appendChild(canvas);


		var pict = new Image();
		pict.src = '/picts/' + galleries[g][1];
		pict.gallery = g;

		pict.set_alpha = function(v) {
			var ctx = document.getElementById('canvas' + this.gallery).getContext('2d');
			ctx.globalAlpha = v / 100;
		}

		pict.cpict = 1;
		pict.ppause = 15;
		pict.inum = null;
		pict.lnflag = false;
		pict.calpha = 0;

		picts.push(pict);
	}		
}
else {
	for (var g = 0; g < 6; g++) {
		var pict = document.createElement('img');
		pict.setAttribute('src','/picts/' + galleries[g][1]);
		pict.setAttribute('width', '66');
		pict.setAttribute('height', '66');
		pict.className = 'imgtrans';
		pict.setAttribute('alt', '');

		pict.set_alpha = function(v) {
			v = (v == 100)?99.999 : v;

			this.style.filter = "alpha(opacity:"+ v +")";
			this.style.KHTMLOpacity = v/100;
			this.style.MozOpacity = v/100;
			this.style.opacity = v/100;
		}

		pict.cpict = 1;
		pict.ppause = 15;
		pict.inum = null;
		pict.lnflag = false;
		pict.calpha = 0;

		document.getElementById('homepicts' + g).appendChild(pict);

		picts.push(pict);
	}
}

inum = setInterval('pfSwitch()',50);

function pfSwitch() {	
	var g = porder[pcurr];

	if (!picts[g].complete) return;

	if (picts[g].ppause > 0) {
		if ((picts[g].ppause < 10) && picts[g].lnflag) {
			picts[g].set_alpha(0);
			picts[g].src = "/picts/" + galleries[g][picts[g].cpict]; 
			picts[g].lnflag = false;
		}

		picts[g].ppause--;			
		return;
	}

	picts[g].set_alpha(picts[g].calpha);
	picts[g].calpha+=5;

	var ctx = (picts[g].gallery >= 0) ? document.getElementById('canvas' + g).getContext('2d') : null;

	if (ctx != null) {
	      ctx.clearRect(0,0,66,66);
	      ctx.globalAlpha = picts[g].calpha / 100;
	      ctx.drawImage(picts[g],0,0);
	}

	if (picts[g].calpha >= 100) {
		document.getElementById('homepicts' + g).style.backgroundImage = 'url(/picts/' + galleries[g][picts[g].cpict] + ')';

		picts[g].cpict++;
		if (picts[g].cpict == galleries[g].length) picts[g].cpict = 0;

		picts[g].calpha = 0;
		picts[g].ppause = 40;
		picts[g].lnflag = true;

		pcurr++;
		if (pcurr > 5) pcurr = 0;
	}
}
