~ubuntu-tour/+junk/new-lang-system

« back to all changes in this revision

Viewing changes to old/tours/html/jquery/jquery.fancybox-1.3.1.js

  • Committer: Anthony Stewart
  • Date: 2011-04-13 21:04:26 UTC
  • Revision ID: madnessred@gmail.com-20110413210426-x336oab2lh2h2b35
starting with new tour.py system

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FancyBox - jQuery Plugin
 
3
 * Simple and fancy lightbox alternative
 
4
 *
 
5
 * Examples and documentation at: http://fancybox.net
 
6
 * 
 
7
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 
8
 *
 
9
 * Version: 1.3.1 (05/03/2010)
 
10
 * Requires: jQuery v1.3+
 
11
 *
 
12
 * Dual licensed under the MIT and GPL licenses:
 
13
 *   http://www.opensource.org/licenses/mit-license.php
 
14
 *   http://www.gnu.org/licenses/gpl.html
 
15
 */
 
16
 
 
17
(function($) {
 
18
 
 
19
        var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,
 
20
 
 
21
                selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],
 
22
 
 
23
                ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
 
24
 
 
25
                loadingTimer, loadingFrame = 1,
 
26
 
 
27
                start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0, 
 
28
 
 
29
                isIE6 = !$.support.opacity && !window.XMLHttpRequest,
 
30
 
 
31
                /*
 
32
                 * Private methods 
 
33
                 */
 
34
 
 
35
                fancybox_abort = function() {
 
36
                        loading.hide();
 
37
 
 
38
                        imgPreloader.onerror = imgPreloader.onload = null;
 
39
 
 
40
                        if (ajaxLoader) {
 
41
                                ajaxLoader.abort();
 
42
                        }
 
43
 
 
44
                        tmp.empty();
 
45
                },
 
46
 
 
47
                fancybox_error = function() {
 
48
                        $.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
 
49
                                'scrolling'             : 'no',
 
50
                                'padding'               : 20,
 
51
                                'transitionIn'  : 'none',
 
52
                                'transitionOut' : 'none'
 
53
                        });
 
54
                },
 
55
 
 
56
                fancybox_get_viewport = function() {
 
57
                        return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
 
58
                },
 
59
 
 
60
                fancybox_get_zoom_to = function () {
 
61
                        var view        = fancybox_get_viewport(),
 
62
                                to              = {},
 
63
 
 
64
                                margin = currentOpts.margin,
 
65
                                resize = currentOpts.autoScale,
 
66
 
 
67
                                horizontal_space        = (shadow + margin) * 2,
 
68
                                vertical_space          = (shadow + margin) * 2,
 
69
                                double_padding          = (currentOpts.padding * 2),
 
70
                                
 
71
                                ratio;
 
72
 
 
73
                        if (currentOpts.width.toString().indexOf('%') > -1) {
 
74
                                to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
 
75
                                resize = false;
 
76
 
 
77
                        } else {
 
78
                                to.width = currentOpts.width + double_padding;
 
79
                        }
 
80
 
 
81
                        if (currentOpts.height.toString().indexOf('%') > -1) {
 
82
                                to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
 
83
                                resize = false;
 
84
 
 
85
                        } else {
 
86
                                to.height = currentOpts.height + double_padding;
 
87
                        }
 
88
 
 
89
                        if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
 
90
                                if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
 
91
                                        horizontal_space        += double_padding;
 
92
                                        vertical_space          += double_padding;
 
93
 
 
94
                                        ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);
 
95
 
 
96
                                        to.width        = Math.round(ratio * (to.width  - double_padding)) + double_padding;
 
97
                                        to.height       = Math.round(ratio * (to.height - double_padding)) + double_padding;
 
98
 
 
99
                                } else {
 
100
                                        to.width        = Math.min(to.width,    (view[0] - horizontal_space));
 
101
                                        to.height       = Math.min(to.height,   (view[1] - vertical_space));
 
102
                                }
 
103
                        }
 
104
 
 
105
                        to.top  = view[3] + ((view[1] - (to.height      + (shadow * 2 ))) * 0.5);
 
106
                        to.left = view[2] + ((view[0] - (to.width       + (shadow * 2 ))) * 0.5);
 
107
 
 
108
                        if (currentOpts.autoScale === false) {
 
109
                                to.top  = Math.max(view[3] + margin, to.top);
 
110
                                to.left = Math.max(view[2] + margin, to.left);
 
111
                        }
 
112
 
 
113
                        return to;
 
114
                },
 
