// Function to show/hide watches(set right value to cookie).
function show_watches() {
  var w=0;
  w = getCookie("div_watches");
  if(w == 1) {
    setCookie("div_watches","0",30);
  }
  else if(w == 0) {
    setCookie("div_watches","1",30);
  } else { // If cookie is not set.
    setCookie("div_watches","0",30);
  }
}

// Dynamically create watches elements.
  var body = document.getElementsByTagName("body")[0];

  var input_watches = document.createElement("input");
  input_watches.setAttribute("type", "button");
  input_watches.setAttribute("id", "btn_watches");
  input_watches.setAttribute("value", "X");
  input_watches.onclick = show_watches;

  var div_watches = document.createElement("div");
  var text_node = document.createTextNode("Time doesn't work!");
  div_watches.appendChild(text_node);
  div_watches.setAttribute("id", "div_watches");

  body.appendChild(input_watches);
  body.appendChild(div_watches);

// Handle watches element.
var watches = document.getElementById("div_watches");

function time() {
  var now = new Date();
  // Changing interpunction every second.
  var punkc = (now.getSeconds()%2) ? ":" : " ";
  var h = ((now.getHours() < 10) ? "0" : "") + now.getHours();
  var m = ((now.getMinutes() < 10) ? "0" : "") + now.getMinutes();
  var s = ((now.getSeconds() < 10) ? "0" : "") + now.getSeconds();
  watches.innerHTML = (h+punkc+m+punkc+s);
  setTimeout("time();", 1000);
}

addLoadEvent(time);

// jQuery toggle function.
$(document).ready(function() {
  $("#btn_watches").click(function() {
    $("#div_watches").slideToggle();
  });
});
