/**
 * Zobrazovani navigace (filry)
 *
 * @autor Ondrej LUKAS (odik)
 */
//eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('F 7=G H();w 5(r,a,b){4=r.I;2(b){9.7[4.c]=b}x(i=0;i<4.j.z;i++){8=4.j[i];2(8.A.B()==\'8\'){n=1;e=k;x(y=0;y<8.j.z;y++){3=8.j[y];2(3.A.B()==\'3\'){2(3.d.q("f-5-e")>=0){8.J(3)}2(a){2(3.d.q("f-5-C")>=0){5(r);a=k;9.7[4.c]=k}l 2(n>6){3.s.t="D";e=g}}l 2(3.d.q("f-5-C")<0){2(9.7[4.c]===g){3.s.t=""}l{3.s.t="D"}}n++}}2(9.7[4.c]===g||a){r.d="f-5-K";9.7[4.c]=k}l{r.d="";9.7[4.c]=g}2(e){m=o.u("3");h=o.u("a");v=o.u("L");E=o.M("\\N Oší");m.d="f-5-e";h.P="#";h.Q=w(){5(r,R,g)};v.p(E);h.p(v);m.p(h);8.p(m)}}}}',54,54,'||if|li|parent|menu||isHide|ul|this|||id|className|next|side|true|nA||childNodes|false|else|nL||document|appendChild|indexOf||style|display|createElement|nS|function|for||length|nodeName|toLowerCase|selected|none|nT|var|new|Array|parentNode|removeChild|hover|span|createTextNode|u2026|dal|href|onclick|null'.split('|'),0,{}))





	// Pro uchovani v pameti, zda je navigace schovana ci rozbalena
	var isHide = new Array();
	
	
	// Vrat seznam `li`
	function getLists (ul) {
		var lists = new Array();
		for (var i = 0; i < ul.childNodes.length; i++) {
			var li = ul.childNodes[i];
			// Jestlize je potomek 'li'
			if (li.nodeName.toLowerCase() == "li") {
				lists[lists.length] = li;
			}
		}
		return lists;
	}
	// Ma menu zapnuty filtr?
	function isMenuActive(lists) {
		var active = false;
		for (var i = 0; i < lists.length; i++) {
			var li = lists[i];
			// Jestlize existuje vybrana polozka
			if (li.className.indexOf("side-menu-active") >= 0) {
				active = true;
			}
		}
		return active;
	}
	
	function menu(r, check, show)
	{
		// Prvek, ktery obaluje potrebnou cast navigace
		parentMenu = r.parentNode; // promenna 'parent' nejde v IE pouzit
		
		// Jestlize potrebuji vynutit zobrazeni
		if (show)
		{
			this.isHide[parentMenu.id] = show;
		}
		
		for (var i = 0; i < parentMenu.childNodes.length; i++)
		{
			var ul = parentMenu.childNodes[i];
			
			// Jestlize je potomek 'ul'
			if (ul.nodeName.toLowerCase() == 'ul') {
				var buttonAll = false;
				var buttonNext = false;
				var lists = getLists(ul);
				var isActive = isMenuActive(lists);
//alert(isActive);
				for (y = 0; y < lists.length; y++) {
//alert(y);
					var li = lists[y];
					// Jestlize existuje polozka ''
					if (li.className.indexOf("side-menu-all") >= 0) {
						ul.removeChild(li);
					}
					// Jestlize existuje polozka '... dalsi'
					if (li.className.indexOf("side-menu-next") >= 0) {
						// odstran polozku (zobrazuje se pouze na zacatku)
						ul.removeChild(li);
					}
					
					// Jestlize je vstupni kontrola
					if (check) {
						this.isHide[parentMenu.id] = true; // simulace, ze menu bylo PUVODNE schovano => na pristi onclick() bude schovano
						// Jestlize vybrana filtr
						if (isActive) {
							if (li.className.indexOf("side-menu-active") < 0) {
								li.style.display = "none"; // schovej polozku
							}
							this.isHide[parentMenu.id] = false; // simulace, ze menu bylo PUVODNE otevreno => na pristi onclick() bude otevreno
							buttonAll = true;
						}
						// Jestlize vice jak 7 polozek => od 6 nezobrazuj
						else if (lists.length > 7 && y >= 6) {
							li.style.display = "none"; // schovej ostatni filtry
							//this.isHide[parentMenu.id] = true; // simulace, ze menu bylo PUVODNE schovano => na pristi onclick() bude schovano
							buttonNext = true;
						}
					}
					// Jestlize polozka neni vybrana
					else if (li.className.indexOf("side-menu-active") < 0) {
						// Jestlize polozka byla schovana
						if (this.isHide[parentMenu.id] === true) {
							// zobraz polozku
							li.style.display = "";
						}
						// Jestlize polozka byla zobrazena
						else {
							// schovej polozku
							li.style.display = "none";
						}
					}
					else {
						if (this.isHide[parentMenu.id] !== true) {
							buttonAll = true; // pokud vybran filtr - rozbali a zase schova => zobraz
						}
					}
					// Jestlize jedna polozka => nezobrazuj tlacitko
					if (lists.length === 1) {
						buttonAll = false;
					}
				}
				
				// Nastaveni stavu zobrazeni
//				if (this.isHide[parentMenu.id] === true || check)
				if (this.isHide[parentMenu.id] === true) {
//r.childNodes[1].style.backgroundPosition = "-190px -1px";
					r.className = "hover";
					this.isHide[parentMenu.id] = false;
				}
				else
				{
//r.childNodes[1].style.backgroundPosition = "";
					r.className = "";
					this.isHide[parentMenu.id] = true;
				}
				setcookie(parentMenu.id, this.isHide[parentMenu.id], 1); // uloz do cookies
				
				
				var buttonNextText;
				// Kategorie nemaji mit 'zrusit' => pouzije se 'dalsi' ... `strong` zustava => na kliknuti se otevre nabidka 
				if (parentMenu.id === "side-menu-category" && buttonAll) {
					buttonAll = false;
					buttonNext = true;
					buttonNextText = "Všechny kategorie";
				}
				// Jestlize ma byt zobrazena polozka 'dalsi'
				if (buttonNext)
				{
					// vzor: <li class=""><a href="#"><span>&hellip; další</span></a></li>
					var nL = document.createElement("li");
					nL.className = "side-menu-next";
					//nA = document.createElement("a");
					var nA = document.createElement("span");
					nA.className = "a cursor-hand";
					switch (parentMenu.id)
					{
					case "side-menu-category":
						nA.className += " side-all-category";
						if (!buttonNextText)
						{
							buttonNextText = "Další kategorie";
						}
						break;
					case "side-menu-occasion":
						nA.className += " side-all-occasion";
						buttonNextText = "Další příležitosti";
						break;
					default:
						buttonNextText = "\u2026 další"; // alert("…".charCodeAt(0).toString(16)); // 2026
						break;
					}
					nA.onclick = function() { menu(r, null, true) }; // po kliknuti rozbal navigaci
					var nS = document.createElement("span");
					var nT = document.createTextNode(buttonNextText);
					//nT = document.createTextNode("\u2026 další"); // alert("…".charCodeAt(0).toString(16)); // 2026

					//nL.className = "side-menu-next";
//					nA.href = "#";
					//nA.className = "a cursor-hand";
					//nA.onclick = function() { menu(r, null, true) }; // po kliknuti rozbal navigaci
					
					nS.appendChild(nT);
					nA.appendChild(nS);
					nL.appendChild(nA);
					ul.appendChild(nL);
				}
				// Jestlize ma byt zobrazena polozka 'zmenit'
				else if (buttonAll)
				{
					var nL = document.createElement("li");
					nL.className = "side-menu-all";
					var nA = document.createElement("span");
					nA.className = "a cursor-hand";
					nA.onclick = function() { menu(r, null, true) }; // po kliknuti rozbal navigaci
					var nS = document.createElement("span");
					var nT = document.createTextNode("Změnit výběr");
					
					nS.appendChild(nT);
					nA.appendChild(nS);
					nL.appendChild(nA);
					ul.appendChild(nL);
				}

			}
		}
	}
















	
	
	// ukladani cookies - pokud si "zavru" side-menu ... chtel bych, aby si ho to pamatovalo i na dalsi strance
	function getExpiresDate(hours)
	{
		today = new Date();
		today.setTime(today.getTime() + hours * 60 * 60 * 1000);
		return today.toGMTString()
	}
	function setcookie(name, value, duration)
	{
		document.cookie = name + "=" + escape(value) + ";expires=" + getExpiresDate(duration) + ";path=/";
	}
	function getcookie(name)
	{
		var cookiestring = "" + document.cookie;
		var index1 = cookiestring.indexOf(name);
		if (index1 == -1)
		{
			return false;
		}
		var index2 = cookiestring.indexOf(";", index1);
		if (index2 == -1)
		{
			index2 = cookiestring.length;
		}
		return unescape(cookiestring.substring(index1 + name.length + 1, index2));
	}