115
 
 
116
                fancybox_format_title = function(title) {
 
117
                        if (title && title.length) {
 
118
                                switch (currentOpts.titlePosition) {
 
119
                                        case 'inside':
 
120
                                                return title;
 
121
                                        case 'over':
 
122
                                                return '<span id="fancybox-title-over">' + title + '</span>';
 
123
                                        default:
 
124
                                                return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
 
125
                                }
 
126
                        }
 
127
 
 
128
                        return false;
 
129
                },
 
130
 
 
131
                fancybox_process_title = function() {
 
132
                        var title       = currentOpts.title,
 
133
                                width   = final_pos.width - (currentOpts.padding * 2),
 
134
                                titlec  = 'fancybox-title-' + currentOpts.titlePosition;
 
135
                                
 
136
                        $('#fancybox-title').remove();
 
137
 
 
138
                        titleh = 0;
 
139
 
 
140
                        if (currentOpts.titleShow === false) {
 
141
                                return;
 
142
                        }
 
143
 
 
144
                        title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);
 
145
 
 
146
                        if (!title || title === '') {
 
147
                                return;
 
148
                        }
 
149
 
 
150
                        $('<div id="fancybox-title" class="' + titlec + '" />').css({
 
151
                                'width'                 : width,
 
152
                                'paddingLeft'   : currentOpts.padding,
 
153
                                'paddingRight'  : currentOpts.padding
 
154
                        }).html(title).appendTo('body');
 
155
 
 
156
                        switch (currentOpts.titlePosition) {
 
157
                                case 'inside':
 
158
                                        titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
 
159
                                        final_pos.height += titleh;
 
160
                                break;
 
161
 
 
162
                                case 'over':
 
163
                                        $('#fancybox-title').css('bottom', currentOpts.padding);
 
164
                                break;
 
165
 
 
166
                                default:
 
167
                                        $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
 
168
                                break;
 
169
                        }
 
170
 
 
171
                        $('#fancybox-title').appendTo( outer ).hide();
 
172
                },
 
173
 
 
174
                fancybox_preload_images = function() {
 
175
                        var href, 
 
176
                                objNext;
 
177
                                
 
178
                        if ((currentArray.length -1) > currentIndex) {
 
179
                                href = currentArray[ currentIndex + 1 ].href;
 
180
 
 
181
                                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
 
182
                                        objNext = new Image();
 
183
                                        objNext.src = href;
 
184
                                }
 
185
                        }
 
186
 
 
187
                        if (currentIndex > 0) {
 
188
                                href = currentArray[ currentIndex - 1 ].href;
 
189
 
 
190
                                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
 
191
                                        objNext = new Image();
 
192
                                        objNext.src = href;
 
193
                                }
 
194
                        }
 
195
                },
 
196
 
 
197
                _finish = function () {
 
198
                        inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));
 
199
 
 
200
                        if (!$.support.opacity) {
 
201
                                inner.get(0).style.removeAttribute('filter');
 
202
                                wrap.get(0).style.removeAttribute('filter');
 
203
                        }
 
204
 
 
205
                        $('#fancybox-title').show();
 
206
 
 
207
                        if (currentOpts.hideOnContentClick)     {
 
208
                                inner.one('click', $.fancybox.close);
 
209
                        }
 
210
                        if (currentOpts.hideOnOverlayClick)     {
 
211
                                overlay.one('click', $.fancybox.close);
 
212
                        }
 
213
 
 
214
                        if (currentOpts.showCloseButton) {
 
215
                                close.show();
 
216
                        }
 
217
 
 
218
 
 
219
                        $(window).bind("resize.fb", $.fancybox.center);
 
220
 
 
221
                        if (currentOpts.centerOnScroll) {
 
222
                                $(window).bind("scroll.fb", $.fancybox.center);
 
223
                        } else {
 
224
                                $(window).unbind("scroll.fb");
 
225
                        }
 
226
 
 
227
                        if ($.isFunction(currentOpts.onComplete)) {
 
228
                                currentOpts.onComplete(currentArray, currentIndex, currentOpts);
 
229
                        }
 
230
 
 
231
                        busy = false;
 
232
 
 
233
                        fancybox_preload_images();
 
234
                },
 
235
 
 
236
                fancybox_draw = function(pos) {
 
237
                        var width       = Math.round(start_pos.width    + (final_pos.width      - start_pos.width)      * pos),
 
238
                                height  = Math.round(start_pos.height   + (final_pos.height     - start_pos.height)     * pos),
 
239
 
 
240
                                top             = Math.round(start_pos.top      + (final_pos.top        - start_pos.top)        * pos),
 
241
                                left    = Math.round(start_pos.left     + (final_pos.left       - start_pos.left)       * pos);
 
242
 
 
243
                        wrap.css({
 
244
                                'width'         : width         + 'px',
 
245
                                'height'        : height        + 'px',
 
246
                                'top'           : top           + 'px',
 
247
                                'left'          : left          + 'px'
 
248
                        });
 
249
 
 
250
                        width   = Math.max(width - currentOpts.padding * 2, 0);
 
251
                        height  = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);
 
