/**
 * Overlay Gallery plugin, version: 1.0.0
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/overlay.html#gallery
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Since  : July 2009
 * Date: ${date}
 * Revision: ${revision} 
 */
(function(a) { var b = a.tools.overlay; b.plugins = b.plugins || {}; b.plugins.gallery = { version: "1.0.0", conf: { imgId: "img", next: ".next", prev: ".prev", info: ".info", progress: ".progress", disabledClass: "disabled", activeClass: "active", opacity: .8, speed: "slow", template: "<strong>${title}</strong> <span>Image ${index} of ${total}</span>", autohide: true, preload: true, api: false} }; a.fn.gallery = function(r) { var c = a.extend({}, b.plugins.gallery.conf), m; a.extend(c, r); m = this.overlay(); var e = this, d = m.getOverlay(), k = d.find(c.next), l = d.find(c.prev), j = d.find(c.info), o = d.find(c.progress), g = l.add(k).add(j).css({ opacity: c.opacity }), h = m.getClosers(), f; function q(m) { o.fadeIn(); g.hide(); h.hide(); var i = m.attr("href"), b = new Image; b.onload = function() { o.fadeOut(); var n = a("#" + c.imgId, d); if (!n.length) { n = a("<img/>").attr("id", c.imgId).css("visibility", "hidden"); d.prepend(n) } n.attr("src", i).css("visibility", "hidden"); var p = b.width, t = (a(window).width() - p) / 2; f = e.index(e.filter("[href=" + i + "]")); e.removeClass(c.activeClass).eq(f).addClass(c.activeClass); var q = c.disabledClass; g.removeClass(q); f === 0 && l.addClass(q); f == e.length - 1 && k.addClass(q); var v = c.template.replace("${title}", m.attr("title") || m.data("title")).replace("${index}", f + 1).replace("${total}", e.length), u = parseInt(j.css("paddingLeft"), 10) + parseInt(j.css("paddingRight"), 10); j.html(v).css({ width: p - u }); d.animate({ width: p, height: b.height, left: t }, c.speed, function() { n.hide().css("visibility", "visible").fadeIn(function() { if (!c.autohide) { g.fadeIn(); h.show() } }) }); if (c.preload) { var r = e.eq(f + 1); if (r.length) { var s = new Image; s.src = r.attr("href") } } }; b.onerror = function() { d.fadeIn().html("Cannot find image " + i) }; b.src = i } function n(a, b) { a.click(function() { if (a.hasClass(c.disabledClass)) return; var d = e.eq(i = f + (b ? 1 : -1)); d.length && q(d) }) } n(k, true); n(l); a(document).keydown(function(a) { if (!d.is(":visible") || a.altKey || a.ctrlKey) return; if (a.keyCode == 37 || a.keyCode == 39) { var b = a.keyCode == 37 ? l : k; b.click(); return a.preventDefault() } return true }); function p() { if (!d.is(":animated")) { g.show(); h.show() } } c.autohide && d.hover(p, function() { g.fadeOut(); h.hide() }).mousemove(p); var s; this.each(function() { var d = a(this), b = a(this).overlay(), f = b; b.onBeforeLoad(function() { q(d) }); b.onClose(function() { e.removeClass(c.activeClass) }) }); return c.api ? s : this } })(jQuery)
