var Shadowbox = function() { var ua = navigator.userAgent.toLowerCase(), S = { version : "3.0b", adapter : null, current : -1, gallery : [], cache : [], content : null, dimensions : null, plugins : null, path : "", options : { adapter : null, animate : true, animateFade : true, autoplayMovies : true, autoDimensions : false, continuous : false, counterLimit : 10, counterType : "default", displayCounter : true, displayNav : true, ease : function(x) { return 1 + Math.pow(x - 1, 3) }, enableKeys : true, errors : { fla : { name : "Flash", url : "http://www.adobe.com/products/flashplayer/" }, qt : { name : "QuickTime", url : "http://www.apple.com/quicktime/download/" }, wmp : { name : "Windows Media Player", url : "http://www.microsoft.com/windows/windowsmedia/" }, f4m : { name : "Flip4Mac", url : "http://www.flip4mac.com/wmv_download.htm" } }, ext : { img : [ "png", "jpg", "jpeg", "gif", "bmp" ], swf : [ "swf" ], flv : [ "flv" ], qt : [ "dv", "mov", "moov", "movie", "mp4" ], wmp : [ "asf", "wm", "wmv" ], qtwmp : [ "avi", "mpg", "mpeg" ], iframe : [ "asp", "aspx", "cgi", "cfm", "htm", "html", "jsp", "pl", "php", "php3", "php4", "php5", "phtml", "rb", "rhtml", "shtml", "txt", "vbs" ] }, fadeDuration : 0.35, flashParams : { bgcolor : "#000000", allowFullScreen : true }, flashVars : {}, flashVersion : "9.0.115", handleOversize : "resize", handleUnsupported : "link", initialHeight : 160, initialWidth : 320, language : "en", modal : false, onChange : null, onClose : null, onFinish : null, onOpen : null, overlayColor : "#000", overlayOpacity : 0.8, players : [ "img" ], resizeDuration : 0.35, showOverlay : true, showMovieControls : true, skipSetup : false, slideshowDelay : 0, useSizzle : true, viewportPadding : 20 }, client : { isIE : ua.indexOf("msie") > -1, isIE6 : ua.indexOf("msie 6") > -1, isIE7 : ua.indexOf("msie 7") > -1, isGecko : ua.indexOf("gecko") > -1 && ua.indexOf("safari") == -1, isWebkit : ua.indexOf("applewebkit/") > -1, isWindows : ua.indexOf("windows") > -1 || ua.indexOf("win32") > -1, isMac : ua.indexOf("macintosh") > -1 || ua.indexOf("mac os x") > -1, isLinux : ua.indexOf("linux") > -1 }, regex : { domain : /:\/\/(.*?)[:\/]/, inline : /#(.+)$/, rel : /^(light|shadow)box/i, gallery : /^(light|shadow)box\[(.*?)\]/i, unsupported : /^unsupported-(\w+)/, param : /\s*([a-z_]*?)\s*=\s*(.+)\s*/ }, libraries : { Prototype : "prototype", jQuery : "jquery", MooTools : "mootools", YAHOO : "yui", dojo : "dojo", Ext : "ext" }, applyOptions : function(opts) { if (opts) { default_options = apply( {}, S.options); apply(S.options, opts) } }, buildCacheObj : function(link, opts) { var href = link.href, obj = { el : link, title : link.getAttribute("title"), options : apply( {}, opts || {}), content : href }; each( [ "player", "title", "height", "width", "gallery" ], function(o) { if (typeof obj.options[o] != "undefined") { obj[o] = obj.options[o]; delete obj.options[o] } }); if (!obj.player) { obj.player = getPlayer(href) } var rel = link.getAttribute("rel"); if (rel) { var m = rel.match(S.regex.gallery); if (m) { obj.gallery = escape(m[2]) } each(rel.split(";"), function(p) { m = p.match(S.regex.param); if (m) { if (m[1] == "options") { eval("apply(obj.options," + m[2] + ")") } else { obj[m[1]] = m[2] } } }) } return obj }, change : function(n) { if (!S.gallery) { return } if (!S.gallery[n]) { if (!S.options.continuous) { return } else { n = n < 0 ? S.gallery.length - 1 : 0 } } S.current = n; if (typeof slide_timer == "number") { clearTimeout(slide_timer); slide_timer = null; slide_delay = slide_start = 0 } if (S.options.onChange) { S.options.onChange() } loadContent() }, clearCache : function() { each(S.cache, function(obj) { if (obj.el) { S.lib.removeEvent(obj.el, "click", handleClick) } }); S.cache = [] }, close : function() { if (!active) { return } active = false; listenKeys(false); if (S.content) { S.content.remove(); S.content = null } if (typeof slide_timer == "number") { clearTimeout(slide_timer) } slide_timer = null; slide_delay = 0; if (S.options.onClose) { S.options.onClose() } S.skin.onClose(); S.revertOptions(); each(v_cache, function(c) { c[0].style.visibility = c[1] }) }, contentId : function() { return content_id }, getCounter : function() { var len = S.gallery.length; if (S.options.counterType == "skip") { var c = [], i = 0, end = len, limit = parseInt(S.options.counterLimit) || 0; if (limit < len && limit > 2) { var h = Math.floor(limit / 2); i = S.current - h; if (i < 0) { i += len } end = S.current + (limit - h); if (end > len) { end -= len } } while (i != end) { if (i == len) { i = 0 } c.push(i++) } } else { var c = (S.current + 1) + " " + S.lang.of + " " + len } return c }, getCurrent : function() { return S.current > -1 ? S.gallery[S.current] : null }, hasNext : function() { return S.gallery.length > 1 && (S.current != S.gallery.length - 1 || S.options.continuous) }, init : function(opts) { if (initialized) { return } initialized = true; opts = opts || {}; init_options = opts; if (opts) { apply(S.options, opts) } for ( var e in S.options.ext) { S.regex[e] = new RegExp(".(" + S.options.ext[e].join("|") + ")s*$", "i") } if (!S.path) { var path_re = /(.+)shadowbox\.js/i, path; each(document.getElementsByTagName("script"), function(s) { if ((path = path_re.exec(s.src)) != null) { S.path = path[1]; return false } }) } if (S.options.adapter) { S.adapter = S.options.adapter } else { for ( var lib in S.libraries) { if (typeof window[lib] != "undefined") { S.adapter = S.libraries[lib]; break } } if (!S.adapter) { S.adapter = "base" } } if (S.options.useSizzle && !window.Sizzle) { U.include(S.path + "libraries/sizzle/sizzle.js") } if (!S.lang) { U.include(S.path + "languages/shadowbox-" + S.options.language + ".js") } each(S.options.players, function(p) { if ((p == "swf" || p == "flv") && !window.swfobject) { U.include(S.path + "libraries/swfobject/swfobject.js") } if (!S[p]) { U.include(S.path + "players/shadowbox-" + p + ".js") } }); if (!S.lib) { U.include(S.path + "adapters/shadowbox-" + S.adapter + ".js") } }, isActive : function() { return active }, isPaused : function() { return slide_timer == "paused" }, load : function() { if (S.skin.options) { apply(S.options, S.skin.options); apply(S.options, init_options) } var markup = S.skin.markup.replace(/\{(\w+)\}/g, function(m, p) { return S.lang[p] }); S.lib.append(document.body, markup); if (S.skin.init) { S.skin.init() } var id; S.lib.addEvent(window, "resize", function() { if (id) { clearTimeout(id); id = null } if (active) { id = setTimeout( function() { if (S.skin.onWindowResize) { S.skin.onWindowResize() } var c = S.content; if (c && c.onWindowResize) { c.onWindowResize() } }, 50) } }); if (!S.options.skipSetup) { S.setup() } }, next : function() { S.change(S.current + 1) }, open : function(obj) { if (U.isLink(obj)) { obj = S.buildCacheObj(obj) } if (obj.constructor == Array) { S.gallery = obj; S.current = 0 } else { if (!obj.gallery) { S.gallery = [ obj ]; S.current = 0 } else { S.current = null; S.gallery = []; each(S.cache, function(c) { if (c.gallery && c.gallery == obj.gallery) { if (S.current == null && c.content == obj.content && c.title == obj.title) { S.current = S.gallery.length } S.gallery.push(c) } }); if (S.current == null) { S.gallery.unshift(obj); S.current = 0 } } } obj = S.getCurrent(); if (obj.options) { S.revertOptions(); S.applyOptions(obj.options) } var g, r, m, s, a, oe = S.options.errors, msg, el; for ( var i = 0; i < S.gallery.length; ++i) { g = S.gallery[i] = apply( {}, S.gallery[i]); r = false; if (g.player == "unsupported") { r = true } else { if (m = S.regex.unsupported.exec(g.player)) { if (S.options.handleUnsupported == "link") { g.player = "html"; switch (m[1]) { case "qtwmp": s = "either"; a = [ oe.qt.url, oe.qt.name, oe.wmp.url, oe.wmp.name ]; break; case "qtf4m": s = "shared"; a = [ oe.qt.url, oe.qt.name, oe.f4m.url, oe.f4m.name ]; break; default: s = "single"; if (m[1] == "swf" || m[1] == "flv") { m[1] = "fla" } a = [ oe[m[1]].url, oe[m[1]].name ] } msg = S.lang.errors[s].replace(/\{(\d+)\}/g, function(m, n) { return a[n] }); g.content = '
' + msg + "
" } else { r = true } } else { if (g.player == "inline") { m = S.regex.inline.exec(g.content); if (m) { var el = U.get(m[1]); if (el) { g.content = el.innerHTML } else { throw "Cannot find element with id " + m[1] } } else { throw "Cannot find element id for inline content" } } else { if (g.player == "swf" || g.player == "flv") { var version = (g.options && g.options.flashVersion) || S.options.flashVersion; if (!swfobject.hasFlashPlayerVersion(version)) { g.width = 310; g.height = 177 } } } } } if (r) { S.gallery.splice(i, 1); if (i < S.current) { --S.current } else { if (i == S.current) { S.current = i > 0 ? i - 1 : i } } --i } } if (S.gallery.length) { if (!active) { if (typeof S.options.onOpen == "function" && S.options.onOpen(obj) === false) { return } v_cache = []; each( [ "select", "object", "embed", "canvas" ], function( tag) { each(document.getElementsByTagName(tag), function(el) { v_cache.push( [ el, el.style.visibility || "visible" ]); el.style.visibility = "hidden" }) }); var h = S.options.autoDimensions && "height" in obj ? obj.height : S.options.initialHeight; var w = S.options.autoDimensions && "width" in obj ? obj.width : S.options.initialWidth; S.skin.onOpen(h, w, loadContent) } else { loadContent() } active = true } }, pause : function() { if (typeof slide_timer != "number") { return } var time = new Date().getTime(); slide_delay = Math.max(0, slide_delay - (time - slide_start)); if (slide_delay) { clearTimeout(slide_timer); slide_timer = "paused"; if (S.skin.onPause) { S.skin.onPause() } } }, play : function() { if (!S.hasNext()) { return } if (!slide_delay) { slide_delay = S.options.slideshowDelay * 1000 } if (slide_delay) { slide_start = new Date().getTime(); slide_timer = setTimeout( function() { slide_delay = slide_start = 0; S.next() }, slide_delay); if (S.skin.onPlay) { S.skin.onPlay() } } }, previous : function() { S.change(S.current - 1) }, revertOptions : function() { apply(S.options, default_options) }, sedivimensions : function(height, width, max_h, max_w, tb, lr, resizable) { var h = height = parseInt(height), w = width = parseInt(width), pad = parseInt(S.options.viewportPadding) || 0; var extra_h = 2 * pad + tb; if (h + extra_h >= max_h) { h = max_h - extra_h } var extra_w = 2 * pad + lr; if (w + extra_w >= max_w) { w = max_w - extra_w } var resize_h = height, resize_w = width, change_h = (height - h) / height, change_w = (width - w) / width, oversized = (change_h > 0 || change_w > 0); if (resizable && oversized && S.options.handleOversize == "resize") { if (change_h > change_w) { w = Math.round((width / height) * h) } else { if (change_w > change_h) { h = Math.round((height / width) * w) } } resize_w = w; resize_h = h } S.dimensions = { height : h + tb, width : w + lr, inner_h : h, inner_w : w, top : (max_h - (h + extra_h)) / 2 + pad, left : (max_w - (w + extra_w)) / 2 + pad, oversized : oversized, resize_h : resize_h, resize_w : resize_w }; return S.dimensions }, setup : function(links, opts) { if (!links) { var links = [], rel; each(document.getElementsByTagName("a"), function(a) { rel = a.getAttribute("rel"); if (rel && S.regex.rel.test(rel)) { links.push(a) } }) } else { var len = links.length; if (len) { if (window.Sizzle) { if (typeof links == "string") { links = Sizzle(links) } else { if (len == 2 && links.push && typeof links[0] == "string" && links[1].nodeType) { links = Sizzle(links[0], links[1]) } } } } else { links = [ links ] } } each(links, function(link) { if (typeof link.shadowboxCacheKey == "undefined") { link.shadowboxCacheKey = S.cache.length; S.lib.addEvent(link, "click", handleClick) } S.cache[link.shadowboxCacheKey] = S.buildCacheObj(link, opts) }) } }, U = S.util = { animate : function(el, p, to, d, cb) { var from = parseFloat(S.lib.getStyle(el, p)); if (isNaN(from)) { from = 0 } var delta = to - from; if (delta == 0) { if (cb) { cb() } return } var op = p == "opacity"; function fn(ease) { var to = from + ease * delta; if (op) { U.setOpacity(el, to) } else { el.style[p] = to + "px" } } if (!d || (!op && !S.options.animate) || (op && !S.options.animateFade)) { fn(1); if (cb) { cb() } return } d *= 1000; var begin = new Date().getTime(), end = begin + d, time, timer = setInterval( function() { time = new Date().getTime(); if (time >= end) { clearInterval(timer); fn(1); if (cb) { cb() } } else { fn(S.options.ease((time - begin) / d)) } }, 10) }, apply : function(o, e) { for ( var p in e) { o[p] = e[p] } return o }, clearOpacity : function(el) { var s = el.style; if (window.ActiveXObject) { if (typeof s.filter == "string" && (/alpha/i).test(s.filter)) { s.filter = s.filter.replace(/[\w\.]*alpha\(.*?\);?/i, "") } } else { s.opacity = "" } }, each : function(obj, fn, scope) { for ( var i = 0, len = obj.length; i < len; ++i) { if (fn.call(scope || obj[i], obj[i], i, obj) === false) { return } } }, get : function(id) { return document.getElementById(id) }, include : function() { var includes = {}; return function(file) { if (includes[file]) { return } includes[file] = true; document.write('