252
 
 
253
                        inner.css({
 
254
                                'width'         : width         + 'px',
 
255
                                'height'        : height        + 'px'
 
256
                        });
 
257
 
 
258
                        if (typeof final_pos.opacity !== 'undefined') {
 
259
                                wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
 
260
                        }
 
261
                },
 
262
 
 
263
                fancybox_get_obj_pos = function(obj) {
 
264
                        var pos         = obj.offset();
 
265
 
 
266
                        pos.top         += parseFloat( obj.css('paddingTop') )  || 0;
 
267
                        pos.left        += parseFloat( obj.css('paddingLeft') ) || 0;
 
268
 
 
269
                        pos.top         += parseFloat( obj.css('border-top-width') )    || 0;
 
270
                        pos.left        += parseFloat( obj.css('border-left-width') )   || 0;
 
271
 
 
272
                        pos.width       = obj.width();
 
273
                        pos.height      = obj.height();
 
274
 
 
275
                        return pos;
 
276
                },
 
277
 
 
278
                fancybox_get_zoom_from = function() {
 
279
                        var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
 
280
                                from = {},
 
281
                                pos,
 
282
                                view;
 
283
 
 
284
                        if (orig && orig.length) {
 
285
                                pos = fancybox_get_obj_pos(orig);
 
286
 
 
287
                                from = {
 
288
                                        width   : (pos.width    + (currentOpts.padding * 2)),
 
289
                                        height  : (pos.height   + (currentOpts.padding * 2)),
 
290
                                        top             : (pos.top              - currentOpts.padding - shadow),
 
291
                                        left    : (pos.left             - currentOpts.padding - shadow)
 
292
                                };
 
293
                                
 
294
                        } else {
 
295
                                view = fancybox_get_viewport();
 
296
 
 
297
                                from = {
 
298
                                        width   : 1,
 
299
                                        height  : 1,
 
300
                                        top             : view[3] + view[1] * 0.5,
 
301
                                        left    : view[2] + view[0] * 0.5
 
302
                                };
 
303
                        }
 
304
 
 
305
                        return from;
 
306
                },
 
307
 
 
308
                fancybox_show = function() {
 
309
                        loading.hide();
 
310
 
 
311
                        if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
 
312
                                if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
 
313
                                        $.event.trigger('fancybox-cancel');
 
314
 
 
315
                                        busy = false;
 
316
                                        return;
 
317
                                }
 
318
                        }
 
319
 
 
320
                        currentArray    = selectedArray;
 
321
                        currentIndex    = selectedIndex;
 
322
                        currentOpts             = selectedOpts;
 
323
 
 
324
                        inner.get(0).scrollTop  = 0;
 
325
                        inner.get(0).scrollLeft = 0;
 
326
 
 
327
                        if (currentOpts.overlayShow) {
 
328
                                if (isIE6) {
 
329
                                        $('select:not(#fancybox-tmp select)').filter(function() {
 
330
                                                return this.style.visibility !== 'hidden';
 
331
                                        }).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {
 
332
                                                this.style.visibility = 'inherit';
 
333
                                        });
 
334
                                }
 
335
 
 
336
                                overlay.css({
 
337
                                        'background-color'      : currentOpts.overlayColor,
 
338
                                        'opacity'                       : currentOpts.overlayOpacity
 
339
                                }).unbind().show();
 
340
                        }
 
341
 
 
342
                        final_pos = fancybox_get_zoom_to();
 
343
 
 
344
                        fancybox_process_title();
 
345
 
 
346
                        if (wrap.is(":visible")) {
 
347
                                $( close.add( nav_left ).add( nav_right ) ).hide();
 
348
 
 
349
                                var pos = wrap.position(),
 
350
                                        equal;
 
351
 
 
352
                                start_pos = {
 
353
                                        top             :       pos.top ,
 
354
                                        left    :       pos.left,
 
355
                                        width   :       wrap.width(),
 
356
                                        height  :       wrap.height()
 
357
                                };
 
358
 
 
359
                                equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);
 
