var currentTab = 1;
Array.prototype.shuffle=function(){var r,t,i=this.length;while(i>1)r=Math.random()*i-->>0,t=this[i],this[i]=this[r],this[r]=t;return this;};

function setupFade(){
	var pic = ['obrazky/rotace/foto01-n.jpg','obrazky/rotace/foto02-n.jpg', 'obrazky/rotace/foto03-n.jpg'].shuffle();
	var e_fade1 = document.getElementById('fade1');
	var e_fade2 = document.getElementById('fade2');
	var e_fade3 = document.getElementById('fade3');
	
	e_fade2.src = pic[0];
	
	var imgVisible=true; // whether or note e_fade2 has full opacity
	var thisPic=0;

	function doFade(){

		// save resources if not showing tab1
		if (currentTab!=1) {
			setTimeout(doFade, 4000);
			return;
		}
		
		thisPic = (thisPic+1)%pic.length;

		if (imgVisible)
			{
			e_fade1.style.backgroundImage = 'url('+pic[thisPic].src+')';
			e_fade1.style.backgroundPosition = '0px 0px';
			}
		else
			{
			/*
			var velky = pic[thisPic].src;
			velky = velky.substring(0, velky.length - 6)
			e_fade3.href = velky + '.jpg';
			*/
			e_fade2.src = pic[thisPic].src;
			}


		var i=0;
		var loopy=setInterval(function(){
		
			i++;
			
			if (imgVisible) {
				e_fade2.style.filter = 'alpha(opacity='+(100-5*i)+')';
				e_fade2.style.MozOpacity = 1-i/20;
				e_fade2.style.opacity = 1-i/20;
			}
			else {
				e_fade2.style.filter = 'alpha(opacity='+(5*i)+')';			
				e_fade2.style.MozOpacity = i/20;
				e_fade2.style.opacity = i/20;
			}
			
			if (i==20) {
				clearInterval(loopy);
				setTimeout(doFade, 4000);
				imgVisible=!imgVisible;
			}
		},35);

		
	}

	window.onload=function(){
		var temp;
		var n=0;
		for (var i=0; i<pic.length; i++) {
			temp = pic[i];
			pic[i]=new Image();
			pic[i].onload=function(){
				n++;
				if (n==pic.length) setTimeout(doFade, 1000);
			}
			pic[i].src = temp;
		}
		//setTimeout('fadeQuote()',3000);
	}
}

