/*!
 * jQuery Tools v1.2.5 - The missing UI library for the Web
 * 
 * overlay/overlay.js
 * overlay/overlay.apple.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 */
(function(b) {
  function n(a, d) {
    var c = this, e = a.add(c), i = b(window), l, g, j, h = b.tools.expose && (d.mask || d.expose), f = Math.random().toString().slice(10);
    h && (typeof h == "string" && (h = {color:h}), h.closeOnClick = h.closeOnEsc = !1);
    var m = d.target || a.attr("rel");
    g = m ? b(m) : a;
    if(!g.length) {
      //throw"Could not find Overlay: " + m;
    }
    a && a.index(g) == -1 && a.click(function(b) {
      c.load(b);
      return b.preventDefault()
    });
    b.extend(c, {load:function(a) {
      if(c.isOpened()) {
        return c
      }
      var l = k[d.effect];
      if(!l) {
        throw'Overlay: cannot find effect : "' + d.effect + '"';
      }
      d.oneInstance && b.each(o, function() {
        this.close(a)
      });
      a = a || b.Event();
      a.type = "onBeforeLoad";
      e.trigger(a);
      if(a.isDefaultPrevented()) {
        return c
      }
      j = !0;
      h && b(g).expose(h);
      var p = d.top, m = d.left, n = g.outerWidth({margin:!0}), q = g.outerHeight({margin:!0});
      typeof p == "string" && (p = p == "center" ? Math.max((i.height() - q) / 2, 0) : parseInt(p, 10) / 100 * i.height());
      m == "center" && (m = Math.max((i.width() - n) / 2, 0));
      l[0].call(c, {top:p, left:m}, function() {
        j && (a.type = "onLoad", e.trigger(a))
      });
      h && d.closeOnClick && b.mask.getMask().one("click", c.close);
      d.closeOnClick && b(document).bind("click." + f, function(a) {
        b(a.target).parents(g).length || c.close(a)
      });
      d.closeOnEsc && b(document).bind("keydown." + f, function(a) {
        a.keyCode == 27 && c.close(a)
      });
      return c
    }, close:function(a) {
      if(!c.isOpened()) {
        return c
      }
      a = a || b.Event();
      a.type = "onBeforeClose";
      e.trigger(a);
      if(!a.isDefaultPrevented()) {
        return j = !1, k[d.effect][1].call(c, function() {
          a.type = "onClose";
          e.trigger(a)
        }), b(document).unbind("click." + f).unbind("keydown." + f), h && b.mask.close(), c
      }
    }, getOverlay:function() {
      return g
    }, getTrigger:function() {
      return a
    }, getClosers:function() {
      return l
    }, isOpened:function() {
      return j
    }, getConf:function() {
      return d
    }});
    b.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","), function(a, e) {
      b.isFunction(d[e]) && b(c).bind(e, d[e]);
      c[e] = function(a) {
        a && b(c).bind(e, a);
        return c
      }
    });
    l = g.find(d.close || ".close");
    !l.length && !d.close && (l = b('<a class="close"></a>'), g.prepend(l));
    l.click(function(a) {
      c.close(a)
    });
    d.load && c.load()
  }
  b.tools = b.tools || {version:"v1.2.5"};
  b.tools.overlay = {addEffect:function(a, b, c) {
    k[a] = [b, c]
  }, conf:{close:null, closeOnClick:!0, closeOnEsc:!0, closeSpeed:"fast", effect:"default", fixed:!b.browser.msie || b.browser.version > 6, left:"center", load:!1, mask:null, oneInstance:!0, speed:"normal", target:null, top:"10%"}};
  var o = [], k = {};
  b.tools.overlay.addEffect("default", function(a, d) {
    var c = this.getConf(), e = b(window);
    c.fixed || (a.top += e.scrollTop(), a.left += e.scrollLeft());
    a.position = c.fixed ? "fixed" : "absolute";
    this.getOverlay().css(a).fadeIn(c.speed, d)
  }, function(a) {
    this.getOverlay().fadeOut(this.getConf().closeSpeed, a)
  });
  b.fn.overlay = function(a) {
    var d = this.data("overlay");
    if(d) {
      return d
    }
    b.isFunction(a) && (a = {onBeforeLoad:a});
    a = b.extend(!0, {}, b.tools.overlay.conf, a);
    this.each(function() {
      d = new n(b(this), a);
      o.push(d);
      b(this).data("overlay", d)
    });
    return a.api ? d : this
  }
})(jQuery);


(function(b) {
  function n(a) {
    var b = a.offset();
    return{top:b.top + a.height() / 2, left:b.left + a.width() / 2}
  }
  var o = b.tools.overlay, k = b(window);
  b.extend(o.conf, {start:{top:null, left:null}, fadeInSpeed:"fast", zIndex:9999});
  o.addEffect("apple", function(a, d) {
    var c = this.getOverlay(), e = this.getConf(), i = this.getTrigger(), l = this, g = c.outerWidth({margin:!0}), j = c.data("img"), h = e.fixed ? "fixed" : "absolute";
    if(!j) {
      var f = c.css("backgroundImage");
      if(!f) {
        //throw"background-image CSS property not set for overlay";
      }
      f = f.slice(f.indexOf("(") + 1, f.indexOf(")")).replace(/\"/g, "");
      c.css("backgroundImage", "none");
      j = b('<img src="' + f + '"/>');
      j.css({border:0, display:"none"}).width(g);
      b("body").append(j);
      c.data("img", j)
    }
    var f = e.start.top || Math.round(k.height() / 2), m = e.start.left || Math.round(k.width() / 2);
    if(i) {
      i = n(i), f = i.top, m = i.left
    }
    e.fixed ? (f -= k.scrollTop(), m -= k.scrollLeft()) : (a.top += k.scrollTop(), a.left += k.scrollLeft());
    j.css({position:"absolute", top:f, left:m, width:0, zIndex:e.zIndex}).show();
    a.position = h;
    c.css(a);
    j.animate({top:c.css("top"), left:c.css("left"), width:g}, e.speed, function() {
      c.css("zIndex", e.zIndex + 1).fadeIn(e.fadeInSpeed, function() {
        l.isOpened() && !b(this).index(c) ? d.call() : c.hide()
      })
    }).css("position", h)
  }, function(a) {
    var d = this.getOverlay().hide(), c = this.getConf(), e = this.getTrigger(), d = d.data("img"), i = {top:c.start.top, left:c.start.left, width:0};
    e && b.extend(i, n(e));
    c.fixed && d.css({position:"absolute"}).animate({top:"+=" + k.scrollTop(), left:"+=" + k.scrollLeft()}, 0);
    d.animate(i, c.closeSpeed, a)
  })
})(jQuery);