360
 
 
361
                                inner.fadeOut(currentOpts.changeFade, function() {
 
362
                                        var finish_resizing = function() {
 
363
                                                inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
 
364
                                        };
 
365
                                        
 
366
                                        $.event.trigger('fancybox-change');
 
367
 
 
368
                                        inner.empty().css('overflow', 'hidden');
 
369
 
 
370
                                        if (equal) {
 
371
                                                inner.css({
 
372
                                                        top                     : currentOpts.padding,
 
373
                                                        left            : currentOpts.padding,
 
374
                                                        width           : Math.max(final_pos.width      - (currentOpts.padding * 2), 1),
 
375
                                                        height          : Math.max(final_pos.height     - (currentOpts.padding * 2) - titleh, 1)
 
376
                                                });
 
377
                                                
 
378
                                                finish_resizing();
 
379
 
 
380
                                        } else {
 
381
                                                inner.css({
 
382
                                                        top                     : currentOpts.padding,
 
383
                                                        left            : currentOpts.padding,
 
384
                                                        width           : Math.max(start_pos.width      - (currentOpts.padding * 2), 1),
 
385
                                                        height          : Math.max(start_pos.height     - (currentOpts.padding * 2), 1)
 
386
                                                });
 
387
                                                
 
388
                                                fx.prop = 0;
 
389
 
 
390
                                                $(fx).animate({ prop: 1 }, {
 
391
                                                         duration       : currentOpts.changeSpeed,
 
392
                                                         easing         : currentOpts.easingChange,
 
393
                                                         step           : fancybox_draw,
 
394
                                                         complete       : finish_resizing
 
395
                                                });
 
396
                                        }
 
397
                                });
 
398
 
 
399
                                return;
 
400
                        }
 
401
 
 
402
                        wrap.css('opacity', 1);
 
403
 
 
404
                        if (currentOpts.transitionIn == 'elastic') {
 
405
                                start_pos = fancybox_get_zoom_from();
 
406
 
 
407
                                inner.css({
 
408
                                                top                     : currentOpts.padding,
 
409
                                                left            : currentOpts.padding,
 
410
                                                width           : Math.max(start_pos.width      - (currentOpts.padding * 2), 1),
 
411
                                                height          : Math.max(start_pos.height     - (currentOpts.padding * 2), 1)
 
412
                                        })
 
413
                                        .html( tmp.contents() );
 
414
 
 
415
                                wrap.css(start_pos).show();
 
416
 
 
417
                                if (currentOpts.opacity) {
 
418
                                        final_pos.opacity = 0;
 
419
                                }
 
420
 
 
421
                                fx.prop = 0;
 
422
 
 
423
                                $(fx).animate({ prop: 1 }, {
 
424
                                         duration       : currentOpts.speedIn,
 
425
                                         easing         : currentOpts.easingIn,
 
426
                                         step           : fancybox_draw,
 
427
                                         complete       : _finish
 
428
                                });
 
429
 
 
430
                        } else {
 
431
                                inner.css({
 
432
                                                top                     : currentOpts.padding,
 
433
                                                left            : currentOpts.padding,
 
434
                                                width           : Math.max(final_pos.width      - (currentOpts.padding * 2), 1),
 
435
                                                height          : Math.max(final_pos.height     - (currentOpts.padding * 2) - titleh, 1)
 
436
                                        })
 
437
                                        .html( tmp.contents() );
 
438
 
 
439
                                wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
 
440
                        }
 
441
                },
 
442
 
 
443
                fancybox_process_inline = function() {
 
444
                        tmp.width(      selectedOpts.width );
 
445
                        tmp.height(     selectedOpts.height );
 
446
 
 
447
                        if (selectedOpts.width  == 'auto') {
 
448
                                selectedOpts.width = tmp.width();
 
449
                        }
 
450
                        if (selectedOpts.height == 'auto') {
 
451
                                selectedOpts.height     = tmp.height();
 
452
                        }
 
453
 
 
454
                        fancybox_show();
 
455
                },
 
456
                
 
457
                fancybox_process_image = function() {
 
458
                        busy = true;
 
459
 
 
460
                        selectedOpts.width      = imgPreloader.width;
 
461
                        selectedOpts.height     = imgPreloader.height;
 
462
 
 
463
                        $("<img />").attr({
 
464
                                'id'    : 'fancybox-img',
 
465
                                'src'   : imgPreloader.src,
 
466
                                'alt'   : selectedOpts.title
 
467
                        }).appendTo( tmp );
 
468
 
 
469
                        fancybox_show();
 
470
                },
 
