function getElementsByClass(searchClass, domNode, tagName) {
	if (domNode == null)
		domNode = document;
	if (tagName == null)
		tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " " + searchClass + " ";
	for (i = 0, j = 0; i < tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function findTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return curtop;
	}
}

function setwidths() {
	var contentframedocument;
	var menuitems;
	var nr;
	var totalwidth;
	var itemwidth;
	var i;
	try {
		contentframedocument = window.frames["contentframe"].document;
		menuitems = getElementsByClass("menuitem", contentframedocument);
		nr = menuitems.length;
		totalwidth = contentframedocument.getElementById("contentmenu").clientWidth;

		itemwidth = (totalwidth / nr) - 5;
		for ( i = 0; i < nr; i++) {
			menuitems[i].style.width = itemwidth + "px";
		}
	} catch (e) {
		try {
			contentframedocument = document;
			menuitems = getElementsByClass("menuitem", contentframedocument);
			nr = menuitems.length;
			totalwidth = contentframedocument.getElementById("contentmenu").clientWidth;

			itemwidth = (totalwidth / nr) - 5;
			for ( i = 0; i < nr; i++) {
				menuitems[i].style.width = itemwidth + "px";
			}
		} catch (e) {
			
		}
	}
}

function roundmenu_on(id, coord1, coord2) {
	var div = document.getElementById(id);
	div.style.background = "url(http://www.hrmuzeum.ro/Kepek/"
			+ id + "_t.gif) " + coord1 + "px " + coord2 + "px no-repeat";
}

function roundmenu_leave(id) {
	var div = document.getElementById(id);
	div.style.background = "";
}

function redirect(href) {
	window.location.href = href;
}

function scrollwindow(id) {
	var a = document.getElementById(id);
	var height = findTop(a) + 249;
	parent.window.scrollTo(0, height);
}

function changeBackground(id, filename) {
	var div = document.getElementById(id);
	div.style.background = "url(http://www.hrmuzeum.ro/Kepek/"
			+ filename + ") 0 0 no-repeat";
}

/*--------------------------------SwitchMenu----------------------------------------*/

/*******************************************************************************
 * Switch Menu script- by Martial B of http://getElementById.com/ Modified by
 * Dynamic Drive for format & NS4/IE4 compatibility Visit
 * http://www.dynamicdrive.com/ for full source code
 ******************************************************************************/

var persistmenu = "yes" // "yes" or "no". Make sure each SPAN content contains
						// an incrementing ID starting at 1 (id="sub1",
						// id="sub2", etc)
var persisttype = "sitewide" // enter "sitewide" for menu to persist across
								// site, "local" for this page only

if (document.getElementById) { // DynamicDrive.com change
	document.write('<style type="text/css">\n')
	document.write('.submenu{display: none;}\n')
	document.write('</style>\n')
}

