/* $Id: image_nodes.js,v 1.3.2.4.4.16 2008/01/28 12:37:28 snpower Exp $ */

// Image Node Auto-Format with Auto Image Grouping.
// Original version by Steve McKenzie.
// Altered by Stella Power for jQuery version.

if (Drupal.jsEnabled) {
  $(document).ready(function lightbox2_image_nodes() {

    var settings = Drupal.settings.lightbox2;

    // Don't do it on the image assist popup selection screen.
    var img_assist = document.getElementById("img_assist_thumbs");
    if (!img_assist) {

      // Select the enabled image types.
      var classes = settings.image_node_classes;
      $("a["+classes+"]").each(function(i) {

        if ((!settings.disable_for_gallery_lists && !settings.disable_for_acidfree_gallery_lists) || (!$(this).parents(".galleries").length && !$(this).parents(".acidfree-folder").length && !$(this).parents(".acidfree-list").length) || ($(this).parents(".galleries").length && !settings.disable_for_gallery_lists) || (($(this).parents(".acidfree-folder").length || $(this).parents(".acidfree-list").length) && !settings.disable_for_acidfree_gallery_lists)) {

          var child = $(this).children();

          // Set the alt text.
          var alt = $(child).attr("alt");
          if (!alt) {
            alt = "";
          }

          // Set the image node link text.
          var link_text = settings.node_link_text;

          // Set the rel attribute.
          var rel = "lightbox";
          if (settings.group_images) {
            rel = "lightbox[node_thumbnails]";
          }
          

          // Handle flickr images.
          var href = '';
          if ($(child).attr("class").match("flickr-photo-img")) {
            href = $(child).attr("src").replace("_s", "").replace("_t", "").replace("_m", "").replace("_b", "");
            if (settings.group_images) {
              rel = "lightbox[flickr]";
            }
          }

          // Set the href attribute.
          else {
            href = $(child).attr("src").replace(".thumbnail", ((settings.display_image_size == "")?settings.display_image_size:"."+ settings.display_image_size)).replace(/(image\/view\/\d+)(\/\w*)/, ((settings.display_image_size == "")?"$1/_original":"$1/"+ settings.display_image_size));
          }

          // Modify the image url.
          $(this).attr({rel: rel,
	    // jbw: Don't like the link text, using the title as link...
            title: "<a href=\"" + this.href + "\" id=\"node_link_text\">" + alt + "</a>",
            href: href
            });
        }

      });

    }
  });
}