471
 
 
472
                fancybox_start = function() {
 
473
                        fancybox_abort();
 
474
 
 
475
                        var obj = selectedArray[ selectedIndex ],
 
476
                                href, 
 
477
                                type, 
 
478
                                title,
 
479
                                str,
 
480
                                emb,
 
481
                                selector,
 
482
                                data;
 
483
 
 
484
                        selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
 
485
                        title = obj.title || $(obj).title || selectedOpts.title || '';
 
486
                        
 
487
                        if (obj.nodeName && !selectedOpts.orig) {
 
488
                                selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
 
489
                        }
 
490
 
 
491
                        if (title === '' && selectedOpts.orig) {
 
492
                                title = selectedOpts.orig.attr('alt');
 
493
                        }
 
494
 
 
495
                        if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
 
496
                                href = selectedOpts.href || null;
 
497
                        } else {
 
498
                                href = selectedOpts.href || obj.href || null;
 
499
                        }
 
500
 
 
501
                        if (selectedOpts.type) {
 
502
                                type = selectedOpts.type;
 
503
 
 
504
                                if (!href) {
 
505
                                        href = selectedOpts.content;
 
506
                                }
 
507
                                
 
508
                        } else if (selectedOpts.content) {
 
509
                                type    = 'html';
 
510
 
 
511
                        } else if (href) {
 
512
                                if (href.match(imgRegExp)) {
 
513
                                        type = 'image';
 
514
 
 
515
                                } else if (href.match(swfRegExp)) {
 
516
                                        type = 'swf';
 
517
 
 
518
                                } else if ($(obj).hasClass("iframe")) {
 
519
                                        type = 'iframe';
 
520
 
 
521
                                } else if (href.match(/#/)) {
 
522
                                        obj = href.substr(href.indexOf("#"));
 
523
 
 
524
                                        type = $(obj).length > 0 ? 'inline' : 'ajax';
 
525
                                } else {
 
526
                                        type = 'ajax';
 
527
                                }
 
528
                        } else {
 
529
                                type = 'inline';
 
530
                        }
 
531
 
 
532
                        selectedOpts.type       = type;
 
533
                        selectedOpts.href       = href;
 
534
                        selectedOpts.title      = title;
 
535
 
 
536
                        if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
 
537
                                selectedOpts.width              = 'auto';
 
538
                                selectedOpts.height             = 'auto';
 
539
                        }
 
540
 
 
541
                        if (selectedOpts.modal) {
 
542
                                selectedOpts.overlayShow                = true;
 
543
                                selectedOpts.hideOnOverlayClick = false;
 
544
                                selectedOpts.hideOnContentClick = false;
 
545
                                selectedOpts.enableEscapeButton = false;
 
546
                                selectedOpts.showCloseButton    = false;
 
547
                        }
 
548
 
 
549
                        if ($.isFunction(selectedOpts.onStart)) {
 
550
                                if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
 
551
                                        busy = false;
 
552
                                        return;
 
553
                                }
 
554
                        }
 
555
 
 
556
                        tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));
 
557
 
 
558
                        $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
 
559
                                $(this).replaceWith(inner.children());
 
560
                        });
 
561
 
 
562
                        switch (type) {
 
563
                                case 'html' :
 
564
                                        tmp.html( selectedOpts.content );
 
565
                                        fancybox_process_inline();
 
566
                                break;
 
567
 
 
568
                                case 'inline' :
 
569
                                        $('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
 
570
                                                $(this).replaceWith(inner.children());
 
571
                                        }).bind('fancybox-cancel', function() {
 
572
                                                $(this).replaceWith(tmp.children());
 
573
                                        });
 
574
 
 
575
                                        $(obj).appendTo(tmp);
 
576
 
 
577
                                        fancybox_process_inline();
 
578
                                break;
 
579
 
 
580
                                case 'image':
 
581
                                        busy = false;
 
582
 
 
583
                                        $.fancybox.showActivity();
 
584
 
 
585
                                        imgPreloader = new Image();
 
586
 
 
587
                                        imgPreloader.onerror = function() {
 
588
                                                fancybox_error();
 
589
                                        };
 
590
 
 
591
                                        imgPreloader.onload = function() {
 
592
                                                imgPreloader.onerror = null;
 
593
                                                imgPreloader.onload = null;
 
594
                                                fancybox_process_image();
 
595
                                        };
 
596
 
 
597
                                        imgPreloader.src = href;
 
598
                
 
599
                                break;
 
600
 
 
601
                                case 'swf':
 
602
                                        str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
 
603
                                        emb = '';
 
604
                                        
 
605
                                        $.each(selectedOpts.swf, function(name, val) {
 
606
                                                str += '<param name="' + name + '" value="' + val + '"></param>';
 
607
                                                emb += ' ' + name + '="' + val + '"';
 
608
                                        });
 
609
 
 
610
                                        str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';
 
611
 
 
612
                                        tmp.html(str);
 
613
 
 
614
                                        fancybox_process_inline();
 
615
                                break;
 
616
 
 
617
                                case 'ajax':
 
618
                                        selector        = href.split('#', 2);
 
