// Press handlers

function ResetListItems(optItem) {
	var list = document.getElementById("sb1_scrollable").childNodes;
	for (var i=0;i<list.length;i++) {
		if (typeof list[i].tagName != "undefined" && list[i].tagName.toUpperCase() == "DIV") {
			try {
				if (typeof optItem != "undefined" && list[i] == optItem) {
					list[i].className = "ContentListItem CLI_Selected";
				} else {
					list[i].className = "ContentListItem";
				}
			} catch(e) {
			}
		}
	}
	var articles = document.getElementById("contitems").childNodes;
	for (var i=0;i<articles.length;i++) {
		if (typeof articles[i].tagName != "undefined" && articles[i].tagName.toUpperCase() == "DIV") {
			try {
				if (typeof optItem != "undefined" && articles[i].id == ("art" + optItem.getAttribute("artid"))) {
					articles[i].className = "ContentItem CI_Open";
				} else {
					articles[i].className = "ContentItem CI_Closed";
				}
			} catch(e) {
			}
		}
	}
	document.body.scrollTop = getRealY(document.getElementById("contitems"));
	// Check if hash is present
	if (document.location.href.indexOf("#") > -1) {
		// Remove hash
		var newhref = document.location.href.substr(0,document.location.href.indexOf("#"));
	} else {
		var newhref = document.location.href;
	}
	var artnum = optItem.id.replace("artlink","");
	newhref += ("#art="+artnum);
	document.location.href = newhref;
}

function ClickItem(who) {
	ResetListItems(who);
}

function CheckHash() {
	var hash = document.location.href.split("#")[1];
	if (typeof hash == "undefined" || hash == "" || hash == null) {
	} else {
		var pair = hash.split("=");
		if (pair[0] != "art" || pair[1] == "") return;
		var artid = pair[1];
		ResetListItems(document.getElementById("artlink"+artid));
	}
}

function getRealY(who) {
	var obj = (typeof who == "string")?document.getElementById(who):who;
	var res = 0;
	var t = who;
	while (1 == 1) {
		if (typeof t.offsetTop != "undefined") res += t.offsetTop;
		t = t.offsetParent;
		if (t == document.body) return res;
	}
}