fhiiqm/js/jquery/jquery.colorbox.js
changeset 1 6288d5685bff
equal deleted inserted replaced
0:ef68113ff309 1:6288d5685bff
       
     1 // ColorBox v1.3.17.2 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
       
     2 // Copyright (c) 2011 Jack Moore - jack@colorpowered.com
       
     3 // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
       
     4 
       
     5 (function ($, document, window) {
       
     6 	var
       
     7 	// ColorBox Default Settings.	
       
     8 	// See http://colorpowered.com/colorbox for details.
       
     9 	defaults = {
       
    10 		transition: "elastic",
       
    11 		speed: 300,
       
    12 		width: false,
       
    13 		initialWidth: "600",
       
    14 		innerWidth: false,
       
    15 		maxWidth: false,
       
    16 		height: false,
       
    17 		initialHeight: "450",
       
    18 		innerHeight: false,
       
    19 		maxHeight: false,
       
    20 		scalePhotos: true,
       
    21 		scrolling: true,
       
    22 		inline: false,
       
    23 		html: false,
       
    24 		iframe: false,
       
    25 		fastIframe: true,
       
    26 		photo: false,
       
    27 		href: false,
       
    28 		title: false,
       
    29 		rel: false,
       
    30 		opacity: 0.9,
       
    31 		preloading: true,
       
    32 		current: "image {current} of {total}",
       
    33 		previous: "previous",
       
    34 		next: "next",
       
    35 		close: "close",
       
    36 		open: false,
       
    37 		returnFocus: true,
       
    38 		loop: true,
       
    39 		slideshow: false,
       
    40 		slideshowAuto: true,
       
    41 		slideshowSpeed: 2500,
       
    42 		slideshowStart: "start slideshow",
       
    43 		slideshowStop: "stop slideshow",
       
    44 		onOpen: false,
       
    45 		onLoad: false,
       
    46 		onComplete: false,
       
    47 		onCleanup: false,
       
    48 		onClosed: false,
       
    49 		overlayClose: true,		
       
    50 		escKey: true,
       
    51 		arrowKey: true,
       
    52         top: false,
       
    53         bottom: false,
       
    54         left: false,
       
    55         right: false,
       
    56         fixed: false,
       
    57         data: false
       
    58 	},
       
    59 	
       
    60 	// Abstracting the HTML and event identifiers for easy rebranding
       
    61 	colorbox = 'colorbox',
       
    62 	prefix = 'cbox',
       
    63     boxElement = prefix + 'Element',
       
    64 	
       
    65 	// Events	
       
    66 	event_open = prefix + '_open',
       
    67 	event_load = prefix + '_load',
       
    68 	event_complete = prefix + '_complete',
       
    69 	event_cleanup = prefix + '_cleanup',
       
    70 	event_closed = prefix + '_closed',
       
    71 	event_purge = prefix + '_purge',
       
    72 	
       
    73 	// Special Handling for IE
       
    74 	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.
       
    75 	isIE6 = isIE && $.browser.version < 7,
       
    76 	event_ie6 = prefix + '_IE6',
       
    77 
       
    78 	// Cached jQuery Object Variables
       
    79 	$overlay,
       
    80 	$box,
       
    81 	$wrap,
       
    82 	$content,
       
    83 	$topBorder,
       
    84 	$leftBorder,
       
    85 	$rightBorder,
       
    86 	$bottomBorder,
       
    87 	$related,
       
    88 	$window,
       
    89 	$loaded,
       
    90 	$loadingBay,
       
    91 	$loadingOverlay,
       
    92 	$title,
       
    93 	$current,
       
    94 	$slideshow,
       
    95 	$next,
       
    96 	$prev,
       
    97 	$close,
       
    98 	$groupControls,
       
    99 
       
   100 	// Variables for cached values or use across multiple functions
       
   101 	settings,
       
   102 	interfaceHeight,
       
   103 	interfaceWidth,
       
   104 	loadedHeight,
       
   105 	loadedWidth,
       
   106 	element,
       
   107 	index,
       
   108 	photo,
       
   109 	open,
       
   110 	active,
       
   111 	closing,
       
   112     handler,
       
   113     loadingTimer,
       
   114     publicMethod;
       
   115 	
       
   116 	// ****************
       
   117 	// HELPER FUNCTIONS
       
   118 	// ****************
       
   119 
       
   120 	// jQuery object generator to reduce code size
       
   121 	function $div(id, cssText, div) { 
       
   122 		div = document.createElement('div');
       
   123 		if (id) {
       
   124             div.id = prefix + id;
       
   125         }
       
   126 		div.style.cssText = cssText || '';
       
   127 		return $(div);
       
   128 	}
       
   129 
       
   130 	// Convert '%' and 'px' values to integers
       
   131 	function setSize(size, dimension) {
       
   132 		return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : $window.height()) / 100) : 1) * parseInt(size, 10));
       
   133 	}
       
   134 	
       
   135 	// Checks an href to see if it is a photo.
       
   136 	// There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
       
   137 	function isImage(url) {
       
   138 		return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url);
       
   139 	}
       
   140 	
       
   141 	// Assigns function results to their respective settings.  This allows functions to be used as values.
       
   142 	function makeSettings(i) {
       
   143         settings = $.extend({}, $.data(element, colorbox));
       
   144         
       
   145 		for (i in settings) {
       
   146 			if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
       
   147 			    settings[i] = settings[i].call(element);
       
   148 			}
       
   149 		}
       
   150         
       
   151 		settings.rel = settings.rel || element.rel || 'nofollow';
       
   152 		settings.href = settings.href || $(element).attr('href');
       
   153 		settings.title = settings.title || element.title;
       
   154         
       
   155         if (typeof settings.href === "string") {
       
   156             settings.href = $.trim(settings.href);
       
   157         }
       
   158 	}
       
   159 
       
   160 	function trigger(event, callback) {
       
   161 		if (callback) {
       
   162 			callback.call(element);
       
   163 		}
       
   164 		$.event.trigger(event);
       
   165 	}
       
   166 
       
   167 	// Slideshow functionality
       
   168 	function slideshow() {
       
   169 		var
       
   170 		timeOut,
       
   171 		className = prefix + "Slideshow_",
       
   172 		click = "click." + prefix,
       
   173 		start,
       
   174 		stop,
       
   175 		clear;
       
   176 		
       
   177 		if (settings.slideshow && $related[1]) {
       
   178 			start = function () {
       
   179 				$slideshow
       
   180 					.text(settings.slideshowStop)
       
   181 					.unbind(click)
       
   182 					.bind(event_complete, function () {
       
   183 						if (index < $related.length - 1 || settings.loop) {
       
   184 							timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
       
   185 						}
       
   186 					})
       
   187 					.bind(event_load, function () {
       
   188 						clearTimeout(timeOut);
       
   189 					})
       
   190 					.one(click + ' ' + event_cleanup, stop);
       
   191 				$box.removeClass(className + "off").addClass(className + "on");
       
   192 				timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
       
   193 			};
       
   194 			
       
   195 			stop = function () {
       
   196 				clearTimeout(timeOut);
       
   197 				$slideshow
       
   198 					.text(settings.slideshowStart)
       
   199 					.unbind([event_complete, event_load, event_cleanup, click].join(' '))
       
   200 					.one(click, start);
       
   201 				$box.removeClass(className + "on").addClass(className + "off");
       
   202 			};
       
   203 			
       
   204 			if (settings.slideshowAuto) {
       
   205 				start();
       
   206 			} else {
       
   207 				stop();
       
   208 			}
       
   209 		} else {
       
   210             $box.removeClass(className + "off " + className + "on");
       
   211         }
       
   212 	}
       
   213 
       
   214 	function launch(target) {
       
   215 		if (!closing) {
       
   216 			
       
   217 			element = target;
       
   218 			
       
   219 			makeSettings();
       
   220 			
       
   221 			$related = $(element);
       
   222 			
       
   223 			index = 0;
       
   224 			
       
   225 			if (settings.rel !== 'nofollow') {
       
   226 				$related = $('.' + boxElement).filter(function () {
       
   227 					var relRelated = $.data(this, colorbox).rel || this.rel;
       
   228 					return (relRelated === settings.rel);
       
   229 				});
       
   230 				index = $related.index(element);
       
   231 				
       
   232 				// Check direct calls to ColorBox.
       
   233 				if (index === -1) {
       
   234 					$related = $related.add(element);
       
   235 					index = $related.length - 1;
       
   236 				}
       
   237 			}
       
   238 			
       
   239 			if (!open) {
       
   240 				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
       
   241 				
       
   242 				$box.show();
       
   243 				
       
   244 				if (settings.returnFocus) {
       
   245 					try {
       
   246 						element.blur();
       
   247 						$(element).one(event_closed, function () {
       
   248 							try {
       
   249 								this.focus();
       
   250 							} catch (e) {
       
   251 								// do nothing
       
   252 							}
       
   253 						});
       
   254 					} catch (e) {
       
   255 						// do nothing
       
   256 					}
       
   257 				}
       
   258 				
       
   259 				// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
       
   260 				$overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
       
   261 				
       
   262 				// Opens inital empty ColorBox prior to content being loaded.
       
   263 				settings.w = setSize(settings.initialWidth, 'x');
       
   264 				settings.h = setSize(settings.initialHeight, 'y');
       
   265 				publicMethod.position();
       
   266 				
       
   267 				if (isIE6) {
       
   268 					$window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
       
   269 						$overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
       
   270 					}).trigger('resize.' + event_ie6);
       
   271 				}
       
   272 				
       
   273 				trigger(event_open, settings.onOpen);
       
   274 				
       
   275 				$groupControls.add($title).hide();
       
   276 				
       
   277 				$close.html(settings.close).show();
       
   278 			}
       
   279 			
       
   280 			publicMethod.load(true);
       
   281 		}
       
   282 	}
       
   283 
       
   284 	// ****************
       
   285 	// PUBLIC FUNCTIONS
       
   286 	// Usage format: $.fn.colorbox.close();
       
   287 	// Usage from within an iframe: parent.$.fn.colorbox.close();
       
   288 	// ****************
       
   289 	
       
   290 	publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
       
   291 		var $this = this;
       
   292 		
       
   293         options = options || {};
       
   294         
       
   295 		if (!$this[0]) {
       
   296 			if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
       
   297                 return $this;
       
   298             }
       
   299             // if no selector was given (ie. $.colorbox()), create a temporary element to work with
       
   300 			$this = $('<a/>');
       
   301 			options.open = true; // assume an immediate open
       
   302 		}
       
   303 		
       
   304 		if (callback) {
       
   305 			options.onComplete = callback;
       
   306 		}
       
   307 		
       
   308 		$this.each(function () {
       
   309 			$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
       
   310 			$(this).addClass(boxElement);
       
   311 		});
       
   312 		
       
   313         if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
       
   314 			launch($this[0]);
       
   315 		}
       
   316         
       
   317 		return $this;
       
   318 	};
       
   319 
       
   320 	// Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
       
   321 	// This preps ColorBox for a speedy open when clicked, and minimizes the burdon on the browser by only
       
   322 	// having to run once, instead of each time colorbox is opened.
       
   323 	publicMethod.init = function () {
       
   324 		// Create & Append jQuery Objects
       
   325 		$window = $(window);
       
   326 		$box = $div().attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''});
       
   327 		$overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
       
   328 		
       
   329 		$wrap = $div("Wrapper");
       
   330 		$content = $div("Content").append(
       
   331 			$loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'),
       
   332 			$loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")),
       
   333 			$title = $div("Title"),
       
   334 			$current = $div("Current"),
       
   335 			$next = $div("Next"),
       
   336 			$prev = $div("Previous"),
       
   337 			$slideshow = $div("Slideshow").bind(event_open, slideshow),
       
   338 			$close = $div("Close")
       
   339 		);
       
   340 		$wrap.append( // The 3x3 Grid that makes up ColorBox
       
   341 			$div().append(
       
   342 				$div("TopLeft"),
       
   343 				$topBorder = $div("TopCenter"),
       
   344 				$div("TopRight")
       
   345 			),
       
   346 			$div(false, 'clear:left').append(
       
   347 				$leftBorder = $div("MiddleLeft"),
       
   348 				$content,
       
   349 				$rightBorder = $div("MiddleRight")
       
   350 			),
       
   351 			$div(false, 'clear:left').append(
       
   352 				$div("BottomLeft"),
       
   353 				$bottomBorder = $div("BottomCenter"),
       
   354 				$div("BottomRight")
       
   355 			)
       
   356 		).children().children().css({'float': 'left'});
       
   357 		
       
   358 		$loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none');
       
   359 		
       
   360 		$('body').prepend($overlay, $box.append($wrap, $loadingBay));
       
   361 		
       
   362 		$content.children()
       
   363 		.hover(function () {
       
   364 			$(this).addClass('hover');
       
   365 		}, function () {
       
   366 			$(this).removeClass('hover');
       
   367 		}).addClass('hover');
       
   368 		
       
   369 		// Cache values needed for size calculations
       
   370 		interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
       
   371 		interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
       
   372 		loadedHeight = $loaded.outerHeight(true);
       
   373 		loadedWidth = $loaded.outerWidth(true);
       
   374 		
       
   375 		// Setting padding to remove the need to do size conversions during the animation step.
       
   376 		$box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
       
   377 		
       
   378         // Setup button events.
       
   379         // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
       
   380         $next.click(function () {
       
   381             publicMethod.next();
       
   382         });
       
   383         $prev.click(function () {
       
   384             publicMethod.prev();
       
   385         });
       
   386         $close.click(function () {
       
   387             publicMethod.close();
       
   388         });
       
   389 		
       
   390 		$groupControls = $next.add($prev).add($current).add($slideshow);
       
   391 		
       
   392 		// Adding the 'hover' class allowed the browser to load the hover-state
       
   393 		// background graphics in case the images were not part of a sprite.  The class can now can be removed.
       
   394 		$content.children().removeClass('hover');
       
   395 		
       
   396 		$overlay.click(function () {
       
   397 			if (settings.overlayClose) {
       
   398 				publicMethod.close();
       
   399 			}
       
   400 		});
       
   401 		
       
   402 		// Set Navigation Key Bindings
       
   403 		$(document).bind('keydown.' + prefix, function (e) {
       
   404             var key = e.keyCode;
       
   405 			if (open && settings.escKey && key === 27) {
       
   406 				e.preventDefault();
       
   407 				publicMethod.close();
       
   408 			}
       
   409 			if (open && settings.arrowKey && $related[1]) {
       
   410 				if (key === 37) {
       
   411 					e.preventDefault();
       
   412 					$prev.click();
       
   413 				} else if (key === 39) {
       
   414 					e.preventDefault();
       
   415 					$next.click();
       
   416 				}
       
   417 			}
       
   418 		});
       
   419 	};
       
   420 	
       
   421 	publicMethod.remove = function () {
       
   422 		$box.add($overlay).remove();
       
   423 		$('.' + boxElement).removeData(colorbox).removeClass(boxElement);
       
   424 	};
       
   425 
       
   426 	publicMethod.position = function (speed, loadedCallback) {
       
   427         var top = 0, left = 0;
       
   428         
       
   429         $window.unbind('resize.' + prefix);
       
   430         
       
   431         // remove the modal so that it doesn't influence the document width/height        
       
   432         $box.hide();
       
   433         
       
   434         if (settings.fixed && !isIE6) {
       
   435             $box.css({position: 'fixed'});
       
   436         } else {
       
   437             top = $window.scrollTop();
       
   438             left = $window.scrollLeft();
       
   439             $box.css({position: 'absolute'});
       
   440         }
       
   441         
       
   442 		// keeps the top and left positions within the browser's viewport.
       
   443         if (settings.right !== false) {
       
   444             left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
       
   445         } else if (settings.left !== false) {
       
   446             left += setSize(settings.left, 'x');
       
   447         } else {
       
   448             left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
       
   449         }
       
   450         
       
   451         if (settings.bottom !== false) {
       
   452             top += Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
       
   453         } else if (settings.top !== false) {
       
   454             top += setSize(settings.top, 'y');
       
   455         } else {
       
   456             top += Math.round(Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2);
       
   457         }
       
   458         
       
   459         $box.show();
       
   460         
       
   461 		// setting the speed to 0 to reduce the delay between same-sized content.
       
   462 		speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
       
   463         
       
   464 		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
       
   465 		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
       
   466 		// it can invoke an obscure IE bug when using iframes.
       
   467 		$wrap[0].style.width = $wrap[0].style.height = "9999px";
       
   468 		
       
   469 		function modalDimensions(that) {
       
   470 			// loading overlay height has to be explicitly set for IE6.
       
   471 			$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
       
   472 			$loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
       
   473 		}
       
   474 		
       
   475 		$box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
       
   476 			duration: speed,
       
   477 			complete: function () {
       
   478 				modalDimensions(this);
       
   479 				
       
   480 				active = false;
       
   481 				
       
   482 				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
       
   483 				$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
       
   484 				$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
       
   485 				
       
   486 				if (loadedCallback) {
       
   487 					loadedCallback();
       
   488 				}
       
   489                 
       
   490                 setTimeout(function(){  // small delay before binding onresize due to an IE8 bug.
       
   491                     $window.bind('resize.' + prefix, publicMethod.position);
       
   492                 }, 1);
       
   493 			},
       
   494 			step: function () {
       
   495 				modalDimensions(this);
       
   496 			}
       
   497 		});
       
   498 	};
       
   499 
       
   500 	publicMethod.resize = function (options) {
       
   501 		if (open) {
       
   502 			options = options || {};
       
   503 			
       
   504 			if (options.width) {
       
   505 				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
       
   506 			}
       
   507 			if (options.innerWidth) {
       
   508 				settings.w = setSize(options.innerWidth, 'x');
       
   509 			}
       
   510 			$loaded.css({width: settings.w});
       
   511 			
       
   512 			if (options.height) {
       
   513 				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
       
   514 			}
       
   515 			if (options.innerHeight) {
       
   516 				settings.h = setSize(options.innerHeight, 'y');
       
   517 			}
       
   518 			if (!options.innerHeight && !options.height) {				
       
   519 				var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
       
   520 				settings.h = $child.height();
       
   521 				$child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
       
   522 			}
       
   523 			$loaded.css({height: settings.h});
       
   524 			
       
   525 			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
       
   526 		}
       
   527 	};
       
   528 
       
   529 	publicMethod.prep = function (object) {
       
   530 		if (!open) {
       
   531 			return;
       
   532 		}
       
   533 		
       
   534 		var callback, speed = settings.transition === "none" ? 0 : settings.speed;
       
   535 		
       
   536 		$loaded.remove();
       
   537 		$loaded = $div('LoadedContent').append(object);
       
   538 		
       
   539 		function getWidth() {
       
   540 			settings.w = settings.w || $loaded.width();
       
   541 			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
       
   542 			return settings.w;
       
   543 		}
       
   544 		function getHeight() {
       
   545 			settings.h = settings.h || $loaded.height();
       
   546 			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
       
   547 			return settings.h;
       
   548 		}
       
   549 		
       
   550 		$loaded.hide()
       
   551 		.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
       
   552 		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
       
   553 		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
       
   554 		.prependTo($content);
       
   555 		
       
   556 		$loadingBay.hide();
       
   557 		
       
   558 		// 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.
       
   559 		//$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
       
   560 		
       
   561         $(photo).css({'float': 'none'});
       
   562         
       
   563 		// Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
       
   564 		if (isIE6) {
       
   565 			$('select').not($box.find('select')).filter(function () {
       
   566 				return this.style.visibility !== 'hidden';
       
   567 			}).css({'visibility': 'hidden'}).one(event_cleanup, function () {
       
   568 				this.style.visibility = 'inherit';
       
   569 			});
       
   570 		}
       
   571 		
       
   572 		callback = function () {
       
   573             var prev, prevSrc, next, nextSrc, total = $related.length, iframe, complete;
       
   574             
       
   575             if (!open) {
       
   576                 return;
       
   577             }
       
   578             
       
   579             function removeFilter() {
       
   580                 if (isIE) {
       
   581                     $box[0].style.removeAttribute('filter');
       
   582                 }
       
   583             }
       
   584             
       
   585             complete = function () {
       
   586                 clearTimeout(loadingTimer);
       
   587                 $loadingOverlay.hide();
       
   588                 trigger(event_complete, settings.onComplete);
       
   589             };
       
   590             
       
   591             if (isIE) {
       
   592                 //This fadeIn helps the bicubic resampling to kick-in.
       
   593                 if (photo) {
       
   594                     $loaded.fadeIn(100);
       
   595                 }
       
   596             }
       
   597             
       
   598             $title.html(settings.title).add($loaded).show();
       
   599             
       
   600             if (total > 1) { // handle grouping
       
   601                 if (typeof settings.current === "string") {
       
   602                     $current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
       
   603                 }
       
   604                 
       
   605                 $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
       
   606                 $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
       
   607                 
       
   608                 prev = index ? $related[index - 1] : $related[total - 1];
       
   609                 next = index < total - 1 ? $related[index + 1] : $related[0];
       
   610                 
       
   611                 if (settings.slideshow) {
       
   612                     $slideshow.show();
       
   613                 }
       
   614                 
       
   615                 // Preloads images within a rel group
       
   616                 if (settings.preloading) {
       
   617                     nextSrc = $.data(next, colorbox).href || next.href;
       
   618                     prevSrc = $.data(prev, colorbox).href || prev.href;
       
   619                     
       
   620                     nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc;
       
   621                     prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc;
       
   622                     
       
   623                     if (isImage(nextSrc)) {
       
   624                         $('<img/>')[0].src = nextSrc;
       
   625                     }
       
   626                     
       
   627                     if (isImage(prevSrc)) {
       
   628                         $('<img/>')[0].src = prevSrc;
       
   629                     }
       
   630                 }
       
   631             } else {
       
   632                 $groupControls.hide();
       
   633             }
       
   634             
       
   635             if (settings.iframe) {
       
   636                 iframe = $('<iframe/>').addClass(prefix + 'Iframe')[0];
       
   637                 
       
   638                 if (settings.fastIframe) {
       
   639                     complete();
       
   640                 } else {
       
   641                     $(iframe).one('load', complete);
       
   642                 }
       
   643                 iframe.name = prefix + (+new Date());
       
   644                 iframe.src = settings.href;
       
   645                 
       
   646                 if (!settings.scrolling) {
       
   647                     iframe.scrolling = "no";
       
   648                 }
       
   649                 
       
   650                 if (isIE) {
       
   651                     iframe.frameBorder = 0;
       
   652                     iframe.allowTransparency = "true";
       
   653                 }
       
   654                 
       
   655                 $(iframe).appendTo($loaded).one(event_purge, function () {
       
   656                     iframe.src = "//about:blank";
       
   657                 });
       
   658             } else {
       
   659                 complete();
       
   660             }
       
   661             
       
   662             if (settings.transition === 'fade') {
       
   663                 $box.fadeTo(speed, 1, removeFilter);
       
   664             } else {
       
   665                 removeFilter();
       
   666             }
       
   667 		};
       
   668 		
       
   669 		if (settings.transition === 'fade') {
       
   670 			$box.fadeTo(speed, 0, function () {
       
   671 				publicMethod.position(0, callback);
       
   672 			});
       
   673 		} else {
       
   674 			publicMethod.position(speed, callback);
       
   675 		}
       
   676 	};
       
   677 
       
   678 	publicMethod.load = function (launched) {
       
   679 		var href, setResize, prep = publicMethod.prep;
       
   680 		
       
   681 		active = true;
       
   682 		
       
   683 		photo = false;
       
   684 		
       
   685 		element = $related[index];
       
   686 		
       
   687 		if (!launched) {
       
   688 			makeSettings();
       
   689 		}
       
   690 		
       
   691 		trigger(event_purge);
       
   692 		
       
   693 		trigger(event_load, settings.onLoad);
       
   694 		
       
   695 		settings.h = settings.height ?
       
   696 				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
       
   697 				settings.innerHeight && setSize(settings.innerHeight, 'y');
       
   698 		
       
   699 		settings.w = settings.width ?
       
   700 				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
       
   701 				settings.innerWidth && setSize(settings.innerWidth, 'x');
       
   702 		
       
   703 		// Sets the minimum dimensions for use in image scaling
       
   704 		settings.mw = settings.w;
       
   705 		settings.mh = settings.h;
       
   706 		
       
   707 		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
       
   708 		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
       
   709 		if (settings.maxWidth) {
       
   710 			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
       
   711 			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
       
   712 		}
       
   713 		if (settings.maxHeight) {
       
   714 			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
       
   715 			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
       
   716 		}
       
   717 		
       
   718 		href = settings.href;
       
   719 		
       
   720         loadingTimer = setTimeout(function () {
       
   721             $loadingOverlay.show();
       
   722         }, 100);
       
   723         
       
   724 		if (settings.inline) {
       
   725 			// Inserts an empty placeholder where inline content is being pulled from.
       
   726 			// An event is bound to put inline content back when ColorBox closes or loads new content.
       
   727 			$div().hide().insertBefore($(href)[0]).one(event_purge, function () {
       
   728 				$(this).replaceWith($loaded.children());
       
   729 			});
       
   730 			prep($(href));
       
   731 		} else if (settings.iframe) {
       
   732 			// IFrame element won't be added to the DOM until it is ready to be displayed,
       
   733 			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
       
   734 			prep(" ");
       
   735 		} else if (settings.html) {
       
   736 			prep(settings.html);
       
   737 		} else if (isImage(href)) {
       
   738 			$(photo = new Image())
       
   739 			.addClass(prefix + 'Photo')
       
   740 			.error(function () {
       
   741 				settings.title = false;
       
   742 				prep($div('Error').text('This image could not be loaded'));
       
   743 			})
       
   744 			.load(function () {
       
   745 				var percent;
       
   746 				photo.onload = null; //stops animated gifs from firing the onload repeatedly.
       
   747 				
       
   748 				if (settings.scalePhotos) {
       
   749 					setResize = function () {
       
   750 						photo.height -= photo.height * percent;
       
   751 						photo.width -= photo.width * percent;	
       
   752 					};
       
   753 					if (settings.mw && photo.width > settings.mw) {
       
   754 						percent = (photo.width - settings.mw) / photo.width;
       
   755 						setResize();
       
   756 					}
       
   757 					if (settings.mh && photo.height > settings.mh) {
       
   758 						percent = (photo.height - settings.mh) / photo.height;
       
   759 						setResize();
       
   760 					}
       
   761 				}
       
   762 				
       
   763 				if (settings.h) {
       
   764 					photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
       
   765 				}
       
   766 				
       
   767 				if ($related[1] && (index < $related.length - 1 || settings.loop)) {
       
   768 					photo.style.cursor = 'pointer';
       
   769 					photo.onclick = function () {
       
   770                         publicMethod.next();
       
   771                     };
       
   772 				}
       
   773 				
       
   774 				if (isIE) {
       
   775 					photo.style.msInterpolationMode = 'bicubic';
       
   776 				}
       
   777 				
       
   778 				setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
       
   779 					prep(photo);
       
   780 				}, 1);
       
   781 			});
       
   782 			
       
   783 			setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
       
   784 				photo.src = href;
       
   785 			}, 1);
       
   786 		} else if (href) {
       
   787 			$loadingBay.load(href, settings.data, function (data, status, xhr) {
       
   788 				prep(status === 'error' ? $div('Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
       
   789 			});
       
   790 		}
       
   791 	};
       
   792         
       
   793 	// Navigates to the next page/image in a set.
       
   794 	publicMethod.next = function () {
       
   795 		if (!active && $related[1] && (index < $related.length - 1 || settings.loop)) {
       
   796 			index = index < $related.length - 1 ? index + 1 : 0;
       
   797 			publicMethod.load();
       
   798 		}
       
   799 	};
       
   800 	
       
   801 	publicMethod.prev = function () {
       
   802 		if (!active && $related[1] && (index || settings.loop)) {
       
   803 			index = index ? index - 1 : $related.length - 1;
       
   804 			publicMethod.load();
       
   805 		}
       
   806 	};
       
   807 
       
   808 	// Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
       
   809 	publicMethod.close = function () {
       
   810 		if (open && !closing) {
       
   811 			
       
   812 			closing = true;
       
   813 			
       
   814 			open = false;
       
   815 			
       
   816 			trigger(event_cleanup, settings.onCleanup);
       
   817 			
       
   818 			$window.unbind('.' + prefix + ' .' + event_ie6);
       
   819 			
       
   820 			$overlay.fadeTo(200, 0);
       
   821 			
       
   822 			$box.stop().fadeTo(300, 0, function () {
       
   823                  
       
   824 				$box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
       
   825 				
       
   826 				trigger(event_purge);
       
   827 				
       
   828 				$loaded.remove();
       
   829 				
       
   830 				setTimeout(function () {
       
   831 					closing = false;
       
   832 					trigger(event_closed, settings.onClosed);
       
   833 				}, 1);
       
   834 			});
       
   835 		}
       
   836 	};
       
   837 
       
   838 	// A method for fetching the current element ColorBox is referencing.
       
   839 	// returns a jQuery object.
       
   840 	publicMethod.element = function () {
       
   841 		return $(element);
       
   842 	};
       
   843 
       
   844 	publicMethod.settings = defaults;
       
   845     
       
   846 	// Bind the live event before DOM-ready for maximum performance in IE6 & 7.
       
   847     handler = function (e) {
       
   848         // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt.
       
   849         if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) {
       
   850             e.preventDefault();
       
   851             launch(this);
       
   852         }
       
   853     };
       
   854     
       
   855     if ($.fn.delegate) {
       
   856         $(document).delegate('.' + boxElement, 'click', handler);
       
   857     } else {
       
   858         $('.' + boxElement).live('click', handler);
       
   859     }
       
   860     
       
   861 	// Initializes ColorBox when the DOM has loaded
       
   862 	$(publicMethod.init);
       
   863 
       
   864 }(jQuery, document, this));