619
                                        data            = selectedOpts.ajax.data || {};
 
620
 
 
621
                                        if (selector.length > 1) {
 
622
                                                href = selector[0];
 
623
 
 
624
                                                if (typeof data == "string") {
 
625
                                                        data += '&selector=' + selector[1];
 
626
                                                } else {
 
627
                                                        data.selector = selector[1];
 
628
                                                }
 
629
                                        }
 
630
 
 
631
                                        busy = false;
 
632
                                        $.fancybox.showActivity();
 
633
 
 
634
                                        ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
 
635
                                                url             : href,
 
636
                                                data    : data,
 
637
                                                error   : fancybox_error,
 
638
                                                success : function(data, textStatus, XMLHttpRequest) {
 
639
                                                        if (ajaxLoader.status == 200) {
 
640
                                                                tmp.html( data );
 
641
                                                                fancybox_process_inline();
 
642
                                                        }
 
643
                                                }
 
644
                                        }));
 
645
 
 
646
                                break;
 
647
 
 
648
                                case 'iframe' :
 
649
                                        $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
 
650
                                        fancybox_show();
 
651
                                break;
 
652
                        }
 
653
                },
 
654
 
 
655
                fancybox_animate_loading = function() {
 
656
                        if (!loading.is(':visible')){
 
657
                                clearInterval(loadingTimer);
 
658
                                return;
 
659
                        }
 
660
 
 
661
                        $('div', loading).css('top', (loadingFrame * -40) + 'px');
 
662
 
 
663
                        loadingFrame = (loadingFrame + 1) % 12;
 
664
                },
 
665
 
 
666
                fancybox_init = function() {
 
667
                        if ($("#fancybox-wrap").length) {
 
668
                                return;
 
669
                        }
 
670
 
 
671
                        $('body').append(
 
672
                                tmp                     = $('<div id="fancybox-tmp"></div>'),
 
673
                                loading         = $('<div id="fancybox-loading"><div></div></div>'),
 
674
                                overlay         = $('<div id="fancybox-overlay"></div>'),
 
675
                                wrap            = $('<div id="fancybox-wrap"></div>')
 
676
                        );
 
677
 
 
678
                        if (!$.support.opacity) {
 
679
                                wrap.addClass('fancybox-ie');
 
680
                                loading.addClass('fancybox-ie');
 
681
                        }
 
682
 
 
683
                        outer = $('<div id="fancybox-outer"></div>')
 
684
                                .append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')
 
685
                                .appendTo( wrap );
 
686
 
 
687
                        outer.append(
 
688
                                inner           = $('<div id="fancybox-inner"></div>'),
 
689
                                close           = $('<a id="fancybox-close"></a>'),
 
690
 
 
691
                                nav_left        = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
 
692
                                nav_right       = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
 
693
                        );
 
694
 
 
695
                        close.click($.fancybox.close);
 
696
                        loading.click($.fancybox.cancel);
 
697
 
 
698
                        nav_left.click(function(e) {
 
699
                                e.preventDefault();
 
700
                                $.fancybox.prev();
 
701
                        });
 
702
 
 
703
                        nav_right.click(function(e) {
 
704
                                e.preventDefault();
 
705
                                $.fancybox.next();
 
706
                        });
 
707
 
 
708
                        if (isIE6) {
 
709
                                overlay.get(0).style.setExpression('height',    "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
 
710
                                loading.get(0).style.setExpression('top',               "(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");
 
711
 
 
712
                                outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
 
713
                        }
 
714
                };
 
715
 
 
716
        /*
 
717
         * Public methods 
 
718
         */
 
719
 
 
720
        $.fn.fancybox = function(options) {
 
721
                $(this)
 
722
                        .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
 
723
                        .unbind('click.fb').bind('click.fb', function(e) {
 
724
                                e.preventDefault();
 
725
 
 
726
                                if (busy) {
 
727
                                        return;
 
728
                                }
 
729
 
 
730
                                busy = true;
 
731
 
 
732
                                $(this).blur();
 
733
 
 
734
                                selectedArray   = [];
 
735
                                selectedIndex   = 0;
 
736
 
 
737
                                var rel = $(this).attr('rel') || '';
 
738
 
 
739
                                if (!rel || rel == '' || rel === 'nofollow') {
 
740
                                        selectedArray.push(this);
 
741
 
 
742
                                } else {
 
743
                                        selectedArray   = $("a[rel=" + rel + "], area[rel=" + rel + "]");
 
744
                                        selectedIndex   = selectedArray.index( this );
 
745
                                }
 
746
 
 
747
                                fancybox_start();
 
748
 
 
749
                                return false;
 
750
                        });
 
751
 
 
752
                return this;
 
753
        };
 
754
 
 
755
        $.fancybox = function(obj) {
 
756
                if (busy) {
 
757
                        return;
 
758
                }
 
759
 
 
760
                busy = true;
 
761
 
 
762
                var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};
 
763
 
 
764
                selectedArray   = [];
 
765
                selectedIndex   = opts.index || 0;
 
766
 
 
767
                if ($.isArray(obj)) {
 
768
                        for (var i = 0, j = obj.length; i < j; i++) {
 
769
                                if (typeof obj[i] == 'object') {
 
770
                                        $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
 
771
                                } else {
 
772
                                        obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
 
773
                                }
 
774
                        }
 
775
 
 
776
                        selectedArray = jQuery.merge(selectedArray, obj);
 
777
 
 
778
                } else {
 
779
                        if (typeof obj == 'object') {
 
780
                                $(obj).data('fancybox', $.extend({}, opts, obj));
 
781
                        } else {
 
782
                                obj = $({}).data('fancybox', $.extend({content : obj}, opts));
 
783
                        }
 
784
 
 
785
                        selectedArray.push(obj);
 
786
                }
 
787
 
 
788
                if (selectedIndex > selectedArray.length || selectedIndex < 0) {
 
789
                        selectedIndex = 0;
 
790
                }
 
791
 
 
792
                fancybox_start();
 
793
        };
 
