//  Lightview 1.0.4 - 17-01-2008

//  Copyright (c) 2008 Nick Stakenburg (http://www.nickstakenburg.com)
//
//  Permission is hereby granted, free of charge, to any person obtaining
//  a copy of this software and associated documentation files (the
//  "Software"), to deal in the Software without restriction, including
//  without limitation the rights to use, copy, modify, merge, publish,
//  distribute, sublicense, and/or sell copies of the Software, and to
//  permit persons to whom the Software is furnished to do so, subject to
//  the following conditions:
//
//  The above copyright notice and this permission notice shall be
//  included in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
//  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
//  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
//  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
//  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
//  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//  More information on this project:
//  http://www.nickstakenburg.com/projects/lightview/

var Lightview = {
  Version: '1.0.4',

  // Configuration
  options: {
    backgroundColor: '#ffffff',                            // Background color of the lightview
    border: 12,                                            // Size of the border
    buttons: { opacity: { normal: 0.65, hover: 1 } },      // Opacity of inner buttons
    closeDimensions: {                                     // If you've changed the close button you can change these
      large: { width: 85, height: 22 },                    // not required but it speeds things up.
      small: { width: 32, height: 22 }
    },
    effects: !!window.Effect,                              // Use effects when available, or true/false
    images: '../Images/lightview/',                        // the directory of the images, from this file
    imgNumberTemplate: 'Image #{position} of #{total}',    // Want a different language? change it here
    overlay: { display: true, opacity: 0.85 },              // overlay display and opacity
    radius: 12,                                            // Corner radius of the border
    resizeDuration: 0.9,                                   // When effects are used, the duration of resizing in seconds
    sideDimensions: { width: 16, height: 22 },             // see closeDimensions
    slideshow: { delay: 5 },                               // seconds each image is visible in slideshow
    titleCaptionSplit: '::',                               // The characters you want to split title and caption with
    transition: function(pos) {                            // Or your own transition
      return ((pos/=0.5) < 1 ? 0.5 * Math.pow(pos, 4) :
        -0.5 * ((pos-=2) * Math.pow(pos,3) - 2));
    },
    viewport: true,                                        // Resize large images to screen when they open
    zIndex: 5000                                           // zIndex of #lightview, #overlay is this -1
  }
};

  Object.extend(Lightview, {REQUIRED_Prototype : "1.6.0", REQUIRED_Scriptaculous : "1.8.0", preloadedImages : [], preloadedData : [], queue : {position : "end", scope : "lightview"}, load : (function ()
{
  this.require("Prototype");
  if (this.options.effects)
    {
      this.require("Scriptaculous");
    }
  var A = /lightview(?:-[\w\d.]+)?\.js/;
  this.images = (($$("head script[src]").find((function (B)
{
  return B.src.match(A);
}
)) || {}).src || "").replace(A, "") + this.options.images;
  if (Prototype.Browser.IE && ! document.namespaces.v)
    {
      document.createStyleSheet().addRule("v\\:*", "behavior: url(#default#VML);");
      document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
    }
}
), require : (function (A)
{
  if (typeof window[A] == "undefined" || this.convertVersionString(window[A].Version) < this.convertVersionString(this[("REQUIRED_" + A)]))
    {
      throw "Lightview requires " + A + " >= " + this[("REQUIRED_" + A)];
    }
}
), convertVersionString : (function (A)
{
  var B = A.split(".");
  return parseInt(B[0]) * 100000 + parseInt(B[1]) * 1000 + parseInt(B[2]);
}
), fixIE : (function (B)
{
  var A = new RegExp("MSIE ([\\d.]+)").exec(B);
  return A ? parseFloat(A[1]) <= 6.2 : false;
}
)(navigator.userAgent), start : (function ()
{
  this.radius = this.options.radius;
  this.border = this.radius > this.options.border ? this.radius : this.options.border;
  this.closeDimensions = this.options.closeDimensions;
  this.sideDimensions = this.options.sideDimensions;
  this.build();
  this.updateViews();
  this.addObservers();
}
), build : (function ()
{
  var G, E, D = this.pixelClone(this.sideDimensions);
  $(document.body).insert(this.overlay = new Element("div", {id : "overlay"}).setStyle({zIndex : this.options.zIndex - 1}).setOpacity(this.options.overlay.opacity).hide()).insert(this.lightview = new Element("div", {id : "lightview"}).setStyle({zIndex : this.options.zIndex}).hide().insert(this.container = new Element("div", {className : "container"}).insert(new Element("ul", {className : "sideButtons"}).insert(this.prevSide = new Element("li", {className : "side prev"}).setStyle(E = Object.extend({marginLeft : - 1 * this.sideDimensions.width + "px"}, D)).insert(this.prevButtonImage = new Element("div", {className : "wrapper"}).setStyle(Object.extend({marginLeft : this.sideDimensions.width + "px"}, D)).insert(new Element("div", {className : "button"})))).insert(this.nextSide = new Element("li", {className : "side next"}).setStyle(Object.extend({marginRight : - 1 * this.sideDimensions.width + "px"}, D)).insert(this.nextButtonImage = new Element("div", {className : "wrapper"}).setStyle(E).insert(new Element("div", {className : "button"}))))).insert(new Element("ul", {className : "frames"}).insert(new Element("li", {className : "frame top"}).insert(G = new Element("div", {className : "liquid"}).setStyle({height : this.border + "px"}).insert(new Element("ul", {className : "half left"}).insert(new Element("li", {className : "wrap"}).insert(new Element("div", {className : "corner"})).insert(new Element("div", {className : "fill"}).setStyle({left : this.border + "px"})))).insert(new Element("div", {className : "filler"})).insert(new Element("ul", {className : "half right"}).insert(new Element("li", {className : "wrap"}).setStyle({marginTop : - 1 * this.border + "px"}).insert(new Element("div", {className : "corner"})).insert(new Element("div", {className : "fill"}).setStyle({left : - 1 * this.border + "px"})))))).insert(new Element("li", {className : "center"}).insert(new Element("div", {className : "wrapup"}).setStyle({bottom : this.border + "px"}).insert(new Element("div", {className : "wrapdown"}).setStyle({marginTop : 2 * this.border + "px"}).insert(this.center = new Element("div", {className : "wrapcenter"}).setOpacity(0).setStyle({padding : "0 " + this.border + "px"}).insert(this.imageWrapper = new Element("div", {className : "imageWrapper"}).insert(this.image = new Element("img", {src : this.images + "blank.gif", alt : ""}))).insert(this.dataContainer = new Element("div", {className : "dataContainer"}).insert(this.closeWrapper = new Element("div", {className : "close"}).setStyle({height : this.options.closeDimensions.large.height + "px", width : this.options.closeDimensions.large.width + "px"}).insert(this.closeButton = new Element("a", {className : "button"}).setStyle({background : "url(" + this.images + "close.jpg) top right no-repeat"}).setOpacity(this.options.buttons.opacity.normal))).insert(this.data = new Element("ul", {className : "data"}).insert(this.imgText = new Element("li", {className : "imgText"}).insert(this.title = new Element("div", {className : "title"})).insert(this.caption = new Element("div", {className : "caption"}))).insert(this.imgNumber = new Element("li", {className : "imgNumber"}).insert(new Element("div"))).insert(this.slideshow = new Element("li", {className : "slideshow"}).insert(this.slideshowButton = new Element("a", {className : "button"}).setOpacity(this.options.buttons.opacity.normal).setStyle({background : "url(" + this.images + "slideshow_play.jpg) top left no-repeat"})))))))).insert(this.loading = new Element("li", {className : "loading"}).insert(new Element("div", {className : "button"}).setStyle({background : "url(" + this.images + "loading.gif) top left no-repeat"})))).insert(this.prevnext = new Element("li", {className : "prevnext"}).setStyle({marginTop : this.border + "px", background : "url(" + this.images + "blank.gif) top left repeat"}).insert(this.prevButton = new Element("div", {className : "prev button"})).insert(this.nextButton = new Element("div", {className : "next button"}))).insert(new Element("li", {className : "frame bottom"}).insert(G.cloneNode(true))))));
  var H = new Image();
  H.onload = (function ()
{
  H.onload = Prototype.emptyFunction;
  var J = {width : H.width + "px", height : H.height + "px"}, C;
  this.sideDimensions = {width : H.width, height : H.height};
  this.prevSide.setStyle(C = Object.extend({marginLeft : - 1 * this.sideDimensions.width + "px"}, J));
  this.prevButtonImage.setStyle(Object.extend({marginLeft : this.sideDimensions.width + "px"}, J));
  this.nextSide.setStyle(Object.extend({marginRight : - 1 * this.sideDimensions.width + "px"}, J));
  this.nextButtonImage.setStyle(C);
}
).bind(this);
  H.src = this.images + "prev.png";
  if (this.fixIE)
    {
      $$("html, body").invoke("setStyle", {width : "100%", height : "100%"});
      this.overlay.setStyle({position : "absolute"});
    }
  this.lightview.select(".title", ".caption", ".imgNumber").invoke("setStyle", {backgroundColor : this.options.backgroundColor});
  var F = this.container.select(".corner");
  $w("tl tr bl br").each((function (K,C)
{
  var J = this.options.radius > 0 ? this.createCorner(K) : new Element("div", {className : "fill"});
  F[C].setStyle({width : this.border + "px", height : this.border + "px"}).addClassName(K).insert(J);
}
).bind(this));
  this.lightview.select(".filler", ".fill", ".wrapdown").invoke("setStyle", {backgroundColor : this.options.backgroundColor});
  $w("prev next").each((function (J)
{
  var C = this.images + J + ".png";
  this[(J + "Button")].side = J;
  this[(J + "ButtonImage")].setStyle(! this.fixIE ? {background : "url(" + C + ")"} : {filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + C + "'', sizingMethod='scale')"});
}
).bind(this));
  var I = {};
  $w("large small").each((function (C)
{
  I[C] = new Image();
  I[C].onload = (function ()
{
  I[C].onload = Prototype.emptyFunction;
  this.closeDimensions[C] = {width : I[C].width, height : I[C].height};
}
).bind(this);
  I[C].src = this.images + "close" + (C == "small" ? "_small.jpg" : ".jpg");
}
).bind(this));
  var B = new Image();
  B.onload = (function ()
{
  B.onload = Prototype.emptyFunction;
  this.loading.setStyle({width : B.width + "px", height : B.height + "px", marginTop : - 0.5 * B.height + "px", marginLeft : - 0.5 * B.width + "px"});
}
).bind(this);
  B.src = this.images + "loading.gif";
  var A = new Image();
  A.onload = (function ()
{
  A.onload = Prototype.emptyFunction;
  this.slideshowButton.setStyle({width : A.width + "px", height : A.height + "px"});
}
).bind(this);
  A.src = this.images + "slideshow_play.jpg";
}
), show : (function (A)
{
  this.element = Object.isNumber(A) ? this.elements[A] : $(A);
  if (! this.element.href)
    {
      return ;
    }
  this.noset = this.element.rel.toLowerCase() == "lightview";
  this.element.blur();
  this.scaledImageDimensions = null;
  if (this.options.effects)
    {
      Effect.Queues.get("lightview").each((function (D)
{
  D.cancel();
}
));
    }
  this.elements = this.noset ? [this.element] : (this.getSet(this.element.rel)).elements;
  this.position = this.elements.indexOf(this.element);
  this.preloadSurroundingImages();
  this.imageDimensions = this.getPreloadedImageDimensions(this.element.href);
  this.disableKeyboardNavigation();
  this.hideOverlapping();
  this.hideButtons();
  this.hideContent();
  this.appear();
  var C = "after" + (this.options.effects ? "Effect" : "Show");
  if (! this.imageDimensions)
    {
      this.startLoading();
      var B = new Image();
      B.onload = (function ()
{
  B.onload = Prototype.emptyFunction;
  this.stopLoading();
  this.imageDimensions = {width : B.width, height : B.height};
  this[C]();
}
).bind(this);
      B.src = this.element.href;
    }
  else
    {
      this[C]();
    }
}
), afterEffect : (function ()
{
  new Effect.Event({queue : this.queue, afterFinish : (function ()
{
  this.afterShow();
}
).bind(this)});
}
), afterShow : (function ()
{
  this.stopLoading();
  this.resizeImage(this.imageDimensions);
  this.setImage(this.options.effects ? this.element.href : this.images + "blank.gif");
  this.fillData();
  this.enableKeyboardNavigation();
  this.resizeWithinViewport();
  this.showContent();
  if (this.options.effects)
    {
      new Effect.Event({queue : this.queue, afterFinish : (function ()
{
  this.showButtons();
}
).bind(this)});
      if (this.sliding)
        {
          new Effect.Event({queue : this.queue, afterFinish : (function ()
{
  this.nextSlide();
}
).bind(this)});
        }
    }
  else
    {
      this.showButtons();
      if (this.sliding)
        {
          this.nextSlide();
        }
    }
}
), previous : (function ()
{
  this.show((this.getSurroundingIndexes()).previous);
}
), next : (function ()
{
  this.show((this.getSurroundingIndexes()).next);
}
), resizeWithinViewport : (function ()
{
  var B = this.getInnerDimensions(), D = this.getBounds();
  if (this.options.viewport && (B.width > D.width || B.height > D.height))
    {
      var E = Object.clone(this.getOuterDimensions()), A = D, C = Object.clone(E);
      if (C.width > A.width)
        {
          C.height *= A.width / C.width;
          C.width = A.width;
          if (C.height > A.height)
            {
              C.width *= A.height / C.height;
              C.height = A.height;
            }
        }
      else
        {
          if (C.height > A.height)
            {
              C.width *= A.height / C.height;
              C.height = A.height;
              if (C.width > A.width)
                {
                  C.height *= A.width / C.width;
                  C.width = A.width;
                }
            }
        }
      var F = C.width % 1 > 0 ? C.height / E.height : C.height % 1 > 0 ? C.width / E.width : 1;
      this.scaledImageDimensions = {width : (this.imageDimensions.width * F).round(), height : (this.imageDimensions.height * F).round()};
      this.resizeImage(this.scaledImageDimensions);
      this.fillData();
      B = {width : this.scaledImageDimensions.width, height : this.scaledImageDimensions.height + this.dataDimensions.height};
    }
  else
    {
      this.resizeImage(this.imageDimensions);
      this.scaledImageDimensions = null;
    }
  this.resize(B);
}
), resize : (function (B)
{
  var F = this.lightview.getDimensions(), I = 2 * this.border, D = B.width + I, L = B.height + I;
  if (F.width == B.width && F.height == B.height)
    {
      return ;
    }
  var C = {width : D + "px", height : L + "px"};
  if (! this.fixIE)
    {
      Object.extend(C, {marginLeft : 0 - D / 2 + "px", marginTop : 0 - L / 2 + "px"});
    }
  if (this.options.effects)
    {
      var G = D - F.width, K = L - F.height, J = parseInt(this.lightview.getStyle("marginLeft").replace("px", "")), E = parseInt(this.lightview.getStyle("marginTop").replace("px", ""));
      if (! this.fixIE)
        {
          var A = 0 - D / 2 - J, H = 0 - L / 2 - E;
        }
      this.resizing = new Effect.Tween(this.lightview, 0, 1, {duration : this.options.resizeDuration, queue : this.queue, transition : this.options.transition, afterFinish : (function ()
{
  this.restoreCenter();
  this.resizing = null;
}
).bind(this)}, (function (P)
{
  var M = (F.width + P * G).toFixed(), O = (F.height + P * K).toFixed();
  if (! this.fixIE)
    {
      var N = this.viewport.getDimensions(), Q = document.viewport.getScrollOffsets();
      this.lightview.setStyle({position : "absolute", marginLeft : 0, marginTop : 0, width : M + "px", height : O + "px", left : (Q[0] + N.width / 2 - M / 2).round() + "px", top : (Q[1] + N.height / 2 - O / 2).round() + "px"});
    }
  else
    {
      this.lightview.setStyle({width : (F.width + P * G).toFixed() + "px", height : (F.height + P * K).toFixed() + "px"});
    }
}
).bind(this));
    }
  else
    {
      this.lightview.setStyle(C);
    }
}
), showContent : (function ()
{
  if (this.options.effects)
    {
      new Effect.Opacity(this.center, {duration : 0.5, from : 0, to : 1, queue : this.queue, afterFinish : Event.fire.bind(this, this.element, "lightview:opened")});
    }
  else
    {
      this.setImage(this.element.href);
      this.center.setOpacity(1);
      $(this.element).fire("lightview:opened");
    }
}
), hideContent : (function ()
{
  this.hideButtons();
  if (this.options.effects && this.lightview.visible())
    {
      new Effect.Opacity(this.center, {duration : 0.18, from : 1, to : 0, queue : this.queue});
    }
  else
    {
      this.center.setOpacity(0);
    }
}
), resizeImage : (function (D)
{
  var C = this.pixelClone(D);
  this.prevnext.setStyle({height : D.height + "px"});
  this.imageWrapper.setStyle(C);
  this.image.setStyle(C);
  var B = this.sideDimensions.width;
  var A = D.width / 2 - 1 + B + this.border;
  this.prevButton.setStyle({width : A + "px", marginLeft : - 1 * B + "px"});
  this.nextButton.setStyle({width : A + "px", marginRight : - 1 * B + "px"});
}
), setImage : (function (A)
{
  this.image.src = A;
}
), fillData : (function ()
{
  this.imgText.hide();
  this.title.hide();
  this.caption.hide();
  this.imgNumber.hide();
  this.slideshow.hide();
  var C = this.element.getAttribute("title"), A = null, B = C && C.indexOf(this.options.titleCaptionSplit) ? C.indexOf(this.options.titleCaptionSplit) : null;
  if (C && B > - 1)
    {
      A = C.substr(B + 2).strip();
      C = C.substr(0, B).strip();
    }
  if (C || A)
    {
      this.imgText.show();
    }
  if (C)
    {
      this.title.update(C).show();
    }
  if (A)
    {
      this.caption.update(A).show();
    }
  if (this.elements.length > 1)
    {
      this.imgNumber.show().down().update(new Template(this.options.imgNumberTemplate).evaluate({position : this.position + 1, total : this.elements.length}));
      this.slideshow.show();
      this.slideshowButton.show();
    }
  this.closeButtonWidth = this.setCloseButton();
  this.dataDimensions = this.setDataDimensions();
}
), setCloseButton : (function ()
{
  var E = this.closeDimensions.small.width, D = this.closeDimensions.large.width, A = this.scaledImageDimensions ? this.scaledImageDimensions.width : this.imageDimensions.width, F = 180, C = 0, B = this.options.borderColor;
  if (A >= F + E && A < F + D)
    {
      B = "url(" + this.images + "close_small.jpg)";
      C = E;
    }
  else
    {
      if (A >= F + D)
        {
          B = "url(" + this.images + "close.jpg)";
          C = D;
        }
    }
  if (C > 0)
    {
      this.closeWrapper.setStyle({width : C + "px"}).show();
    }
  else
    {
      this.closeWrapper.hide();
    }
  return C;
}
), startLoading : (function ()
{
  if (this.options.effects)
    {
      this.loadingEffect = new Effect.Appear(this.loading, {duration : 0.3, from : 0, to : 1, queue : this.queue});
    }
  else
    {
      this.loading.show();
    }
}
), stopLoading : (function ()
{
  if (! this.loading.visible())
    {
      return ;
    }
  if (this.options.effects)
    {
      if (this.loadingEffect)
        {
          Effect.Queues.get("lightview").remove(this.loadingEffect);
        }
      new Effect.Fade(this.loading, {duration : 1, queue : this.queue});
    }
  else
    {
      this.loading.hide();
    }
}
), showButtons : (function ()
{
  var B = this.position != 0 ? "show" : "hide", A = ! this.noset && (this.getSurroundingIndexes()).next != 0 ? "show" : "hide";
  this.prevButton[B]();
  this.nextButton[A]();
  this.prevButtonImage[B]();
  this.nextButtonImage[A]();
}
), hideButtons : (function ()
{
  this.prevButton.hide();
  this.nextButton.hide();
  this.prevButtonImage.hide();
  this.nextButtonImage.hide();
}
), appear : (function ()
{
  if (this.lightview.visible())
    {
      return ;
    }
  if (this.options.effects)
    {
      new Effect.Appear(this.overlay, {duration : 0.6, from : 0, to : this.options.overlay.opacity, queue : this.queue, afterFinish : Element.show.bind(this, this.lightview)});
    }
  else
    {
      this.lightview.show();
      this.overlay.show();
    }
}
), hide : (function ()
{
  if (! this.overlay.visible())
    {
      return ;
    }
  this.stopSlideshow();
  this.prevnext.hide();
  this.center.hide();
  if (this.options.effects)
    {
      if ((Effect.Queues.get("lightview_hide")).effects.length > 0)
        {
          return ;
        }
      Effect.Queues.get("lightview").each((function (A)
{
  A.cancel();
}
));
      new Effect.Fade(this.lightview, {duration : 0.1, queue : {position : "end", scope : "lightview_hide"}});
      new Effect.Fade(this.overlay, {duration : 0.5, queue : {position : "end", scope : "lightview_hide"}, afterFinish : this.afterHide.bind(this)});
    }
  else
    {
      this.lightview.hide();
      this.overlay.hide();
      this.afterHide();
    }
}
), afterHide : (function ()
{
  this.restoreCenter();
  this.center.setOpacity(0).show();
  this.prevnext.show();
  this.disableKeyboardNavigation();
  this.showOverlapping();
  $(this.element).fire("lightview:hidden");
  this.element = null;
  this.elements = null;
  this.set = null;
  this.scaledImageDimensions = null;
}
), setDataDimensions : (function ()
{
  var C = {}, B = this.scaledImageDimensions ? this.scaledImageDimensions.width : this.imageDimensions.width, D = this.lightview.getStyle("display"), A = this.center.getStyle("display");
  this.dataContainer.setStyle({width : B + "px"});
  this.data.setStyle({width : B - this.closeButtonWidth - 1 + "px"});
  this.center.setStyle({visibility : "hidden"}).show();
  this.lightview.setStyle({visibility : "hidden"}).show();
  C = this.dataContainer.getDimensions();
  this.lightview.setStyle({visibility : "visible", display : D});
  this.center.setStyle({visibility : "visible", display : A});
  this.dataContainer.setStyle({width : "100%"});
  return C;
}
), restoreCenter : (function ()
{
  if (this.fixIE)
    {
      return ;
    }
  var A = this.lightview.getDimensions();
  this.lightview.setStyle({position : "fixed", left : "50%", top : "50%", marginLeft : 0 - A.width / 2 + "px", marginTop : 0 - A.height / 2 + "px"});
}
), startSlideshow : (function ()
{
  this.stopSlideshow();
  this.sliding = true;
  this.next.bind(this).delay(0.25);
  this.slideshowButton.setStyle({background : "url(" + this.images + "slideshow_stop.jpg) top left no-repeat"}).hide();
}
), stopSlideshow : (function ()
{
  if (this.sliding)
    {
      this.sliding = false;
    }
  if (this.slideTimer)
    {
      clearTimeout(this.slideTimer);
    }
  this.slideshowButton.setStyle({background : "url(" + this.images + "slideshow_play.jpg) top left no-repeat"});
}
), toggleSlideshow : (function ()
{
	window.print();
//  this[((this.sliding ? "stop" : "start") + "Slideshow")]();
}
), nextSlide : (function ()
{
  if (this.sliding)
    {
      this.slideTimer = this.next.bind(this).delay(this.options.slideshow.delay);
    }
}
), enableKeyboardNavigation : (function ()
{
  this.keyboardEvent = this.keyboardDown.bindAsEventListener(this);
  document.observe("keydown", this.keyboardEvent);
}
), disableKeyboardNavigation : (function ()
{
  if (this.keyboardEvent)
    {
      document.stopObserving("keydown", this.keyboardEvent);
    }
}
), keyboardDown : (function (B)
{
  B.stop();
  var A = String.fromCharCode(B.keyCode).toLowerCase(), C = B.keyCode == Event.KEY_ESC || ["x", "c"].member(A) ? "hide" : B.keyCode == 37 && ! this.noset && ! this.resizing && this.position != 0 ? "previous" : B.keyCode == 39 && ! this.noset && ! this.resizing && (this.getSurroundingIndexes()).next != 0 ? "next" : A == "p" && ! this.noset ? "startSlideshow" : A == "s" && ! this.noset ? "stopSlideshow" : null;
  if (A != "s")
    {
      this.stopSlideshow();
    }
  if (C)
    {
      this[C]();
    }
  if (B.keyCode == Event.KEY_HOME && ! this.noset && ! this.resizing && this.elements.first() != this.element)
    {
      this.show(this.elements.first());
    }
  if (B.keyCode == Event.KEY_END && ! this.noset && ! this.resizing && this.elements.last() != this.element)
    {
      this.show(this.elements.last());
    }
}
), updateViews : (function ()
{
  this.sets = [];
  var A = $$("a[rel^=lightview]");
  A.invoke("stopObserving", "click");
  A.each((function (B)
{
  B.observe("click", this.show.curry(B).wrap((function (E,D)
{
  D.stop();
  E(D);
}
)).bindAsEventListener(this)).observe("mouseover", this.preloadImageHover.bind(this, B));
  var C = A.partition((function (D)
{
  return D.rel == B.rel;
}
));
  if (C[0].length)
    {
      this.sets.push({rel : B.rel, elements : C[0]});
      A = C[1];
    }
}
).bind(this));
}
), getSet : (function (A)
{
  return this.sets.find((function (B)
{
  return B.rel == A;
}
));
}
), addObservers : (function ()
{
  $(document.body).observe("click", this.bodyClick.bindAsEventListener(this));
  $w("prev next").each((function (A)
{
  this[(A + "Button")].observe("mouseover", this.toggleSideButton.bindAsEventListener(this)).observe("mouseout", this.toggleSideButton.bindAsEventListener(this)).observe("click", this[(A == "next" ? A : "previous")].wrap((function (C,B)
{
  this.stopSlideshow();
  C(B);
}
)).bindAsEventListener(this));
}
).bind(this));
  this.container.select("a.button").each((function (A)
{
  A.observe("mouseover", Element.setOpacity.bind(this, A, this.options.buttons.opacity.hover)).observe("mouseout", Element.setOpacity.bind(this, A, this.options.buttons.opacity.normal));
}
).bind(this));
  this.closeButton.observe("click", this.hide.bindAsEventListener(this));
  this.slideshowButton.observe("click", this.toggleSlideshow.bindAsEventListener(this));
}
), bodyClick : (function (B)
{
  var A = [this.overlay, this.left, this.right, this.loading.down()];
  if (Prototype.Browser.IE)
    {
      A.push(this.closeable);
    }
  if (B.target && A.include(B.target))
    {
      this.hide();
    }
}
), preloadImageHover : (function (A)
{
  if (A._lightviewPreloaded || ! A.rel || this.getPreloadedImageDimensions(A.rel))
    {
      return ;
    }
  this.preloadFromSet(A);
}
), preloadSurroundingImages : (function ()
{
  if (this.elements.length == 0)
    {
      return ;
    }
  surrounding = this.getSurroundingIndexes();
  this.preloadFromSet([surrounding.next, surrounding.previous]);
}
), preloadFromSet : (function (C)
{
  var B = this.elements && this.elements.member(C) || Object.isArray(C) ? this.elements : C.rel ? (this.getSet(C.rel)).elements : null;
  if (! B)
    {
      return ;
    }
  var A = $A(Object.isNumber(C) ? [C] : Object.isElement($(C)) ? [B.indexOf(C)] : C).uniq();
  A.each((function (F)
{
  var G = B[F], E = G.href;
  if (G._lightboxPreloaded || ! E || this.getPreloadedImageDimensions(E))
    {
      return ;
    }
  var D = new Image();
  D.onload = (function ()
{
  D.onload = Prototype.emptyFunction;
  this.preloadedImages.push({href : E, width : D.width, height : D.height});
  $$("a[href]").findAll((function (H)
{
  return H.href == E;
}
)).each((function (H)
{
  H._lightviewPreloaded = true;
}
));
}
).bind(this);
  D.src = E;
}
).bind(this));
}
), getPreloadedImageDimensions : (function (A)
{
  var B = this.preloadedImages.find((function (C)
{
  return C.href == A;
}
));
  return B ? {width : B.width, height : B.height} : null;
}
), toggleSideButton : (function (E)
{
  var C = E.element(), B = C.side, A = this.sideDimensions.width, F = E.type == "mouseover" ? 0 : B == "prev" ? A : - 1 * A, D = {marginLeft : F + "px"};
  if (this.options.effects)
    {
      if (! this.sideEffect)
        {
          this.sideEffect = {};
        }
      if (this.sideEffect[B])
        {
          Effect.Queues.get("lightview_side" + B).remove(this.sideEffect[B]);
        }
      this.sideEffect[B] = new Effect.Morph(this[(B + "ButtonImage")], {style : D, duration : 0.2, queue : {scope : "lightview_side" + B, limit : 1}});
    }
  else
    {
      this[(B + "ButtonImage")].setStyle(D);
    }
}
), getSurroundingIndexes : (function ()
{
  if (! this.elements)
    {
      return ;
    }
  var D = this.position, C = this.elements.length;
  var B = D <= 0 ? C - 1 : D - 1, A = D >= C - 1 ? 0 : D + 1;
  return {previous : B, next : A};
}
), createCorner : (function (C)
{
  var D, A = this.radius, B = this.border, F = new Element("canvas"), E = {top : C.charAt(0) == "t", left : C.charAt(1) == "l"};
  if (F && F.getContext && F.getContext("2d"))
    {
      D = new Element("canvas", {width : B + "px", height : B + "px", overflow : "hidden"}), ctx = D.getContext("2d");
      ctx.fillStyle = this.options.backgroundColor;
      ctx.arc(E.left ? A : B - A, E.top ? A : B - A, A, 0, Math.PI * 2, true);
      ctx.fill();
      ctx.fillRect(E.left ? A : 0, 0, B - A, B);
      ctx.fillRect(0, E.top ? A : 0, B, B - A);
    }
  else
    {
      D = new Element("div").setStyle({width : B + "px", height : B + "px", margin : 0, padding : 0, display : "block", position : "relative", overflow : "hidden"});
      D.insert(new Element("v:roundrect", {fillcolor : this.options.backgroundColor, strokeWeight : "1px", strokeColor : this.options.backgroundColor, arcSize : (A / B * 0.5).toFixed(2)}).setStyle({width : 2 * B - 1 + "px", height : 2 * B - 1 + "px", position : "absolute", left : (E.left ? 0 : - 1 * B) + "px", top : (E.top ? 0 : - 1 * B) + "px"}));
    }
  return D;
}
), hideOverlapping : (function ()
{
  if (this.preventingOverlap)
    {
      return ;
    }
  $$("select", "embed", "object").invoke("setStyle", {visibility : "hidden"});
  this.preventingOverlap = true;
}
), showOverlapping : (function ()
{
  $$("select", "embed", "object").invoke("setStyle", {visibility : "visible"});
  this.preventingOverlap = false;
}
), viewport : {getDimensions : (function ()
{
  var A = {};
  var C = Prototype.Browser;
  $w("width height").each((function (E)
{
  var B = E.capitalize();
  A[E] = C.WebKit && ! document.evaluate ? self[("inner" + B)] : C.Opera ? document.body[("client" + B)] : document.documentElement[("client" + B)];
}
));
  return A;
}
)}, pixelClone : (function (A)
{
  var B = {};
  Object.keys(A).each((function (C)
{
  B[C] = A[C] + "px";
}
));
  return B;
}
), fitsWithinViewport : (function ()
{
  var E = this.options.viewportPadding, D = 2 * this.border + this.sideDimensions.width, A = D + E, C = this.viewport.getDimensions();
  var B = this.getInnerSize(), F = this.getBounds(), G = {width : B.width + E, height : B.height + E};
  return G.width <= F.width || G.height <= F.height;
}
), getInnerDimensions : (function ()
{
  return {width : this.imageDimensions.width, height : this.imageDimensions.height + this.dataDimensions.height};
}
), getOuterDimensions : (function ()
{
  var B = this.getInnerDimensions(), A = 2 * this.border;
  return {width : B.width + A, height : B.height + A};
}
), getBounds : (function ()
{
  var C = 20, A = 2 * this.sideDimensions.height + C, B = this.viewport.getDimensions();
  return {width : B.width - A, height : B.height - A};
}
)});
  Lightview.load();
  document.observe("dom:loaded", Lightview.start.bind(Lightview));