var sel = null;

function solurl(url) {
  var r = new RegExp("\\..*", "g");
  var f = url.replace(r, "");
  return f + "-solution.html";
}

function bonsolurl(url) {
  return "files/solution-" + url;
}

function puzzlemenu(pid,x,y,ismeta,url) {
  if (sel == pid) { cleardiv(); return; }
  sel = pid;

  var d = document.getElementById("menu");

  d.style.backgroundColor = ismeta ? "#999999" : "#0060b6";
  d.style.color = ismeta ? "white" : "#999999";
  d.style.borderTop = ismeta ? "2px solid white" : "none";
  d.style.padding = "0px";
  d.style.paddingBottom = "4px";
  d.style.paddingTop = ismeta ? "4px" : "0px";
  d.style.display = "block";
  d.style.position = "absolute";
  d.style.top = y-2 + "px";
  d.style.left = x-1 + "px";

  var html = "";
  if (ismeta) {
    html = ismeta + "<br/><br/>";
  }
  html += "<hr/>";
  html += "<a href=\"" + PUZZLE_URL + url + "\">download</a><br/>";
  var name = url;
  if (url.indexOf(".") >= 0) {
    name = url.substr(0, url.indexOf("."));
  }
  html += "<a href=\"" + SOLUTION_URL + solurl(url) + "\">solution</a><br/>";
    
  d.innerHTML = html;
}

function bonusmenu(pid, x, y, msg, url, pid) {
  if (sel == pid) { cleardiv(); return; }
  sel = pid;

  var d = document.getElementById("menu");
  
  d.style.backgroundColor = "#e36e00";
  d.style.color = "white";				     				     
  d.style.borderTop = "2px solid white";
  d.style.padding = "4px";
  d.style.display = "block";
  d.style.position = "absolute";
  d.style.top = y-2 + "px";
  d.style.left = x-1 + "px";

  var html = msg + "<hr/>";
  html += "<a href=\"" + PUZZLE_URL + url + "\">download</a><br/>";
  var name = url;
  if (url.indexOf(".") >= 0) {
    name = url.substr(0, url.indexOf("."));
  }
  html += "<hr/><a href=\"verify-" + pid + ".html\">verify</a>";
  html += "<hr/><a href=\"" + SOLUTION_URL + bonsolurl(url) + "\">solution</a>";
  d.innerHTML = html;
}

function cleardiv() {
  var d = document.getElementById("menu");
  d.style.display = "none";
  sel = null;
}
  

