function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  
  return null;
} 

function highlightSelectedSystem() {
	var topBarSystemsMenuList = document.getElementById("top-bar-systems-menu-list");
	var os = getQueryVariable("os");
	
	if (os != null) {
		os = os.toLowerCase();
	}
	else {
		os = "all";
	}
	
	var menuItems = new Array();
	
	for (var i = 0; i < topBarSystemsMenuList.childNodes.length; i++) {
		if (topBarSystemsMenuList.childNodes[i].nodeName == "LI") {
			menuItems.push(topBarSystemsMenuList.childNodes[i]);
		}
	}
	
	var menuChildIdx = 0;
	
	// Ugly and error-prone in case a new system category comes in, but parsing html to know 
	// which list item under topBarSystemsMenuList corresponds to the current os would fail
	// if the language is no longer English...
	switch (os) {
	case "windows":
		menuChildIdx = 1;
		break;
	case "linux":
		menuChildIdx = 2;
		break;
	case "mobile":
		menuChildIdx = 3;
		break;
	case "mac":
		menuChildIdx = 4;
		break;
	case "news":
		menuChildIdx = 5;
		break;
	default:
		menuChildIdx = 0;
	}
	
	// Highlight selected system by setting its link font to bold.
	menuItems[menuChildIdx].firstChild.nextSibling.style.fontWeight = "bold";
}

