Colorbox vs Fancybox

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Colorbox
// ColorBox v1.4.0 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
// Copyright (c) 2011 Jack Moore - jacklmoore.com
// License: http://www.opensource.org/licenses/mit-license.php

;(function ($, document, window) {
    var
    // Default settings object. 
    // See http://jacklmoore.com/colorbox for details.
    defaults = {
        transition: "elastic",
        speed: 300,
        width: false,
        initialWidth: "600",
        innerWidth: false,
        maxWidth: false,
        height: false,
        initialHeight: "450",
        innerHeight: false,
        maxHeight: false,
        scalePhotos: true,
        scrolling: true,
        inline: false,
        html: false,
        iframe: false,
        fastIframe: true,
        photo: false,
        href: false,
        title: false,
        rel: false,
        opacity: 0.9,
        preloading: true,
        current: "image {current} of {total}",
        previous: "previous",
        next: "next",
        close: "close",
        open: false,
        returnFocus: true,
        reposition: true,
        loop: true,
        slideshow: false,
        slideshowAuto: true,
        slideshowSpeed: 2500,
        slideshowStart: "start slideshow",
        slideshowStop: "stop slideshow",
        onOpen: false,
        onLoad: false,
        onComplete: false,
        onCleanup: false,
        onClosed: false,
        overlayClose: true,             
        escKey: true,
        arrowKey: true,
        top: false,
        bottom: false,
        left: false,
        right: false,
        fixed: false,
        data: undefined
    },
        
    // Abstracting the HTML and event identifiers for easy rebranding
    colorbox = 'colorbox',
    prefix = 'cbox',
    boxElement = prefix + 'Element',
    
    // Events   
    event_open = prefix + '_open',
    event_load = prefix + '_load',
    event_complete = prefix + '_complete',
    event_cleanup = prefix + '_cleanup',
    event_closed = prefix + '_closed',
    event_purge = prefix + '_purge',
    
    // Special Handling for IE
    isIE = $.browser.msie && !$.support.opacity, // Detects IE6,7,8.  IE9 supports opacity.  Feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome, hence the user-agent test.
    isIE6 = isIE && $.browser.version < 7,
    event_ie6 = prefix + '_IE6',
    
    // Cached jQuery Object Variables
    $overlay,
    $box,
    $wrap,
    $content,
    $topBorder,
    $leftBorder,
    $rightBorder,
    $bottomBorder,
    $related,
    $window,
    $loaded,
    $loadingBay,
    $loadingOverlay,
    $title,
    $current,
    $slideshow,
    $next,
    $prev,
    $close,
    $groupControls,
    
    // Variables for cached values or use across multiple functions
    settings,
    interfaceHeight,
    interfaceWidth,
    loadedHeight,
    loadedWidth,
    element,
    index,
    photo,
    open,
    active,
    closing,
    loadingTimer,
    publicMethod,
    div = "div";

        // ****************
        // HELPER FUNCTIONS
        // ****************
    
        // Convience function for creating new jQuery objects
    function $tag(tag, id, css) {
                var element = document.createElement(tag);

                if (id) {
                        element.id = prefix + id;
                }

                if (css) {
                        element.style.cssText = css;
                }
                
                return $(element);
    }

        // Determine the next and previous members in a group.
        function getIndex(increment) {
                var 
                max = $related.length, 
                newIndex = (index + increment) % max;
                
                return (newIndex < 0) ? max + newIndex : newIndex;
        }

        // Convert '%' and 'px' values to integers
        function setSize(size, dimension) {
                return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : $window.height()) / 100) : 1) * parseInt(size, 10));
        }
        
        // Checks an href to see if it is a photo.
        // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
        function isImage(url) {
                return settings.photo || /\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(url);
        }
        
        // Assigns function results to their respective properties
        function makeSettings() {
        var i;
        settings = $.extend({}, $.data(element, colorbox));
        
                for (i in settings) {
                        if ($.isFunction(settings[i]) && i.slice(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
                            settings[i] = settings[i].call(element);
                        }
                }
        
                settings.rel = settings.rel || element.rel || 'nofollow';
                settings.href = settings.href || $(element).attr('href');
                settings.title = settings.title || element.title;
        
        if (typeof settings.href === "string") {
            settings.href = $.trim(settings.href);
        }
        }

        function trigger(event, callback) {
                $.event.trigger(event);
                if (callback) {
                        callback.call(element);
                }
        }

        // Slideshow functionality
        function slideshow() {
                var
                timeOut,
                className = prefix + "Slideshow_",
                click = "click." + prefix,
                start,
                stop,
                clear;
                
                if (settings.slideshow && $related[1]) {
                        start = function () {
                                $slideshow
                                        .text(settings.slideshowStop)
                                        .unbind(click)
                                        .bind(event_complete, function () {
                                                if (settings.loop || $related[index + 1]) {
                                                        timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
                                                }
                                        })
                                        .bind(event_load, function () {
                                                clearTimeout(timeOut);
                                        })
                                        .one(click + ' ' + event_cleanup, stop);
                                $box.removeClass(className + "off").addClass(className + "on");
                                timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
                        };
                        
                        stop = function () {
                                clearTimeout(timeOut);
                                $slideshow
                                        .text(settings.slideshowStart)
                                        .unbind([event_complete, event_load, event_cleanup, click].join(' '))
                                        .one(click, function () {
                                                publicMethod.next();
                                                start();
                                        });
                                $box.removeClass(className + "on").addClass(className + "off");
                        };
                        
                        if (settings.slideshowAuto) {
                                start();
                        } else {
                                stop();
                        }
                } else {
            $box.removeClass(className + "off " + className + "on");
        }
        }

        function launch(target) {
                if (!closing) {
                        
                        element = target;
                        
                        makeSettings();
                        
                        $related = $(element);
                        
                        index = 0;
                        
                        if (settings.rel !== 'nofollow') {
                                $related = $('.' + boxElement).filter(function () {
                                        var relRelated = $.data(this, colorbox).rel || this.rel;
                                        return (relRelated === settings.rel);
                                });
                                index = $related.index(element);
                                
                                // Check direct calls to ColorBox.
                                if (index === -1) {
                                        $related = $related.add(element);
                                        index = $related.length - 1;
                                }
                        }
                        
                        if (!open) {
                                open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
                                
                                $box.show();
                                
                                if (settings.returnFocus) {
                                        try {
                                                element.blur();
                                                $(element).one(event_closed, function () {
                                                        try {
                                                                this.focus();
                                                        } catch (e) {
                                                                // do nothing
                                                        }
                                                });
                                        } catch (e) {
                                                // do nothing
                                        }
                                }
                                
                                // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
                                $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
                                
                                // Opens inital empty ColorBox prior to content being loaded.
                                settings.w = setSize(settings.initialWidth, 'x');
                                settings.h = setSize(settings.initialHeight, 'y');
                                publicMethod.position();
                                
                                if (isIE6) {
                                        $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
                                                $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
                                        }).trigger('resize.' + event_ie6);
                                }
                                
                                trigger(event_open, settings.onOpen);
                                
                                $groupControls.add($title).hide();
                                
                                $close.html(settings.close).show();
                        }
                        
                        publicMethod.load(true);
                }
        }

        // ****************
        // PUBLIC FUNCTIONS
        // Usage format: $.fn.colorbox.close();
        // Usage from within an iframe: parent.$.fn.colorbox.close();
        // ****************
        
        publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
                var $this = this;
                
        options = options || {};
        
                publicMethod.init();
                
                if (!$this[0]) {
                        if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
                return $this;
            }
            // if no selector was given (ie. $.colorbox()), create a temporary element to work with
                        $this = $('<a/>');
                        options.open = true; // assume an immediate open
                }
                
                if (callback) {
                        options.onComplete = callback;
                }
                
                $this.each(function () {
                        $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
                }).addClass(boxElement);
                
        if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
                        launch($this[0]);
                }
        
                return $this;
        };

        // Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
        // This preps ColorBox for a speedy open when clicked, and minimizes the burdon on the browser by only
        // having to run once, instead of each time colorbox is opened.
        publicMethod.init = function () {
                if (!$box) {
                        
                        // If the body is not present yet, wait for DOM ready
                        if (!$('body')[0]) {
                                $(publicMethod.init);
                                return;
                        }
                        
                        // Create the markup and append to BODY
                        $window = $(window);
                        $box = $tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''});
                        $overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
                        $wrap = $tag(div, "Wrapper");
                        $content = $tag(div, "Content").append(
                                $loaded = $tag(div, "LoadedContent", 'width:0; height:0; overflow:hidden'),
                                $loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic")),
                                $title = $tag(div, "Title"),
                                $current = $tag(div, "Current"),
                                $next = $tag(div, "Next"),
                                $prev = $tag(div, "Previous"),
                                $slideshow = $tag(div, "Slideshow").bind(event_open, slideshow),
                                $close = $tag(div, "Close")
                        );
                        
                        $wrap.append( // The 3x3 Grid that makes up ColorBox
                                $tag(div).append(
                                        $tag(div, "TopLeft"),
                                        $topBorder = $tag(div, "TopCenter"),
                                        $tag(div, "TopRight")
                                ),
                                $tag(div, false, 'clear:left').append(
                                        $leftBorder = $tag(div, "MiddleLeft"),
                                        $content,
                                        $rightBorder = $tag(div, "MiddleRight")
                                ),
                                $tag(div, false, 'clear:left').append(
                                        $tag(div, "BottomLeft"),
                                        $bottomBorder = $tag(div, "BottomCenter"),
                                        $tag(div, "BottomRight")
                                )
                        ).find('div div').css({'float': 'left'});
                        
                        $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
                        
                        $('body').append($overlay, $box.append($wrap, $loadingBay));
                        
                        // Cache values needed for size calculations
                        interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
                        interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
                        loadedHeight = $loaded.outerHeight(true);
                        loadedWidth = $loaded.outerWidth(true);
                        
                        // Setting padding to remove the need to do size conversions during the animation step.
                        $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
                        
                        // Setup button events.
                        // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
                        $next.click(function () {
                                publicMethod.next();
                        });
                        $prev.click(function () {
                                publicMethod.prev();
                        });
                        $close.click(function () {
                                publicMethod.close();
                        });
                        
                        $groupControls = $next.add($prev).add($current).add($slideshow);
                        
                        $overlay.click(function () {
                                if (settings.overlayClose) {
                                        publicMethod.close();
                                }
                        });
                        
                        // Set Navigation Key Bindings
                        $(document).bind('keydown.' + prefix, function (e) {
                                var key = e.keyCode;
                                if (open && settings.escKey && key === 27) {
                                        e.preventDefault();
                                        publicMethod.close();
                                }
                                if (open && settings.arrowKey && $related[1]) {
                                        if (key === 37) {
                                                e.preventDefault();
                                                $prev.click();
                                        } else if (key === 39) {
                                                e.preventDefault();
                                                $next.click();
                                        }
                                }
                        });
                }
        };
        
        publicMethod.remove = function () {
                $box.add($overlay).remove();
                $box = null;
                $('.' + boxElement).removeData(colorbox).removeClass(boxElement);
        };

        publicMethod.position = function (speed, loadedCallback) {
        var top = 0, left = 0, offset = $box.offset();
        
        $window.unbind('resize.' + prefix);

        // remove the modal so that it doesn't influence the document width/height        
        $box.css({top: -99999, left: -99999});

        if (settings.fixed && !isIE6) {
            $box.css({position: 'fixed'});
        } else {
            top = $window.scrollTop();
            left = $window.scrollLeft();
            $box.css({position: 'absolute'});
        }

                // keeps the top and left positions within the browser's viewport.
        if (settings.right !== false) {
            left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
        } else if (settings.left !== false) {
            left += setSize(settings.left, 'x');
        } else {
            left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
        }
        
        if (settings.bottom !== false) {
            top += Math.max($window.height() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
        } else if (settings.top !== false) {
            top += setSize(settings.top, 'y');
        } else {
            top += Math.round(Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
        }
        
        $box.css({top: offset.top, left: offset.left});
        
                // setting the speed to 0 to reduce the delay between same-sized content.
                speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
        
                // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
                // but it has to be shrank down around the size of div#colorbox when it's done.  If not,
                // it can invoke an obscure IE bug when using iframes.
                $wrap[0].style.width = $wrap[0].style.height = "9999px";
                
                function modalDimensions(that) {
                        // loading overlay height has to be explicitly set for IE6.
                        $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
                        $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
                }
                
                $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
                        duration: speed,
                        complete: function () {
                                modalDimensions(this);
                                
                                active = false;
                                
                                // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
                                $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
                                $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
                
                if (settings.reposition) {
                        setTimeout(function () {  // small delay before binding onresize due to an IE8 bug.
                            $window.bind('resize.' + prefix, publicMethod.position);
                        }, 1);
                    }

                                if (loadedCallback) {
                                        loadedCallback();
                                }
                        },
                        step: function () {
                                modalDimensions(this);
                        }
                });
        };

        publicMethod.resize = function (options) {
                if (open) {
                        options = options || {};
                        
                        if (options.width) {
                                settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
                        }
                        if (options.innerWidth) {
                                settings.w = setSize(options.innerWidth, 'x');
                        }
                        $loaded.css({width: settings.w});
                        
                        if (options.height) {
                                settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
                        }
                        if (options.innerHeight) {
                                settings.h = setSize(options.innerHeight, 'y');
                        }
                        if (!options.innerHeight && !options.height) {
                                $loaded.css({height: "auto"});
                                settings.h = $loaded.height();
                        }
                        $loaded.css({height: settings.h});
                        
                        publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
                }
        };

        publicMethod.prep = function (object) {
                if (!open) {
                        return;
                }
                
                var callback, speed = settings.transition === "none" ? 0 : settings.speed;
                
                $loaded.remove();
                $loaded = $tag(div, 'LoadedContent').append(object);
                
                function getWidth() {
                        settings.w = settings.w || $loaded.width();
                        settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
                        return settings.w;
                }
                function getHeight() {
                        settings.h = settings.h || $loaded.height();
                        settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
                        return settings.h;
                }
                
                $loaded.hide()
                .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
                .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
                .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
                .prependTo($content);
                
                $loadingBay.hide();
                
                // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
                //$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
                
        $(photo).css({'float': 'none'});
        
                // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
                if (isIE6) {
                        $('select').not($box.find('select')).filter(function () {
                                return this.style.visibility !== 'hidden';
                        }).css({'visibility': 'hidden'}).one(event_cleanup, function () {
                                this.style.visibility = 'inherit';
                        });
                }
                
                callback = function () {
            var preload, i, total = $related.length, iframe, frameBorder = 'frameBorder', allowTransparency = 'allowTransparency', complete, src, img;
            
            if (!open) {
                return;
            }
            
            function removeFilter() {
                if (isIE) {
                    $box[0].style.removeAttribute('filter');
                }
            }
            
            complete = function () {
                clearTimeout(loadingTimer);
                $loadingOverlay.hide();
                trigger(event_complete, settings.onComplete);
            };
            
            if (isIE) {
                //This fadeIn helps the bicubic resampling to kick-in.
                if (photo) {
                    $loaded.fadeIn(100);
                }
            }
            
            $title.html(settings.title).add($loaded).show();
            
            if (total > 1) { // handle grouping
                if (typeof settings.current === "string") {
                    $current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
                }
                
                $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
                $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
                                
                if (settings.slideshow) {
                    $slideshow.show();
                }
                                
                // Preloads images within a rel group
                if (settings.preloading) {
                                        preload = [
                                                getIndex(-1),
                                                getIndex(1)
                                        ];
                                        while (i = $related[preload.pop()]) {
                                                src = $.data(i, colorbox).href || i.href;
                                                if ($.isFunction(src)) {
                                                        src = src.call(i);
                                                }
                                                if (isImage(src)) {
                                                        img = new Image();
                                                        img.src = src;
                                                }
                                        }
                }
            } else {
                $groupControls.hide();
            }
            
            if (settings.iframe) {
                iframe = $tag('iframe')[0];
                
                if (frameBorder in iframe) {
                    iframe[frameBorder] = 0;
                }
                if (allowTransparency in iframe) {
                    iframe[allowTransparency] = "true";
                }
                // give the iframe a unique name to prevent caching
                iframe.name = prefix + (+new Date());
                if (settings.fastIframe) {
                    complete();
                } else {
                    $(iframe).one('load', complete);
                }
                iframe.src = settings.href;
                if (!settings.scrolling) {
                    iframe.scrolling = "no";
                }
                $(iframe).addClass(prefix + 'Iframe').appendTo($loaded).one(event_purge, function () {
                    iframe.src = "//about:blank";
                });
            } else {
                complete();
            }
            
            if (settings.transition === 'fade') {
                $box.fadeTo(speed, 1, removeFilter);
            } else {
                removeFilter();
            }
                };
                
                if (settings.transition === 'fade') {
                        $box.fadeTo(speed, 0, function () {
                                publicMethod.position(0, callback);
                        });
                } else {
                        publicMethod.position(speed, callback);
                }
        };

        publicMethod.load = function (launched) {
                var href, setResize, prep = publicMethod.prep;
                
                active = true;
                
                photo = false;
                
                element = $related[index];
                
                if (!launched) {
                        makeSettings();
                }
                
                trigger(event_purge);
                
                trigger(event_load, settings.onLoad);
                
                settings.h = settings.height ?
                                setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
                                settings.innerHeight && setSize(settings.innerHeight, 'y');
                
                settings.w = settings.width ?
                                setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
                                settings.innerWidth && setSize(settings.innerWidth, 'x');
                
                // Sets the minimum dimensions for use in image scaling
                settings.mw = settings.w;
                settings.mh = settings.h;
                
                // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
                // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
                if (settings.maxWidth) {
                        settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
                        settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
                }
                if (settings.maxHeight) {
                        settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
                        settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
                }
                
                href = settings.href;
                
        loadingTimer = setTimeout(function () {
            $loadingOverlay.show();
        }, 100);
        
                if (settings.inline) {
                        // Inserts an empty placeholder where inline content is being pulled from.
                        // An event is bound to put inline content back when ColorBox closes or loads new content.
                        $tag(div).hide().insertBefore($(href)[0]).one(event_purge, function () {
                                $(this).replaceWith($loaded.children());
                        });
                        prep($(href));
                } else if (settings.iframe) {
                        // IFrame element won't be added to the DOM until it is ready to be displayed,
                        // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
                        prep(" ");
                } else if (settings.html) {
                        prep(settings.html);
                } else if (isImage(href)) {
                        $(photo = new Image())
                        .addClass(prefix + 'Photo')
                        .error(function () {
                                settings.title = false;
                                prep($tag(div, 'Error').text('This image could not be loaded'));
                        })
                        .load(function () {
                                var percent;
                                photo.onload = null; //stops animated gifs from firing the onload repeatedly.
                                
                                if (settings.scalePhotos) {
                                        setResize = function () {
                                                photo.height -= photo.height * percent;
                                                photo.width -= photo.width * percent;   
                                        };
                                        if (settings.mw && photo.width > settings.mw) {
                                                percent = (photo.width - settings.mw) / photo.width;
                                                setResize();
                                        }
                                        if (settings.mh && photo.height > settings.mh) {
                                                percent = (photo.height - settings.mh) / photo.height;
                                                setResize();
                                        }
                                }
                                
                                if (settings.h) {
                                        photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
                                }
                                
                                if ($related[1] && (settings.loop || $related[index + 1])) {
                                        photo.style.cursor = 'pointer';
                                        photo.onclick = function () {
                        publicMethod.next();
                    };
                                }
                                
                                if (isIE) {
                                        photo.style.msInterpolationMode = 'bicubic';
                                }
                                
                                setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
                                        prep(photo);
                                }, 1);
                        });
                        
                        setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
                                photo.src = href;
                        }, 1);
                } else if (href) {
                        $loadingBay.load(href, settings.data, function (data, status, xhr) {
                                prep(status === 'error' ? $tag(div, 'Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
                        });
                }
        };
        
        // Navigates to the next page/image in a set.
        publicMethod.next = function () {
                if (!active && $related[1] && (settings.loop || $related[index + 1])) {
                        index = getIndex(1);
                        publicMethod.load();
                }
        };
        
        publicMethod.prev = function () {
                if (!active && $related[1] && (settings.loop || index)) {
                        index = getIndex(-1);
                        publicMethod.load();
                }
        };

        // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
        publicMethod.close = function () {
                if (open && !closing) {
                        
                        closing = true;
                        
                        open = false;
                        
                        trigger(event_cleanup, settings.onCleanup);
                        
                        $window.unbind('.' + prefix + ' .' + event_ie6);
                        
                        $overlay.fadeTo(200, 0);
                        
                        $box.stop().fadeTo(300, 0, function () {
                 
                                $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
                                
                                trigger(event_purge);
                                
                                $loaded.remove();
                                
                                setTimeout(function () {
                                        closing = false;
                                        trigger(event_closed, settings.onClosed);
                                }, 1);
                        });
                }
        };

        // A method for fetching the current element ColorBox is referencing.
        // returns a jQuery object.
        publicMethod.element = function () {
                return $(element);
        };

        publicMethod.settings = defaults;
    
        // Bind the live event before DOM-ready for maximum performance in IE6 & 7.
        $('.' + boxElement, document).live('click', function (e) {
        // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
        // See: http://jacklmoore.com/notes/click-events/
        if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
            e.preventDefault();
            launch(this);
        }
    });

        // Setup ColorBox
        publicMethod.init();

}(jQuery, document, this));
ready
Fancybox
/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 *
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
 *
 * Version: 1.3.4 (11/11/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function($) {
        var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right,

                selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],

                ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,

                loadingTimer, loadingFrame = 1,

                titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('<div/>')[0], { prop: 0 }),

                isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,

                /*
                 * Private methods 
                 */

                _abort = function() {
                        loading.hide();

                        imgPreloader.onerror = imgPreloader.onload = null;

                        if (ajaxLoader) {
                                ajaxLoader.abort();
                        }

                        tmp.empty();
                },

                _error = function() {
                        if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) {
                                loading.hide();
                                busy = false;
                                return;
                        }

                        selectedOpts.titleShow = false;

                        selectedOpts.width = 'auto';
                        selectedOpts.height = 'auto';

                        tmp.html( '<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>' );

                        _process_inline();
                },

                _start = function() {
                        var obj = selectedArray[ selectedIndex ],
                                href, 
                                type, 
                                title,
                                str,
                                emb,
                                ret;

                        _abort();

                        selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));

                        ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts);

                        if (ret === false) {
                                busy = false;
                                return;
                        } else if (typeof ret == 'object') {
                                selectedOpts = $.extend(selectedOpts, ret);
                        }

                        title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || '';

                        if (obj.nodeName && !selectedOpts.orig) {
                                selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
                        }

                        if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) {
                                title = selectedOpts.orig.attr('alt');
                        }

                        href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null;

                        if ((/^(?:javascript)/i).test(href) || href == '#') {
                                href = null;
                        }

                        if (selectedOpts.type) {
                                type = selectedOpts.type;

                                if (!href) {
                                        href = selectedOpts.content;
                                }

                        } else if (selectedOpts.content) {
                                type = 'html';

                        } else if (href) {
                                if (href.match(imgRegExp)) {
                                        type = 'image';

                                } else if (href.match(swfRegExp)) {
                                        type = 'swf';

                                } else if ($(obj).hasClass("iframe")) {
                                        type = 'iframe';

                                } else if (href.indexOf("#") === 0) {
                                        type = 'inline';

                                } else {
                                        type = 'ajax';
                                }
                        }

                        if (!type) {
                                _error();
                                return;
                        }

                        if (type == 'inline') {
                                obj     = href.substr(href.indexOf("#"));
                                type = $(obj).length > 0 ? 'inline' : 'ajax';
                        }

                        selectedOpts.type = type;
                        selectedOpts.href = href;
                        selectedOpts.title = title;

                        if (selectedOpts.autoDimensions) {
                                if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') {
                                        selectedOpts.width = 'auto';
                                        selectedOpts.height = 'auto';
                                } else {
                                        selectedOpts.autoDimensions = false;    
                                }
                        }

                        if (selectedOpts.modal) {
                                selectedOpts.overlayShow = true;
                                selectedOpts.hideOnOverlayClick = false;
                                selectedOpts.hideOnContentClick = false;
                                selectedOpts.enableEscapeButton = false;
                                selectedOpts.showCloseButton = false;
                        }

                        selectedOpts.padding = parseInt(selectedOpts.padding, 10);
                        selectedOpts.margin = parseInt(selectedOpts.margin, 10);

                        tmp.css('padding', (selectedOpts.padding + selectedOpts.margin));

                        $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
                                $(this).replaceWith(content.children());                                
                        });

                        switch (type) {
                                case 'html' :
                                        tmp.html( selectedOpts.content );
                                        _process_inline();
                                break;

                                case 'inline' :
                                        if ( $(obj).parent().is('#fancybox-content') === true) {
                                                busy = false;
                                                return;
                                        }

                                        $('<div class="fancybox-inline-tmp" />')
                                                .hide()
                                                .insertBefore( $(obj) )
                                                .bind('fancybox-cleanup', function() {
                                                        $(this).replaceWith(content.children());
                                                }).bind('fancybox-cancel', function() {
                                                        $(this).replaceWith(tmp.children());
                                                });

                                        $(obj).appendTo(tmp);

                                        _process_inline();
                                break;

                                case 'image':
                                        busy = false;

                                        $.fancybox.showActivity();

                                        imgPreloader = new Image();

                                        imgPreloader.onerror = function() {
                                                _error();
                                        };

                                        imgPreloader.onload = function() {
                                                busy = true;

                                                imgPreloader.onerror = imgPreloader.onload = null;

                                                _process_image();
                                        };

                                        imgPreloader.src = href;
                                break;

                                case 'swf':
                                        selectedOpts.scrolling = 'no';

                                        str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
                                        emb = '';

                                        $.each(selectedOpts.swf, function(name, val) {
                                                str += '<param name="' + name + '" value="' + val + '"></param>';
                                                emb += ' ' + name + '="' + val + '"';
                                        });

                                        str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';

                                        tmp.html(str);

                                        _process_inline();
                                break;

                                case 'ajax':
                                        busy = false;

                                        $.fancybox.showActivity();

                                        selectedOpts.ajax.win = selectedOpts.ajax.success;

                                        ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, {
                                                url     : href,
                                                data : selectedOpts.ajax.data || {},
                                                error : function(XMLHttpRequest, textStatus, errorThrown) {
                                                        if ( XMLHttpRequest.status > 0 ) {
                                                                _error();
                                                        }
                                                },
                                                success : function(data, textStatus, XMLHttpRequest) {
                                                        var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader;
                                                        if (o.status == 200) {
                                                                if ( typeof selectedOpts.ajax.win == 'function' ) {
                                                                        ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest);

                                                                        if (ret === false) {
                                                                                loading.hide();
                                                                                return;
                                                                        } else if (typeof ret == 'string' || typeof ret == 'object') {
                                                                                data = ret;
                                                                        }
                                                                }

                                                                tmp.html( data );
                                                                _process_inline();
                                                        }
                                                }
                                        }));

                                break;

                                case 'iframe':
                                        _show();
                                break;
                        }
                },

                _process_inline = function() {
                        var
                                w = selectedOpts.width,
                                h = selectedOpts.height;

                        if (w.toString().indexOf('%') > -1) {
                                w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px';

                        } else {
                                w = w == 'auto' ? 'auto' : w + 'px';    
                        }

                        if (h.toString().indexOf('%') > -1) {
                                h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px';

                        } else {
                                h = h == 'auto' ? 'auto' : h + 'px';    
                        }

                        tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>');

                        selectedOpts.width = tmp.width();
                        selectedOpts.height = tmp.height();

                        _show();
                },

                _process_image = function() {
                        selectedOpts.width = imgPreloader.width;
                        selectedOpts.height = imgPreloader.height;

                        $("<img />").attr({
                                'id' : 'fancybox-img',
                                'src' : imgPreloader.src,
                                'alt' : selectedOpts.title
                        }).appendTo( tmp );

                        _show();
                },

                _show = function() {
                        var pos, equal;

                        loading.hide();

                        if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
                                $.event.trigger('fancybox-cancel');

                                busy = false;
                                return;
                        }

                        busy = true;

                        $(content.add( overlay )).unbind();

                        $(window).unbind("resize.fb scroll.fb");
                        $(document).unbind('keydown.fb');

                        if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') {
                                wrap.css('height', wrap.height());
                        }

                        currentArray = selectedArray;
                        currentIndex = selectedIndex;
                        currentOpts = selectedOpts;

                        if (currentOpts.overlayShow) {
                                overlay.css({
                                        'background-color' : currentOpts.overlayColor,
                                        'opacity' : currentOpts.overlayOpacity,
                                        'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto',
                                        'height' : $(document).height()
                                });

                                if (!overlay.is(':visible')) {
                                        if (isIE6) {
                                                $('select:not(#fancybox-tmp select)').filter(function() {
                                                        return this.style.visibility !== 'hidden';
                                                }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() {
                                                        this.style.visibility = 'inherit';
                                                });
                                        }

                                        overlay.show();
                                }
                        } else {
                                overlay.hide();
                        }

                        final_pos = _get_zoom_to();

                        _process_title();

                        if (wrap.is(":visible")) {
                                $( close.add( nav_left ).add( nav_right ) ).hide();

                                pos = wrap.position(),

                                start_pos = {
                                        top      : pos.top,
                                        left : pos.left,
                                        width : wrap.width(),
                                        height : wrap.height()
                                };

                                equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);

                                content.fadeTo(currentOpts.changeFade, 0.3, function() {
                                        var finish_resizing = function() {
                                                content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish);
                                        };

                                        $.event.trigger('fancybox-change');

                                        content
                                                .empty()
                                                .removeAttr('filter')
                                                .css({
                                                        'border-width' : currentOpts.padding,
                                                        'width' : final_pos.width - currentOpts.padding * 2,
                                                        'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
                                                });

                                        if (equal) {
                                                finish_resizing();

                                        } else {
                                                fx.prop = 0;

                                                $(fx).animate({prop: 1}, {
                                                         duration : currentOpts.changeSpeed,
                                                         easing : currentOpts.easingChange,
                                                         step : _draw,
                                                         complete : finish_resizing
                                                });
                                        }
                                });

                                return;
                        }

                        wrap.removeAttr("style");

                        content.css('border-width', currentOpts.padding);

                        if (currentOpts.transitionIn == 'elastic') {
                                start_pos = _get_zoom_from();

                                content.html( tmp.contents() );

                                wrap.show();

                                if (currentOpts.opacity) {
                                        final_pos.opacity = 0;
                                }

                                fx.prop = 0;

                                $(fx).animate({prop: 1}, {
                                         duration : currentOpts.speedIn,
                                         easing : currentOpts.easingIn,
                                         step : _draw,
                                         complete : _finish
                                });

                                return;
                        }

                        if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { 
                                title.show();   
                        }

                        content
                                .css({
                                        'width' : final_pos.width - currentOpts.padding * 2,
                                        'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
                                })
                                .html( tmp.contents() );

                        wrap
                                .css(final_pos)
                                .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
                },

                _format_title = function(title) {
                        if (title && title.length) {
                                if (currentOpts.titlePosition == 'float') {
                                        return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + title + '</td><td id="fancybox-title-float-right"></td></tr></table>';
                                }

                                return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title + '</div>';
                        }

                        return false;
                },

                _process_title = function() {
                        titleStr = currentOpts.title || '';
                        titleHeight = 0;

                        title
                                .empty()
                                .removeAttr('style')
                                .removeClass();

                        if (currentOpts.titleShow === false) {
                                title.hide();
                                return;
                        }

                        titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr);

                        if (!titleStr || titleStr === '') {
                                title.hide();
                                return;
                        }

                        title
                                .addClass('fancybox-title-' + currentOpts.titlePosition)
                                .html( titleStr )
                                .appendTo( 'body' )
                                .show();

                        switch (currentOpts.titlePosition) {
                                case 'inside':
                                        title
                                                .css({
                                                        'width' : final_pos.width - (currentOpts.padding * 2),
                                                        'marginLeft' : currentOpts.padding,
                                                        'marginRight' : currentOpts.padding
                                                });

                                        titleHeight = title.outerHeight(true);

                                        title.appendTo( outer );

                                        final_pos.height += titleHeight;
                                break;

                                case 'over':
                                        title
                                                .css({
                                                        'marginLeft' : currentOpts.padding,
                                                        'width' : final_pos.width - (currentOpts.padding * 2),
                                                        'bottom' : currentOpts.padding
                                                })
                                                .appendTo( outer );
                                break;

                                case 'float':
                                        title
                                                .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1)
                                                .appendTo( wrap );
                                break;

                                default:
                                        title
                                                .css({
                                                        'width' : final_pos.width - (currentOpts.padding * 2),
                                                        'paddingLeft' : currentOpts.padding,
                                                        'paddingRight' : currentOpts.padding
                                                })
                                                .appendTo( wrap );
                                break;
                        }

                        title.hide();
                },

                _set_navigation = function() {
                        if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) {
                                $(document).bind('keydown.fb', function(e) {
                                        if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
                                                e.preventDefault();
                                                $.fancybox.close();

                                        } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
                                                e.preventDefault();
                                                $.fancybox[ e.keyCode == 37 ? 'prev' : 'next']();
                                        }
                                });
                        }

                        if (!currentOpts.showNavArrows) { 
                                nav_left.hide();
                                nav_right.hide();
                                return;
                        }

                        if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
                                nav_left.show();
                        }

                        if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
                                nav_right.show();
                        }
                },

                _finish = function () {
                        if (!$.support.opacity) {
                                content.get(0).style.removeAttribute('filter');
                                wrap.get(0).style.removeAttribute('filter');
                        }

                        if (selectedOpts.autoDimensions) {
                                content.css('height', 'auto');
                        }

                        wrap.css('height', 'auto');

                        if (titleStr && titleStr.length) {
                                title.show();
                        }

                        if (currentOpts.showCloseButton) {
                                close.show();
                        }

                        _set_navigation();
        
                        if (currentOpts.hideOnContentClick)     {
                                content.bind('click', $.fancybox.close);
                        }

                        if (currentOpts.hideOnOverlayClick)     {
                                overlay.bind('click', $.fancybox.close);
                        }

                        $(window).bind("resize.fb", $.fancybox.resize);

                        if (currentOpts.centerOnScroll) {
                                $(window).bind("scroll.fb", $.fancybox.center);
                        }

                        if (currentOpts.type == 'iframe') {
                                $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="' + selectedOpts.scrolling + '" src="' + currentOpts.href + '"></iframe>').appendTo(content);
                        }

                        wrap.show();

                        busy = false;

                        $.fancybox.center();

                        currentOpts.onComplete(currentArray, currentIndex, currentOpts);

                        _preload_images();
                },

                _preload_images = function() {
                        var href, 
                                objNext;

                        if ((currentArray.length -1) > currentIndex) {
                                href = currentArray[ currentIndex + 1 ].href;

                                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                                        objNext = new Image();
                                        objNext.src = href;
                                }
                        }

                        if (currentIndex > 0) {
                                href = currentArray[ currentIndex - 1 ].href;

                                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                                        objNext = new Image();
                                        objNext.src = href;
                                }
                        }
                },

                _draw = function(pos) {
                        var dim = {
                                width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10),
                                height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10),

                                top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10),
                                left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10)
                        };

                        if (typeof final_pos.opacity !== 'undefined') {
                                dim.opacity = pos < 0.5 ? 0.5 : pos;
                        }

                        wrap.css(dim);

                        content.css({
                                'width' : dim.width - currentOpts.padding * 2,
                                'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2
                        });
                },

                _get_viewport = function() {
                        return [
                                $(window).width() - (currentOpts.margin * 2),
                                $(window).height() - (currentOpts.margin * 2),
                                $(document).scrollLeft() + currentOpts.margin,
                                $(document).scrollTop() + currentOpts.margin
                        ];
                },

                _get_zoom_to = function () {
                        var view = _get_viewport(),
                                to = {},
                                resize = currentOpts.autoScale,
                                double_padding = currentOpts.padding * 2,
                                ratio;

                        if (currentOpts.width.toString().indexOf('%') > -1) {
                                to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10);
                        } else {
                                to.width = currentOpts.width + double_padding;
                        }

                        if (currentOpts.height.toString().indexOf('%') > -1) {
                                to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10);
                        } else {
                                to.height = currentOpts.height + double_padding;
                        }

                        if (resize && (to.width > view[0] || to.height > view[1])) {
                                if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
                                        ratio = (currentOpts.width ) / (currentOpts.height );

                                        if ((to.width ) > view[0]) {
                                                to.width = view[0];
                                                to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10);
                                        }

                                        if ((to.height) > view[1]) {
                                                to.height = view[1];
                                                to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10);
                                        }

                                } else {
                                        to.width = Math.min(to.width, view[0]);
                                        to.height = Math.min(to.height, view[1]);
                                }
                        }

                        to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10);
                        to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10);

                        return to;
                },

                _get_obj_pos = function(obj) {
                        var pos = obj.offset();

                        pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0;
                        pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0;

                        pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0;
                        pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0;

                        pos.width = obj.width();
                        pos.height = obj.height();

                        return pos;
                },

                _get_zoom_from = function() {
                        var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
                                from = {},
                                pos,
                                view;

                        if (orig && orig.length) {
                                pos = _get_obj_pos(orig);

                                from = {
                                        width : pos.width + (currentOpts.padding * 2),
                                        height : pos.height + (currentOpts.padding * 2),
                                        top     : pos.top - currentOpts.padding - 20,
                                        left : pos.left - currentOpts.padding - 20
                                };

                        } else {
                                view = _get_viewport();

                                from = {
                                        width : currentOpts.padding * 2,
                                        height : currentOpts.padding * 2,
                                        top     : parseInt(view[3] + view[1] * 0.5, 10),
                                        left : parseInt(view[2] + view[0] * 0.5, 10)
                                };
                        }

                        return from;
                },

                _animate_loading = function() {
                        if (!loading.is(':visible')){
                                clearInterval(loadingTimer);
                                return;
                        }

                        $('div', loading).css('top', (loadingFrame * -40) + 'px');

                        loadingFrame = (loadingFrame + 1) % 12;
                };

        /*
         * Public methods 
         */

        $.fn.fancybox = function(options) {
                if (!$(this).length) {
                        return this;
                }

                $(this)
                        .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
                        .unbind('click.fb')
                        .bind('click.fb', function(e) {
                                e.preventDefault();

                                if (busy) {
                                        return;
                                }

                                busy = true;

                                $(this).blur();

                                selectedArray = [];
                                selectedIndex = 0;

                                var rel = $(this).attr('rel') || '';

                                if (!rel || rel == '' || rel === 'nofollow') {
                                        selectedArray.push(this);

                                } else {
                                        selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
                                        selectedIndex = selectedArray.index( this );
                                }

                                _start();

                                return;
                        });

                return this;
        };

        $.fancybox = function(obj) {
                var opts;

                if (busy) {
                        return;
                }

                busy = true;
                opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};

                selectedArray = [];
                selectedIndex = parseInt(opts.index, 10) || 0;

                if ($.isArray(obj)) {
                        for (var i = 0, j = obj.length; i < j; i++) {
                                if (typeof obj[i] == 'object') {
                                        $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
                                } else {
                                        obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
                                }
                        }

                        selectedArray = jQuery.merge(selectedArray, obj);

                } else {
                        if (typeof obj == 'object') {
                                $(obj).data('fancybox', $.extend({}, opts, obj));
                        } else {
                                obj = $({}).data('fancybox', $.extend({content : obj}, opts));
                        }

                        selectedArray.push(obj);
                }

                if (selectedIndex > selectedArray.length || selectedIndex < 0) {
                        selectedIndex = 0;
                }

                _start();
        };

        $.fancybox.showActivity = function() {
                clearInterval(loadingTimer);

                loading.show();
                loadingTimer = setInterval(_animate_loading, 66);
        };

        $.fancybox.hideActivity = function() {
                loading.hide();
        };

        $.fancybox.next = function() {
                return $.fancybox.pos( currentIndex + 1);
        };

        $.fancybox.prev = function() {
                return $.fancybox.pos( currentIndex - 1);
        };

        $.fancybox.pos = function(pos) {
                if (busy) {
                        return;
                }

                pos = parseInt(pos);

                selectedArray = currentArray;

                if (pos > -1 && pos < currentArray.length) {
                        selectedIndex = pos;
                        _start();

                } else if (currentOpts.cyclic && currentArray.length > 1) {
                        selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1;
                        _start();
                }

                return;
        };

        $.fancybox.cancel = function() {
                if (busy) {
                        return;
                }

                busy = true;

                $.event.trigger('fancybox-cancel');

                _abort();

                selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);

                busy = false;
        };

        // Note: within an iframe use - parent.$.fancybox.close();
        $.fancybox.close = function() {
                if (busy || wrap.is(':hidden')) {
                        return;
                }

                busy = true;

                if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
                        busy = false;
                        return;
                }

                _abort();

                $(close.add( nav_left ).add( nav_right )).hide();

                $(content.add( overlay )).unbind();

                $(window).unbind("resize.fb scroll.fb");
                $(document).unbind('keydown.fb');

                content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank');

                if (currentOpts.titlePosition !== 'inside') {
                        title.empty();
                }

                wrap.stop();

                function _cleanup() {
                        overlay.fadeOut('fast');

                        title.empty().hide();
                        wrap.hide();

                        $.event.trigger('fancybox-cleanup');

                        content.empty();

                        currentOpts.onClosed(currentArray, currentIndex, currentOpts);

                        currentArray = selectedOpts     = [];
                        currentIndex = selectedIndex = 0;
                        currentOpts = selectedOpts      = {};

                        busy = false;
                }

                if (currentOpts.transitionOut == 'elastic') {
                        start_pos = _get_zoom_from();

                        var pos = wrap.position();

                        final_pos = {
                                top      : pos.top ,
                                left : pos.left,
                                width : wrap.width(),
                                height : wrap.height()
                        };

                        if (currentOpts.opacity) {
                                final_pos.opacity = 1;
                        }

                        title.empty().hide();

                        fx.prop = 1;

                        $(fx).animate({ prop: 0 }, {
                                 duration : currentOpts.speedOut,
                                 easing : currentOpts.easingOut,
                                 step : _draw,
                                 complete : _cleanup
                        });

                } else {
                        wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
                }
        };

        $.fancybox.resize = function() {
                if (overlay.is(':visible')) {
                        overlay.css('height', $(document).height());
                }

                $.fancybox.center(true);
        };

        $.fancybox.center = function() {
                var view, align;

                if (busy) {
                        return; 
                }

                align = arguments[0] === true ? 1 : 0;
                view = _get_viewport();

                if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) {
                        return; 
                }

                wrap
                        .stop()
                        .animate({
                                'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)),
                                'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding))
                        }, typeof arguments[0] == 'number' ? arguments[0] : 200);
        };

        $.fancybox.init = function() {
                if ($("#fancybox-wrap").length) {
                        return;
                }

                $('body').append(
                        tmp     = $('<div id="fancybox-tmp"></div>'),
                        loading = $('<div id="fancybox-loading"><div></div></div>'),
                        overlay = $('<div id="fancybox-overlay"></div>'),
                        wrap = $('<div id="fancybox-wrap"></div>')
                );

                outer = $('<div id="fancybox-outer"></div>')
                        .append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>')
                        .appendTo( wrap );

                outer.append(
                        content = $('<div id="fancybox-content"></div>'),
                        close = $('<a id="fancybox-close"></a>'),
                        title = $('<div id="fancybox-title"></div>'),

                        nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
                        nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
                );

                close.click($.fancybox.close);
                loading.click($.fancybox.cancel);

                nav_left.click(function(e) {
                        e.preventDefault();
                        $.fancybox.prev();
                });

                nav_right.click(function(e) {
                        e.preventDefault();
                        $.fancybox.next();
                });

                if ($.fn.mousewheel) {
                        wrap.bind('mousewheel.fb', function(e, delta) {
                                if (busy) {
                                        e.preventDefault();

                                } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
                                        e.preventDefault();
                                        $.fancybox[ delta > 0 ? 'prev' : 'next']();
                                }
                        });
                }

                if (!$.support.opacity) {
                        wrap.addClass('fancybox-ie');
                }

                if (isIE6) {
                        loading.addClass('fancybox-ie6');
                        wrap.addClass('fancybox-ie6');

                        $('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer);
                }
        };

        $.fn.fancybox.defaults = {
                padding : 10,
                margin : 40,
                opacity : false,
                modal : false,
                cyclic : false,
                scrolling : 'auto',     // 'auto', 'yes' or 'no'

                width : 560,
                height : 340,

                autoScale : true,
                autoDimensions : true,
                centerOnScroll : false,

                ajax : {},
                swf : { wmode: 'transparent' },

                hideOnOverlayClick : true,
                hideOnContentClick : false,

                overlayShow : true,
                overlayOpacity : 0.7,
                overlayColor : '#777',

                titleShow : true,
                titlePosition : 'float', // 'float', 'outside', 'inside' or 'over'
                titleFormat : null,
                titleFromAlt : false,

                transitionIn : 'fade', // 'elastic', 'fade' or 'none'
                transitionOut : 'fade', // 'elastic', 'fade' or 'none'

                speedIn : 300,
                speedOut : 300,

                changeSpeed : 300,
                changeFade : 'fast',

                easingIn : 'swing',
                easingOut : 'swing',

                showCloseButton  : true,
                showNavArrows : true,
                enableEscapeButton : true,
                enableKeyboardNav : true,

                onStart : function(){},
                onCancel : function(){},
                onComplete : function(){},
                onCleanup : function(){},
                onClosed : function(){},
                onError : function(){}
        };

        $(document).ready(function() {
                $.fancybox.init();
        });

})(jQuery);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.