794
 
 
795
        $.fancybox.showActivity = function() {
 
796
                clearInterval(loadingTimer);
 
797
 
 
798
                loading.show();
 
799
                loadingTimer = setInterval(fancybox_animate_loading, 66);
 
800
        };
 
801
 
 
802
        $.fancybox.hideActivity = function() {
 
803
                loading.hide();
 
804
        };
 
805
 
 
806
        $.fancybox.next = function() {
 
807
                return $.fancybox.pos( currentIndex + 1);
 
808
        };
 
809
        
 
810
        $.fancybox.prev = function() {
 
811
                return $.fancybox.pos( currentIndex - 1);
 
812
        };
 
813
 
 
814
        $.fancybox.pos = function(pos) {
 
815
                if (busy) {
 
816
                        return;
 
817
                }
 
818
 
 
819
                pos = parseInt(pos, 10);
 
820
 
 
821
                if (pos > -1 && currentArray.length > pos) {
 
822
                        selectedIndex = pos;
 
823
                        fancybox_start();
 
824
                }
 
825
 
 
826
                if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
 
827
                        selectedIndex = currentArray.length - 1;
 
828
                        fancybox_start();
 
829
                }
 
830
 
 
831
                if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
 
832
                        selectedIndex = 0;
 
833
                        fancybox_start();
 
834
                }
 
835
 
 
836
                return;
 
837
        };
 
838
 
 
839
        $.fancybox.cancel = function() {
 
840
                if (busy) {
 
841
                        return;
 
842
                }
 
843
 
 
844
                busy = true;
 
845
 
 
846
                $.event.trigger('fancybox-cancel');
 
847
 
 
848
                fancybox_abort();
 
849
 
 
850
                if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
 
851
                        selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
 
852
                }
 
853
 
 
854
                busy = false;
 
855
        };
 
856
 
 
857
        // Note: within an iframe use - parent.$.fancybox.close();
 
858
        $.fancybox.close = function() {
 
859
                if (busy || wrap.is(':hidden')) {
 
860
                        return;
 
861
                }
 
862
 
 
863
                busy = true;
 
864
 
 
865
                if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
 
866
                        if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
 
867
                                busy = false;
 
868
                                return;
 
869
                        }
 
870
                }
 
871
 
 
872
                fancybox_abort();
 
873
 
 
874
                $(close.add( nav_left ).add( nav_right )).hide();
 
875
 
 
876
                $('#fancybox-title').remove();
 
877
 
 
878
                wrap.add(inner).add(overlay).unbind();
 
879
 
 
880
                $(window).unbind("resize.fb scroll.fb");
 
881
                $(document).unbind('keydown.fb');
 
882
 
 
883
                function _cleanup() {
 
884
                        overlay.fadeOut('fast');
 
885
 
 
886
                        wrap.hide();
 
887
 
 
888
                        $.event.trigger('fancybox-cleanup');
 
889
 
 
890
                        inner.empty();
 
891
 
 
892
                        if ($.isFunction(currentOpts.onClosed)) {
 
893
                                currentOpts.onClosed(currentArray, currentIndex, currentOpts);
 
894
                        }
 
895
 
 
896
                        currentArray    = selectedOpts  = [];
 
897
                        currentIndex    = selectedIndex = 0;
 
898
                        currentOpts             = selectedOpts  = {};
 
899
 
 
900
                        busy = false;
 
901
                }
 
