var last=-1;
var interval=10001;

window.onload=function(){
	try{
		if (foto_dna.length>0){
			var ti=document.getElementById("tmp_i");
			ti.style.marginTop=(navigator.appName=="Microsoft Internet Explorer"?"-125px":"-112px");

			setTimeout('obr()',interval);
		}
		try{
			hybac();
		}catch (x){
		}
	}catch (e){
		alert(e);
	}
}

//nove okno, ubytovanie
function ub(id, hr){
	var w=850,
		h=720;

	var x=(screen.width/2)-(w/2),
		y=(screen.height/2)-(h/2);

	//"/ubytovanie/"+id+"/"
	window.open(hr,"","height="+h+", width="+w+", left="+x+", top="+y+", location=no, scrollbars=yes");
}

function ok(){
	var ti=document.getElementById("tmp_i");
	var ia=document.getElementById("i_foto_dna");
	ia.src=ti.src;
	ia.alt=ia.title=foto_dna[last][0]+", autor: "+foto_dna[last][1];
	
	ti.style.display="none";
	document.getElementById("a_odkaz").href="/"+foto_dna[last][2]+".0/"+foto_dna[last][4]+"/";
	setTimeout("obr()",interval);
}

function zobraz(obr){
	last=obr;
	foto_dna[obr][5]=true;
	var ti=document.getElementById("tmp_i");
	t("tmp_i",0);
	ti.src="/i/clanky/m_den_"+foto_dna[obr][3];
	ti.style.display="";
	
	for (var i=0;i<=100;i+=10)
		setTimeout('t("tmp_i",'+i+')',(i+1)*5);
}

function obr(){
	var ok=false;
	for (var i=0;i<foto_dna.length;i++)
		if (!foto_dna[i][5]){
			ok=true;
			break;
		}
	
	var novy_obr;
	
	if (ok){
		do{
			novy_obr=Math.ceil(Math.random()*foto_dna.length)-1;
		}while (foto_dna[novy_obr][5]);
		zobraz(novy_obr);
	}else{
		for (var i=0;i<foto_dna.length;i++)
			foto_dna[i][5]=false;
		
		do{
			novy_obr=Math.ceil(Math.random()*foto_dna.length)-1;
		}while (novy_obr==last && foto_dna.length>1);
		zobraz(novy_obr);
	}
}

function t(a,b){
	try{
		var a=document.getElementById(a);
		a.style.opacity=b/100;
		a.style.MozOpacity=b/100;
		a.style.KhtmlOpacity=b/100;
		a.style.filter="alpha(opacity="+b+")";
		if (b==100)
			ok();
	}catch (e){
	}
}