var fotosArray = new Array();
var cisloFoto = -1;
function rndImage(cacheArray){
	var arraysize = cacheArray.length;
	cisloFoto = cisloFoto+1;
	if(cisloFoto > arraysize-1){cisloFoto = 0;}
	return cacheArray[cisloFoto];
}
function cacheIt(cacheArray){
	//cache the images
	var cache = new Array();
	var imgsLen = cacheArray.length;
	for(var i=0; i<imgsLen; i++)
	{
		cache[i] = new Image;
		cache[i].src = cacheArray[i];
	}
	return cache;
}

function swapIt(arrayString,id,idUpper,unshow,first){
	var newImg = rndImage(fotosArray[arrayString]);
	var imgUpper = document.getElementById(idUpper);
	var img = document.getElementById(id);
	if(unshow == 'true'){
		img.src = newImg.src;
	}else{
		imgUpper.src = newImg.src;
	}
	//alert(img.src);
	//alert(imgUpper.src);
	setTimeout("realSwap('"+arrayString+"','"+id+"','"+idUpper+"','"+unshow+"','0');",50);
	var odkaz = newImg.src.substr(newImg.src.lastIndexOf('/')).replace("_thumb.jpg","");
	img.onclick = function(){winOpen(base+'/foto/'+arrayString+'/'+odkaz+'/');return false;}
	imgUpper.onclick = function(){winOpen(base+'/foto/'+arrayString+'/'+odkaz+'/');return false;}
}
function realSwap(arrayString,id,idUpper,unshow,step){
	var imgUpper = document.getElementById(idUpper);

	if(unshow != 'false'){var realShow = 100-step;;}else{var realShow = step;}
	var styleValue = 'opacity: '+(realShow/100)+';filter: alpha(opacity='+realShow+');-moz-opacity: '+(realShow/100)+';-khtml-opacity: '+(realShow/100)+';';
	//alert(styleValue);
	//if(realShow == 0){styleValue += 'visibility:hidden;';}else{styleValue += 'visibility:visible;';}
	//alert(idUpper);
	imgUpper.style.cssText =styleValue;

	//alert(imgUpper.getAttribute('id') +" - " +imgUpper.className);
	if(step == 100){
		if(unshow == 'true'){unshow = 'false';}else{unshow = 'true';}
		setTimeout("swapIt('"+arrayString+"','"+id+"','"+idUpper+"','"+unshow+"','false');",3000);
	}else{
		step = (step)*1 + 5;
		setTimeout("realSwap('"+arrayString+"','"+id+"','"+idUpper+"','"+unshow+"','"+step+"');",50);
	}
}