function SwitchMenu(obj) {
	if (document.getElementById) {
		var el = document.getElementById(obj);
		var ar = document.getElementById("menulinks").getElementsByTagName(
				"span"); // DynamicDrive.com change
		if (el.style.display != "block") { // DynamicDrive.com change
			for ( var i = 0; i < ar.length; i++) {
				if (ar[i].className == "submenu") // DynamicDrive.com change
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		} else {
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			returnvalue = unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function onloadfunction() {
	if (persistmenu == "yes") {
		var cookiename = (persisttype == "sitewide") ? "switchmenu"
				: window.location.pathname
		var cookievalue = get_cookie(cookiename)
		if (cookievalue != "")
			document.getElementById(cookievalue).style.display = "block"
	}
}

function savemenustate() {
	var inc = 1, blockid = ""
	while (document.getElementById("sub" + inc)) {
		if (document.getElementById("sub" + inc).style.display == "block") {
			blockid = "sub" + inc
			break
		}
		inc++
	}
	var cookiename = (persisttype == "sitewide") ? "switchmenu"
			: window.location.pathname
	var cookievalue = (persisttype == "sitewide") ? blockid + ";path=/"
			: blockid
	document.cookie = cookiename + "=" + cookievalue
}

if (window.addEventListener)
	window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
	window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
	window.onload = savemenustate

	/*--------------------------------/SwitchMenu----------------------------------------*/

function hover_enter(id) {
	var div_top = document.getElementById(id);
	div_top.style.background = "url(http://www.hrmuzeum.ro/Kepek/aktiv_menuelem_felso.jpg) 0 0 no-repeat";
}

function hover_leave(id) {
	var div_top = document.getElementById(id);
	div_top.style.background = "url(http://www.hrmuzeum.ro/Kepek/inaktiv_menuelem_felso.jpg) 0 0 no-repeat";
}

function sub_hover_enter(id) {
	var div_top = document.getElementById(id);
	div_top.style.background = "url(http://www.hrmuzeum.ro/Kepek/aktiv_almenuelem_felso.jpg) 0 0 no-repeat";
}

function sub_hover_leave(id) {
	var div_top = document.getElementById(id);
	div_top.style.background = "url(http://www.hrmuzeum.ro/Kepek/inaktiv_almenuelem_felso.jpg) 0 0 no-repeat";
}

function contentmenu_hover_enter(id1, id2, id3) {
	var div1 = document.getElementById(id1);
	div1.style.background = "url(http://www.hrmuzeum.ro/Kepek/br3.jpg) 100% 100% no-repeat";
	var div2 = document.getElementById(id2);
	div2.style.background = "url(http://www.hrmuzeum.ro/Kepek/tl3.jpg) 0 0 no-repeat";
	var div3 = document.getElementById(id3);
	div3.style.background = "url(http://www.hrmuzeum.ro/Kepek/tr3.jpg) 100% 0 no-repeat";
}

function contentmenu_hover_leave(id1, id2, id3) {
	var div1 = document.getElementById(id1);
	div1.style.background = "url(http://www.hrmuzeum.ro/Kepek/br2.jpg) 100% 100% no-repeat";
	var div2 = document.getElementById(id2);
	div2.style.background = "url(http://www.hrmuzeum.ro/Kepek/tl2.jpg) 0 0 no-repeat";
	var div3 = document.getElementById(id3);
	div3.style.background = "url(http://www.hrmuzeum.ro/Kepek/tr2.jpg) 100% 0 no-repeat";
}

function setheights() {
	var height;
	var contentframedocument;
	var content;
	var menu;
	try {
		if (window.frames["contentframe"].document != null) {
			height = 0;
			contentframedocument = window.frames["contentframe"].document;
			height += contentframedocument.getElementById("contentmenu").clientHeight;
			height += contentframedocument.getElementById("textcontainer").clientHeight;
			if (contentframedocument.getElementById("sidebar").clientHeight > height) {
				height = contentframedocument.getElementById("sidebar").clientHeight;
			}
			height += 10;
			content = document.getElementById("content");
			if (content.clientHeight < height)
				content.style.height = height + "px";
			menu = document.getElementById("menu");
			if (menu.clientHeight < height)
				menu.style.height = height + "px";
		}
	} catch (e) {
		try {
			if (parent.document != null) {
				height = 0;
				contentframedocument = document;
				height += contentframedocument.getElementById("contentmenu").clientHeight;
				height += contentframedocument.getElementById("textcontainer").clientHeight;
				if (contentframedocument.getElementById("sidebar").clientHeight > height) {
					height = contentframedocument.getElementById("sidebar").clientHeight;
				}
				height += 17;
				content = parent.document.getElementById("content");
				//if (content.clientHeight < height)
					content.style.height = height + "px";
				menu = parent.document.getElementById("menu");
				//if (menu.clientHeight < height)
					menu.style.height = height + "px";
				var contentframe = parent.document.getElementById("contentframe");
				contentframe.style.height = height + "px";
			}
		} catch (e) {
			alert(e);
		}
	}
}

function setheights2() {
	var height = 0;
	var contentframedocument = document;
	if (contentframedocument != null) {
		height += contentframedocument.getElementById("contentmenu").clientHeight;
		height += contentframedocument.getElementById("textcontainer").clientHeight;
		if (contentframedocument.getElementById("sidebar").clientHeight > height) {
			height = contentframedocument.getElementById("sidebar").clientHeight;
		}
		var containerdocument = parent.document;
		var content = containerdocument.getElementById("content");
		if (content.clientHeight < height)
			content.style.height = height + "px";
		var menu = containerdocument.getElementById("menu");
		if (menu.clientHeight < height)
			menu.style.height = height + "px";
	}
}

function init() {
	setheights();
	setwidths();
	onloadfunction();
}

window.onload = init;
window.onunload = savemenustate;
