// navigace
activateMenu = function(nav) {
	if (document.all && document.getElementById(nav).currentStyle) {
		var navroot = document.getElementById(nav);
		var lis=navroot.getElementsByTagName("LI");  
		for (i=0; i<lis.length; i++) {
			if(lis[i].lastChild.tagName=="UL"){	
				lis[i].onmouseover=function() {		
					this.lastChild.style.display="block";
					}
				lis[i].onmouseout=function() {                       
					this.lastChild.style.display="none";
					}
				}
			}
		}
	}

// inicializace navigace
window.onload= function() {
	activateMenu('vertnav');
	runIndexProds();
	runTicker();
	}

// popup obrázky
function popup(sPicURL, sPicDesc) { 
	window.open( "./popup.asp?IMG=" + sPicURL + "&DSC=" + sPicDesc, "imgWin", "height=100,menubar=0,personalbar=0,resizable=1,scrollbars=0,status=0,toolbar=0,width=100"); 
	}

function runTicker() {	
	tickers = Array();
	objs = document.getElementsByTagName("LI");
	for(i = 0; i < objs.length; i++) {
		if(objs[i].className.indexOf("ticker") >= 0) {
			tickers[tickers.length] = objs[i];
		}
	}
	if(tickers.length > 0) {
		actLine = 0;
		tickerSpeed = 1500;
		ticker();
	}
}

function ticker() {
	tickers[actLine].style.display = "none";
	if(actLine < (tickers.length - 1)) actLine++; else actLine = 0;
	tickers[actLine].style.display = "block";
	setTimeout("ticker()",tickerSpeed);
}

/**
 * iniciuje toceni produktu na HP
 */
function runIndexProds() {
	if(ul = document.getElementById("indexProds")) {
		prods = Array();
		fakes = "";
		fakesCnt = 0;
		/* nacteni li elementu */
		for(i = 0; i < ul.childNodes.length; i++) {
			if(ul.childNodes[i].className) {
				if(ul.childNodes[i].className.indexOf("indexItem") != -1) {
					prods[prods.length] = ul.childNodes[i];
				}
				if(ul.childNodes[i].className.indexOf("fake") != -1) {
					fakes += ul.childNodes[i].id + ",";
					fakesCnt++;
				}
			}
		}
		/* zakladni parametry */
		prodsNum = prods.length - fakesCnt;
		prodsPerPage = (prodsNum > 10) ? 10 : prodsNum;
		indexProdsSpeed = 5000; // rychlost stridani v ms
		if(prodsNum > 0) {
			setTimeout("indexProds(1);", indexProdsSpeed); // spustit
		}
	}
}

/**
 * cyklus otaceni produktu na HP
 */
function indexProds(p) {
	// schovat starou
	lastItem = (p > 0) ? p - 1 : (prodsNum - 1);
	if(sstr = prods[lastItem].className.indexOf(" emph")) {
		prods[lastItem].className = prods[lastItem].className.substring(0, sstr) + " hide";
	}
	// zobrazit dalsi
	prods[p].className += " emph";
	// zobrazit 1. skrytou, cekajici na seznam
	if((p + (prodsPerPage - 1)) < prods.length) {
 		if(sstr = prods[p + (prodsPerPage - 1)].className.indexOf(" hide")) {
			prods[p + (prodsPerPage - 1)].className = prods[p + (prodsPerPage - 1)].className.substring(0, sstr);
		}
	}
	
	if(p < (prodsNum - 1)) {
		// inkrementace
		p++;
	} else {
		// konec cyklu toceni (reset na zakladni verzi)
		setTimeout("resetIndexProds()", indexProdsSpeed);
		setTimeout("indexProds(1)", indexProdsSpeed * 2);
		return;
	}
	setTimeout("indexProds(" + p + ")", indexProdsSpeed);
}

/**
 * uvadi produkty na HP do defaultni podoby
 */
function resetIndexProds() {
	// prirazuje tridy podle pozice v seznamu
	for(i = 0; i < prods.length; i++) {
		if(!i) {
			prods[i].className = "indexItem emph";
		} else if(i < prodsPerPage) {
			prods[i].className = "idnexItem";
		} else if(i >= prodsPerPage && i < prodsNum) {
			prods[i].className = "idnexItem hide";
		} else if(i >= prodsNum) {
			prods[i].className = "idnexItem fake hide";
		}
	}
}

