var switcher = function() {};


switcher.cache = true;

switcher.liClick = function() {
	tmp = lib.elements.findByClassName("selected", document.getElementById("downloadSwitch"));
	for(var i=0; i < tmp.length; i++) {
		tmp[i].className = "unselected";
	}
	if(switcher.cache == true) {
		this.className = "selected";
	}
	else {
		switcher.cache = true;
	}
}

switcher.hideAll = function() {
	var tmp = lib.elements.findByClassName("selected", document.getElementById("downloadSwitch"));
	for(var i=0; i < tmp.length; i++) {
		tmp[i].className = "unselected";
	}
	switcher.cache = false;
}


// Nalezneme si všechny li a nastavime jim priznak na click
switcher.setEvent = function() {
	if (document.getElementById("downloadSwitch")) {
		var downloadSwitchChoises = lib.elements.findByClassName("choise", document.getElementById("downloadSwitch"));
		// projedeme si jednotlive nody a nalezneme jednotlive <li> a nastavime jim udalosti 
		for(var i=0; i < downloadSwitchChoises.length; i++) {
			var downloadSwitchTops = lib.elements.findByClassName("unselected", downloadSwitchChoises[i]);
			for(var x=0; x < downloadSwitchTops.length; x++) {
				lib.evt.add(downloadSwitchTops[x], "click", switcher.liClick, 5);
				downloadSwitchTops[x].getElementsByTagName("a")[0].href="#rozbaleno";
			}
		}
		tmp = lib.elements.findByClassName("close", document.getElementById("downloadSwitch"));
		for(var i=0; i < tmp.length; i++) {
			lib.evt.add(tmp[i], "click", switcher.hideAll, 2);
		}

		
	}
};


lib.evt.add(window, "load", switcher.setEvent);
