var ImgRelLightBox = {
  addToImage: function(element, rxp) {
    imgs = element.getElementsByTagName("IMG");
    for (i = 0; i < imgs.length; i++) { 
      a = imgs[i].parentNode;
      if (a && a.tagName == "A" && rxp.test(a.href))
        a.setAttribute("rel", "lightbox");
    }
  },

  addToAllImages: function() {
    entry_id = "main-block";
    class_name = "entry";
    local_domain = document.location.href;
    var idx;
    idx = local_domain.indexOf("//");
    if (idx >= 0) {
      local_domain = local_domain.substr(idx+2);
      idx = local_domain.indexOf("/");
      if (idx >= 0)
        local_domain = local_domain.substr(0, idx);
    }
    local_domain = local_domain.replace("www.", "(www.)?"); /* dirty hack */
    local_domain = local_domain.replace(/\x2e/g, "\\x2e");
    var rxp = new RegExp(eval("/https?:\\x2f\\x2f" + local_domain + "/"));

    var img_callback = function(element) {
      ImgRelLightBox.addToImage(element, rxp);
    }

    el = document.getElementsByClassName(entry_id);
    if (el) el = el[0];
    if (el) {
      DocGen.forEachClassName(el, class_name, img_callback);
    }
    initLightbox();
  },

  register: function() {
    DocGen.doOnLoad(ImgRelLightBox.addToAllImages);
  }
}

ImgRelLightBox.register();