/*
	// Pro uchovani v pameti, zda je navigace schovana ci rozbalena
	var isHide = new Array();
	
	
	// Vrat seznam `li`
	function getLists (ul) {
		lists = new Array();
		for (i = 0; i < ul.childNodes.length; i++) {
			li = ul.childNodes[i];
			// Jestlize je potomek 'li'
			if (li.nodeName.toLowerCase() == "li") {
				lists[lists.length] = li;
			}
		}
		return lists;
	}
	
	function menu(r, check, show)
	{
		// Prvek, ktery obaluje potrebnou cast navigace
		parentMenu = r.parentNode; // promenna 'parent' nejde v IE pouzit
		
		// Jestlize potrebuji vynutit zobrazeni
		if (show)
		{
			this.isHide[parentMenu.id] = show;
		}
		
		for (i = 0; i < parentMenu.childNodes.length; i++)
		{
			ul = parentMenu.childNodes[i];
			
			// Jestlize je potomek 'ul'
			if (ul.nodeName.toLowerCase() == 'ul') {
				n = 1;
				next = false;
				for (y = 0; y < ul.childNodes.length; y++)
				{
					li = ul.childNodes[y];
					// Jestlize je potomek 'li'
					if (li.nodeName.toLowerCase() == 'li')
					{
						// Jestlize existuje polozka '... dalsi'
						if (li.className.indexOf("side-menu-next") >= 0) 
						{
							// odstran polozku (zobrazuje se pouze na zacatku)
							ul.removeChild(li);
						}
						
						// Jestlize je vstupni kontrola
						if (check)
						{
							// Jestlize byl filtr na predchozi strance schovan
							/*if (getcookie(parentMenu.id) === "true")
							{
								li.style.display = "none";
								check = false;
								this.isHide[parentMenu.id] = false;
							}
							// Jestlize existuje vybrana polozka
							else*//* if (li.className.indexOf("side-menu-active") >= 0)
							{
								// schovej navigaci
								menu(r);
								// pristi onclick() -  nebude schovano
								check = false;
								this.isHide[parentMenu.id] = false;
							}
							// Jestlize vice jak 6 polozek
							else if (n > 6)
							{
								// schovej ostatni
								li.style.display = "none";
								next = true;
								// pristi onclick() - bude schovano
//								this.isHide[parentMenu.id] = true;
							}
						}
						// Jestlize polozka neni vybrana
						else if (li.className.indexOf("side-menu-active") < 0)
						{
							// Jestlize polozka byla schovana
							if (this.isHide[parentMenu.id] === true)
							{
								// zobraz polozku
								li.style.display = "";
							}
							// Jestlize polozka byla zobrazen
							else
							{
								// schovej polozku
								li.style.display = "none";
							}
						}
						n++;
					}
				}
				
				// Nastaveni stavu zobrazeni
				if (this.isHide[parentMenu.id] === true || check)
//				if (this.isHide[parentMenu.id] === true)
				{
//r.childNodes[1].style.backgroundPosition = "-190px -1px";
					r.className = "hover";
					this.isHide[parentMenu.id] = false;
				}
				else
				{
//r.childNodes[1].style.backgroundPosition = "";
					r.className = "";
					this.isHide[parentMenu.id] = true;
				}
				setcookie(parentMenu.id, this.isHide[parentMenu.id], 1); // uloz do cookies
				
				// Jestlize ma byt zobrazena polozka '... dalsi'
				if (next)
				{
					switch (parentMenu.id)
					{
					case "side-menu-category":
						nextText = "Všechny kategorie";
						break;
					default:
						nextText = "\u2026 další";
						break;
					}
					
					// vzor: <li class=""><a href="#"><span>&hellip; další</span></a></li>
					nL = document.createElement("li");
//					nA = document.createElement("a");
					nA = document.createElement("span");
					nS = document.createElement("span");
					//nT = document.createTextNode("\u2026 další"); // alert("…".charCodeAt(0).toString(16)); // 2026
					nT = document.createTextNode(nextText); // alert("…".charCodeAt(0).toString(16)); // 2026

					nL.className = "side-menu-next";
//					nA.href = "#";
					nA.className = "a cursor-hand";
					nA.onclick = function() { menu(r, null, true) }; // po kliknuti rozbal navigaci
					
					nS.appendChild(nT);
					nA.appendChild(nS);
					nL.appendChild(nA);
					ul.appendChild(nL);
				}
			}
		}
	}
*/
