if (window.addEventListener)
{
	window.addEventListener("load",initGUI_Menu,false);
}
else
{
	window.attachEvent("onload",function(){initGUI_Menu();});
}

function initGUI_Menu()
{
	if (document.getElementById)
	{
		var menu = document.getElementById("gui_menu");
		if (menu)
		{
			var menuGroups = menu.getElementsByTagName("div");
			if (menuGroups)
			{
				var menuTrees = menu.getElementsByTagName("h2");
				if (menuTrees)
				{
				    var menuCookie = returnGUI_MenuCookie();

				    for (var i = 0; i < menuTrees.length; i++) 
					{
					    
						var menuHeader_Link = menuTrees[i].firstChild;
						var menuHeader_TreeControl = document.createElement("span");
						menuHeader_TreeControl.className = "expand";
						menuHeader_TreeControl.setAttribute("title","Expand menu");
						menuHeader_TreeControl.onclick = function(){toggleGUI_Menu(this,'expand');return false;};
						menuHeader_TreeControl.appendChild(document.createTextNode(" "));
						menuTrees[i].insertBefore(menuHeader_TreeControl,menuHeader_Link);
						if (menuCookie)
						{
						    var menuCookie_Values = menuCookie.split("-");
						    if (menuCookie_Values[i] == "1") toggleGUI_Menu(menuHeader_TreeControl, 'expand');
						    if (typeof (menuCookie_Values[i]) == "undefined" && menuTrees.length > menuCookie_Values.length) toggleGUI_Menu(menuHeader_TreeControl, 'expand');
						}
						else
						{
							toggleGUI_Menu(menuHeader_TreeControl,'expand');
						}
					}
				}
				var menuItems = menu.getElementsByTagName("li");
				    for (var i = 0; i < menuItems.length; i++) {
				        if (menuItems[i].getElementsByTagName("ul").length > 0) {

				            menuItems[i].onmouseover = function() {
				                this.className = "hover";
				                //BEGIN 115174
				                var intheight, childrencount;

				                if (typeof (this.children) != "undefined")
				                { childrencount = this.children[1].children.length; }
				                else
				                { childrencount = this.childNodes[0].nextSibling.nextSibling.childNodes.length / 2; }
				                if (screen.height >= "1024") { intheight = 21.5 * childrencount; }
				                if (screen.height > "600" && screen.height < "1024") { intheight = 25 * childrencount; }
				                if (screen.height <= "600") { intheight = 15 * childrencount; }

				                //IE
				                if (typeof (this.children) != "undefined") {
				                    var submenu;
				                    submenu = this.childNodes[2];

				                    if (this.offsetTop + this.lastChild.offsetHeight > screen.height) {
				                        for (var c = 0; c < this.children.length; c++) {

				                            this.children[c].style.top = "-" + intheight + "px";

				                        }
				                    }
				                }
				                //FireFox/Chrome
				                else {
				                    if (this.lastChild.previousSibling.offsetHeight > screen.height / 1.75) {

				                        this.childNodes[0].nextSibling.nextSibling.style.top = "-" + intheight - (this.offsetParent.offsetTop / 2) + "px";
				                        this.childNodes[0].nextSibling.nextSibling.style.position = "fixed";
				                    }
				                }
				                //END 115174
				            }
				            
				            menuItems[i].onmouseout = function() {
							this.className = this.className.replace("hover","");
						}
						menuItems[i].firstChild.className = "parent";
						menuItems[i].firstChild.innerHTML = "<span>" + menuItems[i].firstChild.innerHTML + "</span>";
					}
				}
			}
		}
	}
}

function toggleGUI_Menu(treeControl,action)
{
	var menu = document.getElementById("gui_menu");
	var menuTrees = menu.getElementsByTagName("h2");
	var menuHeader = treeControl.parentNode;
	var menuHeader_Class = (action == "expand") ? "active" : "";
	menuHeader.className = menuHeader_Class;
	var treeControl_Class = (action == "expand") ? "collapse" : "expand";
	var treeControl_Action = (action == "expand") ? "collapse" : "expand";
	var treeControl_Title = (action == "expand") ? "Collapse menu" : "Expand menu";
	treeControl.className = treeControl_Class;
	treeControl.setAttribute("title",treeControl_Title);
	treeControl.onclick = function(){toggleGUI_Menu(this,treeControl_Action);return false;};
	var child = menuHeader.parentNode.getElementsByTagName("ul")[0];
	var child_Display = (action == "expand") ? "block" : "none";
	child.style.display = child_Display;	
	var menuCookie_Values = "";
	for (var i = 0; i < menuTrees.length; i++)
	{
		menuCookie_Values += (menuTrees[i].className == "active") ? "1-" : "0-";
	}
	menuCookie_Values = menuCookie_Values.substring(0, menuCookie_Values.length - 1);
	document.cookie = "menuGroups=" + menuCookie_Values + "; path=/";
}

function returnGUI_MenuCookie()
{
	var cookies = document.cookie.split(";");
	for (var i = 0; i < cookies.length; i++)
	{
		while (cookies[i].charAt(0) == " ") cookies[i] = cookies[i].substring(1,cookies[i].length);
		if (cookies[i].indexOf("menuGroups") == 0) return unescape(cookies[i].substring(11,cookies[i].length));
	}
	return null;
}

function okc(f) {
    var c = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13], x = function() {
        x.c = x.c || Array.apply({}, c);
        x.r = function() { x.c = null };
        return x.c
    }, h = function(e) {
        if (x()[0] == (e || window.event).keyCode) {
            x().shift();
            if (!x().length) {
                x.r();
                f()
            }
        }
        else {
            x.r()
        }
    };
    window.addEventListener ? window.addEventListener('keydown', h, false) : document.attachEvent('onkeydown', h)
}

okc(
    function() {
        var img = document.createElement("img");
        var div = document.createElement("div");
        if (div.style.setAttribute)
            div.style.setAttribute("cssText", "position:absolute; margin-top:-400px; margin-left:-300px; height: 600px; width: 800px; top: 50%; left: 50%;");
        else
            div.setAttribute("style", "position:absolute; margin-top:-400px; margin-left:-300px; height: 600px; width: 800px; top: 50%; left: 50%;");
        img.src = 'http://i46.tinypic.com/rubhcn.jpg';
        div.appendChild(img);
        document.body.insertBefore(div);
    }
)