902
 
 
903
                inner.css('overflow', 'hidden');
 
904
 
 
905
                if (currentOpts.transitionOut == 'elastic') {
 
906
                        start_pos = fancybox_get_zoom_from();
 
907
 
 
908
                        var pos = wrap.position();
 
909
 
 
910
                        final_pos = {
 
911
                                top             :       pos.top ,
 
912
                                left    :       pos.left,
 
913
                                width   :       wrap.width(),
 
914
                                height  :       wrap.height()
 
915
                        };
 
916
 
 
917
                        if (currentOpts.opacity) {
 
918
                                final_pos.opacity = 1;
 
919
                        }
 
920
 
 
921
                        fx.prop = 1;
 
922
 
 
923
                        $(fx).animate({ prop: 0 }, {
 
924
                                 duration       : currentOpts.speedOut,
 
925
                                 easing         : currentOpts.easingOut,
 
926
                                 step           : fancybox_draw,
 
927
                                 complete       : _cleanup
 
928
                        });
 
929
 
 
930
                } else {
 
931
                        wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
 
932
                }
 
933
        };
 
934
 
 
935
        $.fancybox.resize = function() {
 
936
                var c, h;
 
937
                
 
938
                if (busy || wrap.is(':hidden')) {
 
939
                        return;
 
940
                }
 
941
 
 
942
                busy = true;
 
943
 
 
944
                c = inner.wrapInner("<div style='overflow:auto'></div>").children();
 
945
                h = c.height();
 
946
 
 
947
                wrap.css({height:       h + (currentOpts.padding * 2) + titleh});
 
948
                inner.css({height:      h});
 
949
 
 
950
                c.replaceWith(c.children());
 
951
 
 
952
                $.fancybox.center();
 
953
        };
 
954
 
 
955
        $.fancybox.center = function() {
 
956
                busy = true;
 
957
 
 
958
                var view        = fancybox_get_viewport(),
 
959
                        margin  = currentOpts.margin,
 
960
                        to              = {};
 
961
 
 
962
                to.top  = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
 
963
                to.left = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);
 
964
 
 
965
                to.top  = Math.max(view[3] + margin, to.top);
 
966
                to.left = Math.max(view[2] + margin, to.left);
 
967
 
 
968
                wrap.css(to);
 
969
 
 
970
                busy = false;
 
971
        };
 
972
 
 
973
        $.fn.fancybox.defaults = {
 
974
                padding                         :       10,
 
975
                margin                          :       20,
 
976
                opacity                         :       false,
 
977
                modal                           :       false,
 
978
                cyclic                          :       false,
 
979
                scrolling                       :       'auto', // 'auto', 'yes' or 'no'
 
980
 
 
981
                width                           :       560,
 
982
                height                          :       340,
 
983
 
 
984
                autoScale                       :       true,
 
985
                autoDimensions          :       true,
 
986
                centerOnScroll          :       false,
 
987
 
 
988
                ajax                            :       {},
 
989
                swf                                     :       { wmode: 'transparent' },
 
990
 
 
991
                hideOnOverlayClick      :       true,
 
992
                hideOnContentClick      :       false,
 
993
 
 
994
                overlayShow                     :       true,
 
995
                overlayOpacity          :       0.3,
 
996
                overlayColor            :       '#666',
 
997
 
 
998
                titleShow                       :       true,
 
999
                titlePosition           :       'outside',      // 'outside', 'inside' or 'over'
 
1000
                titleFormat                     :       null,
 
1001
 
 
1002
                transitionIn            :       'fade', // 'elastic', 'fade' or 'none'
 
1003
                transitionOut           :       'fade', // 'elastic', 'fade' or 'none'
 
1004
 
 
1005
                speedIn                         :       300,
 
1006
                speedOut                        :       300,
 
1007
 
 
1008
                changeSpeed                     :       300,
 
1009
                changeFade                      :       'fast',
 
1010
 
 
1011
                easingIn                        :       'swing',
 
1012
                easingOut                       :       'swing',
 
1013
 
 
1014
                showCloseButton         :       true,
 
1015
                showNavArrows           :       true,
 
1016
                enableEscapeButton      :       true,
 
1017
 
 
1018
                onStart                         :       null,
 
1019
                onCancel                        :       null,
 
1020
                onComplete                      :       null,
 
1021
                onCleanup                       :       null,
 
1022
                onClosed                        :       null
 
1023
        };
 
1024
 
 
1025
        $(document).ready(function() {
 
1026
                fancybox_init();
 
1027
        });
 
1028
 
 
1029
})(jQuery);