function sw1() {
    if (document.getElementById("liste")&&document.getElementById("minibaum")) {
        if (document.getElementById("liste").style.display != "block") {
            document.getElementById("liste").style.display = "block";
            document.getElementById("minibaum").style.display = "none";
        } else {
            document.getElementById("liste").style.display = "none";
            document.getElementById("minibaum").style.display = "block";
        }
    }
}

var pqshop = {
	box1: null,
	box2: null,
	box3: null,
	aktive: false,
	selid:null,
	init: function(open) {
		pqshop.box1 = document.getElementById("onlinesop_b1");
		pqshop.box2 = document.getElementById("onlinesop_b2");
		pqshop.box3 = document.getElementById("onlinesop_b3");
		if (pqshop.box1 && pqshop.box2 && pqshop.box3) {
			pqshop.aktive = true;			
		}
		if (shopliste_root && shopliste_root.length>0) {
			for (var pos in shopliste_root) {
				var add = pqshop.getBox(shopliste_root[pos],1);
				if (add) {
					pqshop.box1.appendChild(add);
				}
			}
			open = open.split("-");
			if (open[0] && open[1]) {
				pqshop.select(1,open[0]);
			} else if (open[0]) {
				pqshop.markier(open[0]);				
			}
			if (open[1] && open[2]) {
				pqshop.select(2,open[1]);
			} else if (open[1]) {
				pqshop.markier(open[1]);
			}
			if (open[2]) {
				pqshop.markier(open[2]);
			}
		}
	},
	getBox: function(gid,box) {
		var ret = false; 
		if (box<1) { box = 1; }
		if (box>3) { box = 3; }
		if (shopliste && shopliste[gid]) {
			ret = document.createElement("span");
			ret.id = "onlineshop_element_id_" + gid;
			ret.className = "onlineshop_inaktiv";
			// link erstellen mit JS
			var link =  document.createElement("a");
			link.href = "javascript:pqshop.select(" + box + ", " + gid + ");";
			var bez = shopliste[gid]["bez"];
			if (bez.substr(bez.length-2,2)==" |") { 
				bez = bez.substring(0,bez.length-2); 
			}
			link.appendChild(document.createTextNode(bez));
			var anzahl = document.createElement("span");
			anzahl.appendChild(document.createTextNode(" (" + shopliste[gid]["anzahl"] + ")"));			
			link.appendChild(anzahl)
			ret.appendChild(link);
		}
		return ret;
	},
	select: function(box, gid) {
		if (box>0 && box<3 && shopliste && shopliste[gid]) {		
			if (shopliste[gid]['kinder'] && shopliste[gid]['kinder'].length>0) {				
				if (box+1 == 2) {
					var myBox = pqshop.box2;
					var rBox =  pqshop.box1;
				} else {
					var myBox = pqshop.box3;
					var rBox =  pqshop.box2;
				}				
				for (var pos in rBox.childNodes) {
					rBox.childNodes[pos].className = "onlineshop_inaktiv";
				}
				while (myBox.childNodes[0]) {
					myBox.removeChild(myBox.childNodes[0]);
				}
				if (box == 1) {
					while (pqshop.box3.childNodes[0]) {
						pqshop.box3.removeChild(pqshop.box3.childNodes[0]);
					}
				}
				for (var pos in shopliste[gid]['kinder']) {
					var add = pqshop.getBox(shopliste[gid]['kinder'][pos], box+1);
					if (add) {
						myBox.appendChild(add);
					}
				}
				pqshop.markier(gid);
			} else {
				// auswahl getroffen, laden!
				location.href = "./?s=onlineshop&gs_onlineshop_seite=1&gs_onlineshop_sgr=" + gid;
			} 
		} else if ( box==3) {
			location.href = "./?s=onlineshop&gs_onlineshop_seite=1&gs_onlineshop_sgr=" + gid;
		}
	},
	markier: function(gid){
		var dom = document.getElementById("onlineshop_element_id_" + gid);
		if (dom) {
			pqshop.selid = gid;		
			dom.className = "onlineshop_aktive";
            if (document.getElementById("t1") && dom.childNodes[0] && dom.childNodes[0].firstChild) {
                document.getElementById("t1").innerHTML = dom.childNodes[0].firstChild.nodeValue;
            }
			if (dom.parentNode) {
				if (dom.offsetTop - dom.offsetHeight>0) {
					dom.parentNode.scrollTop = dom.offsetTop - dom.offsetHeight - 4;
				} else {
					dom.parentNode.scrollTop = 0;
				}
			} else {
				alert("kein parent");
			}
		}
	}
}
