


var SABLONA_KOMPONENTA_KATALOG_ZBOZI = new function () {



this.tridaKomponenta = "komponentaZbozi";
this.tridaPolozka = "polozka";
this.intervalPrepinaniMs = 6000;
this.intervalEfektuMs = 50;



this.komponentyNaStrance = [];
this.iteratory = [];
this.poctyPolozek = [];
this.poctyZobrazovanych = [];
this.efektFaze = 0;



this.inicializuj = function ()
{

	// ziskej vsechny komponenty-zbozi na strance
	var kolekce = window.document.body.getElementsByTagName("div");
 	for(var klic in kolekce)
 	{
		if(
			kolekce[klic].className &&
			kolekce[klic].className.indexOf(this.tridaKomponenta) != -1
		)
		{
			var komponenta = kolekce[klic];
			var pocetPolozek = this.ziskejPolozkyKomponenty(komponenta).length;
			var pocetZobrazovanych = this.ziskejParametr(komponenta, "animace") - 0;
			if(pocetZobrazovanych > 0)
			{
				this.komponentyNaStrance.push(komponenta);
				this.iteratory.push(0);
				this.poctyPolozek.push(pocetPolozek);
				this.poctyZobrazovanych.push(pocetZobrazovanych);
			}
		}
	}

	// animuj
	window.setTimeout(
		"window.SABLONA_KOMPONENTA_KATALOG_ZBOZI.animujPrepinani();", 1);

}



this.ziskejParametr = function (komponenta, nazevParametru)
{
	if(! komponenta.className)
	{
		return "";
	}
	nazevParametru += "_";
	var trida = komponenta.className;
	var pozice = trida.indexOf(nazevParametru);
	if(pozice < 0)
	{
		return "";
	}
	pozice += nazevParametru.length;
	trida = trida.substring(pozice);
	pozice = trida.indexOf(" ");
	if (pozice < 0)
	{
		return trida;
	}
	return trida.substring(0, pozice);
}



this.ziskejPolozkyKomponenty = function (komponenta)
{
	var polozky = [];
	var kolekce = komponenta.getElementsByTagName("div");
 	for(var klic in kolekce)
	{
		if(
			kolekce[klic].className &&
			kolekce[klic].className.indexOf(this.tridaPolozka) != -1
		)
		{
			polozky.push(kolekce[klic]);
		}
	}
	return polozky;
}



this.nastavViditelnostPolozek = function (
	komponenta, prvniZobrazena, pocetZobrazenych)
{
	var polozky = this.ziskejPolozkyKomponenty(komponenta);
 	for(var i = 0; i < polozky.length; i ++)
	{
		if (
			i >= prvniZobrazena &&
			i < prvniZobrazena + pocetZobrazenych
		)
		{
			polozky[i].style.display = "block";
		}
		else
		{
			polozky[i].style.display = "none";
		}
	}
}



this.animujPrepinani = function ()
{

	// zpracuj vsechny komponenty na strance
	for(var i = 0; i < this.komponentyNaStrance.length; i ++)
	{

		// nastav viditelnost polozek
		this.nastavViditelnostPolozek(
			this.komponentyNaStrance[i],
			this.iteratory[i],
			this.poctyZobrazovanych[i]);

		// inkrementuj iteratory
		this.iteratory[i] += this.poctyZobrazovanych[i];
		if(this.iteratory[i] > this.poctyPolozek[i] - this.poctyZobrazovanych[i])
		{
			this.iteratory[i] = 0;
		}

	}

	// animuj
	window.setTimeout(
		"window.SABLONA_KOMPONENTA_KATALOG_ZBOZI.animujPrepinani();",
		this.intervalPrepinaniMs);
	window.setTimeout(
		"window.SABLONA_KOMPONENTA_KATALOG_ZBOZI.animujEfekt();",
		this.intervalPrepinaniMs - (5 * this.intervalEfektuMs));

}



this.nastavPruhlednostKomponent = function (pruhlednost)
{
	pruhlednost = Math.max(0, Math.min(100, pruhlednost));
	for(var i = 0; i < this.komponentyNaStrance.length; i ++)
	{
		var komponenta = this.komponentyNaStrance[i];

		// animuj nazvy zbozi (h2)
		var kolekce = komponenta.getElementsByTagName("h2");
		for(klic in kolekce)
		{
			var prvek = kolekce[klic];
			if(prvek.style)
			{
			  prvek.style.opacity = pruhlednost/100;
	  		prvek.style.filter = "Alpha(Opacity="+pruhlednost+")";
	  	}
	  }

		// animuj obrazky (img)
		kolekce = komponenta.getElementsByTagName("img");
		for(klic in kolekce)
		{
			var prvek = kolekce[klic];
			if(prvek.style)
			{
			  prvek.style.opacity = pruhlednost/100;
	  		prvek.style.filter = "Alpha(Opacity="+pruhlednost+")";
	  	}
	  }

		// animuj panel stav (div.stav)
		/*
		kolekce = komponenta.getElementsByTagName("div");
		for(klic in kolekce)
		{
			var prvek = kolekce[klic];
			if(
				prvek.style &&
				prvek.className &&
				prvek.className.indexOf("stav") != -1
			)
			{
			  prvek.style.opacity = pruhlednost/100;
	  		prvek.style.filter = "Alpha(Opacity="+pruhlednost+")";
	  	}
	  }
	  */

	}
}



this.animujEfekt = function ()
{
	var pruhlednost = Math.abs((2 * this.efektFaze) - 100);
	this.nastavPruhlednostKomponent(pruhlednost);
	this.efektFaze += 10;
	if(this.efektFaze <= 100)
	{
		window.setTimeout(
			"window.SABLONA_KOMPONENTA_KATALOG_ZBOZI.animujEfekt();",
			this.intervalEfektuMs);
	}
	else
	{
		this.efektFaze = 0;
	}
}



}



if (SABLONA_XHTML)
{
	SABLONA_XHTML.pridejInicializator(
		"SABLONA_KOMPONENTA_KATALOG_ZBOZI.inicializuj ();");
}



