// ColorBox v1.3.18 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php

jq_163(function() {
    var
    // Default settings object.	
    // See http://jacklmoore.com/colorbox for details.
    defaults = {
        transition: "elastic",
        speed: 300,
        width: false,
        initialWidth: "600",
        innerWidth: false,
        maxWidth: 790,
        height: false,
        initialHeight: "450",
        innerHeight: false,
        maxHeight: 483,
        scalePhotos: false,
        scrolling: false,
        inline: false,
        html: false,
        iframe: false,
        fastIframe: true,
        photo: false,
        href: false,
        title: false,
        rel: false,
        opacity: 0.4,
        preloading: true,
        current: "image {current} of {total}",
        previous: "previous",
        next: "next",
        close: "close",
        open: false,
        returnFocus: true,
        loop: true,
        slideshow: false,
        slideshowAuto: true,
        slideshowSpeed: 2500,
        slideshowStart: "start slideshow",
        slideshowStop: "stop slideshow",
        onOpen: false,
        onLoad: false,
        onComplete: false,
        onCleanup: false,
        onClosed: false,
        overlayClose: true,		
        escKey: true,
        arrowKey: true,
        top: "80px", /* Change this to change how far from the top the image is */
        bottom: false,
        left: false,
        right: false,
        fixed: false,
        data: undefined
    },
	
    // Abstracting the HTML and event identifiers for easy rebranding
    colorbox = 'colorbox',
    prefix = 'cbox',
    boxElement = prefix + 'Element',
    
    // Events	
    event_open = prefix + '_open',
    event_load = prefix + '_load',
    event_complete = prefix + '_complete',
    event_cleanup = prefix + '_cleanup',
    event_closed = prefix + '_closed',
    event_purge = prefix + '_purge',
    
    // Special Handling for IE
    isIE = jq_163.browser.msie && !jq_163.support.opacity, // Detects IE6,7,8.  IE9 supports opacity.  Feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome, hence the user-agent test.
    isIE6 = isIE && jq_163.browser.version < 7,
    event_ie6 = prefix + '_IE6',
    
    // Cached jQuery Object Variables
    jq_163overlay,
    jq_163box,
    jq_163wrap,
    jq_163content,
    jq_163topBorder,
    jq_163leftBorder,
    jq_163rightBorder,
    jq_163bottomBorder,
    jq_163related,
    jq_163window,
    jq_163loaded,
    jq_163loadingBay,
    jq_163loadingOverlay,
    jq_163title,
    jq_163current,
    jq_163slideshow,
    jq_163next,
    jq_163prev,
    jq_163close,
    jq_163groupControls,
    
    // Variables for cached values or use across multiple functions
    settings,
    interfaceHeight,
    interfaceWidth,
    loadedHeight,
    loadedWidth,
    element,
    index,
    photo,
    open,
    active,
    closing,
    loadingTimer,
    publicMethod,
    div = "div";

	// ****************
	// HELPER FUNCTIONS
	// ****************
    
	// Convience function for creating new jQuery objects
    function jq_163tag(tag, id, css) {
        var element = document.createElement(tag);
        
        if (id) {
            element.id = prefix + id;
        }
        
        if (css) {
            element.style.cssText = css;
        }
        
        return jq_163(element);
    }

	// Determine the next and previous members in a group.
	function getIndex(increment) {
		var 
		max = jq_163related.length, 
		newIndex = (index + increment) % max;
		
		return (newIndex < 0) ? max + newIndex : newIndex;
	}

	// Convert '%' and 'px' values to integers
	function setSize(size, dimension) {
		return Math.round((/%/.test(size) ? ((dimension === 'x' ? jq_163window.width() : jq_163window.height()) / 100) : 1) * parseInt(size, 10));
	}
	
	// Checks an href to see if it is a photo.
	// There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
	function isImage(url) {
		return settings.photo || /\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?jq_163/i.test(url);
	}
	
	// Assigns function results to their respective properties
	function makeSettings() {
        var i;
        settings = jq_163.extend({}, jq_163.data(element, colorbox));
        
		for (i in settings) {
			if (jq_163.isFunction(settings[i]) && i.slice(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
			    settings[i] = settings[i].call(element);
			}
		}
        
		settings.rel = settings.rel || element.rel || 'nofollow';
		settings.href = settings.href || jq_163(element).attr('href');
		settings.title = settings.title || element.title;
        
        if (typeof settings.href === "string") {
            settings.href = jq_163.trim(settings.href);
        }
	}

	function trigger(event, callback) {
		jq_163.event.trigger(event);
		if (callback) {
			callback.call(element);
		}
	}

	// Slideshow functionality
	function slideshow() {
		var
		timeOut,
		className = prefix + "Slideshow_",
		click = "click." + prefix,
		start,
		stop,
		clear;
		
		if (settings.slideshow && jq_163related[1]) {
			start = function () {
				jq_163slideshow
					.text(settings.slideshowStop)
					.unbind(click)
					.bind(event_complete, function () {
						if (index < jq_163related.length - 1 || settings.loop) {
							timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
						}
					})
					.bind(event_load, function () {
						clearTimeout(timeOut);
					})
					.one(click + ' ' + event_cleanup, stop);
				jq_163box.removeClass(className + "off").addClass(className + "on");
				timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
			};
			
			stop = function () {
				clearTimeout(timeOut);
				jq_163slideshow
					.text(settings.slideshowStart)
					.unbind([event_complete, event_load, event_cleanup, click].join(' '))
					.one(click, function () {
						publicMethod.next();
						start();
					});
				jq_163box.removeClass(className + "on").addClass(className + "off");
			};
			
			if (settings.slideshowAuto) {
				start();
			} else {
				stop();
			}
		} else {
            jq_163box.removeClass(className + "off " + className + "on");
        }
	}

	function launch(target) {
		if (!closing) {
			
			element = target;
			
			makeSettings();
			
			jq_163related = jq_163(element);
			
			index = 0;
			
			if (settings.rel !== 'nofollow') {
				jq_163related = jq_163('.' + boxElement).filter(function () {
					var relRelated = jq_163.data(this, colorbox).rel || this.rel;
					return (relRelated === settings.rel);
				});
				index = jq_163related.index(element);
				
				// Check direct calls to ColorBox.
				if (index === -1) {
					jq_163related = jq_163related.add(element);
					index = jq_163related.length - 1;
				}
			}
			
			if (!open) {
				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
				
				jq_163box.show();
				
				if (settings.returnFocus) {
					try {
						element.blur();
						jq_163(element).one(event_closed, function () {
							try {
								this.focus();
							} catch (e) {
								// do nothing
							}
						});
					} catch (e) {
						// do nothing
					}
				}
				
				// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
				jq_163overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
				
				// Opens inital empty ColorBox prior to content being loaded.
				settings.w = setSize(settings.initialWidth, 'x');
				settings.h = setSize(settings.initialHeight, 'y');
				publicMethod.position();
				
				if (isIE6) {
					jq_163window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
						jq_163overlay.css({width: jq_163window.width(), height: jq_163window.height(), top: jq_163window.scrollTop(), left: jq_163window.scrollLeft()});
					}).trigger('resize.' + event_ie6);
				}
				
				trigger(event_open, settings.onOpen);
				
				jq_163groupControls.add(jq_163title).hide();
				
				jq_163close.html(settings.close).show();
			}
			
			publicMethod.load(true);
		}
	}

	// ****************
	// PUBLIC FUNCTIONS
	// Usage format: jq_163.fn.colorbox.close();
	// Usage from within an iframe: parent.jq_163.fn.colorbox.close();
	// ****************
	
	publicMethod = jq_163.fn[colorbox] = jq_163[colorbox] = function (options, callback) {
		var jq_163this = this;
		
        options = options || {};
        
		publicMethod.init();
		
		if (!jq_163this[0]) {
			if (jq_163this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
                return jq_163this;
            }
            // if no selector was given (ie. jq_163.colorbox()), create a temporary element to work with
			jq_163this = jq_163('<a/>');
			options.open = true; // assume an immediate open
		}
		
		if (callback) {
			options.onComplete = callback;
		}
		
		jq_163this.each(function () {
			jq_163.data(this, colorbox, jq_163.extend({}, jq_163.data(this, colorbox) || defaults, options));
			jq_163(this).addClass(boxElement);
		});
		
        if ((jq_163.isFunction(options.open) && options.open.call(jq_163this)) || options.open) {
			launch(jq_163this[0]);
		}
        
		return jq_163this;
	};

	// Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
	// This preps ColorBox for a speedy open when clicked, and minimizes the burdon on the browser by only
	// having to run once, instead of each time colorbox is opened.
	publicMethod.init = function () {
		if (!jq_163box) {
			
			// If the body is not present yet, wait for DOM ready
			if (!jq_163('body')[0]) {
				jq_163(publicMethod.init);
				return;
			}
			
			// Create the markup and append to BODY
			jq_163window = jq_163(window);
			jq_163box = jq_163tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''});
			jq_163overlay = jq_163tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
			jq_163wrap = jq_163tag(div, "Wrapper");
			jq_163content = jq_163tag(div, "Content").append(
				jq_163loaded = jq_163tag(div, "LoadedContent", 'width:0; height:0; overflow:hidden'),
				jq_163loadingOverlay = jq_163tag(div, "LoadingOverlay").add(jq_163tag(div, "LoadingGraphic")),
				jq_163title = jq_163tag(div, "Title"),
				jq_163current = jq_163tag(div, "Current"),
				jq_163next = jq_163tag(div, "Next"),
				jq_163prev = jq_163tag(div, "Previous"),
				jq_163slideshow = jq_163tag(div, "Slideshow").bind(event_open, slideshow),
				jq_163close = jq_163tag(div, "Close")
			);
			
			jq_163wrap.append( // The 3x3 Grid that makes up ColorBox
				jq_163tag(div).append(
					jq_163tag(div, "TopLeft"),
					jq_163topBorder = jq_163tag(div, "TopCenter"),
					jq_163tag(div, "TopRight")
				),
				jq_163tag(div, false, 'clear:left').append(
					jq_163leftBorder = jq_163tag(div, "MiddleLeft"),
					jq_163content,
					jq_163rightBorder = jq_163tag(div, "MiddleRight")
				),
				jq_163tag(div, false, 'clear:left').append(
					jq_163tag(div, "BottomLeft"),
					jq_163bottomBorder = jq_163tag(div, "BottomCenter"),
					jq_163tag(div, "BottomRight")
				)
			).find('div div').css({'float': 'left'});
			
			jq_163loadingBay = jq_163tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
			
			jq_163('body').prepend(jq_163overlay, jq_163box.append(jq_163wrap, jq_163loadingBay));
			
			// Cache values needed for size calculations
			interfaceHeight = jq_163topBorder.height() + jq_163bottomBorder.height() + jq_163content.outerHeight(true) - jq_163content.height();//Subtraction needed for IE6
			interfaceWidth = jq_163leftBorder.width() + jq_163rightBorder.width() + jq_163content.outerWidth(true) - jq_163content.width();
			loadedHeight = jq_163loaded.outerHeight(true);
			loadedWidth = jq_163loaded.outerWidth(true);
			
			// Setting padding to remove the need to do size conversions during the animation step.
			jq_163box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
			
			// Setup button events.
			// Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
			jq_163next.click(function () {
				publicMethod.next();
			});
			jq_163prev.click(function () {
				publicMethod.prev();
			});
			jq_163close.click(function () {
				publicMethod.close();
			});
			
			jq_163groupControls = jq_163next.add(jq_163prev).add(jq_163current).add(jq_163slideshow);
			
			jq_163overlay.click(function () {
				if (settings.overlayClose) {
					publicMethod.close();
				}
			});
			
			// Set Navigation Key Bindings
			jq_163(document).bind('keydown.' + prefix, function (e) {
				var key = e.keyCode;
				if (open && settings.escKey && key === 27) {
					e.preventDefault();
					publicMethod.close();
				}
				if (open && settings.arrowKey && jq_163related[1]) {
					if (key === 37) {
						e.preventDefault();
						jq_163prev.click();
					} else if (key === 39) {
						e.preventDefault();
						jq_163next.click();
					}
				}
			});
		}
	};
	
	publicMethod.remove = function () {
		jq_163box.add(jq_163overlay).remove();
		jq_163box = null;
		jq_163('.' + boxElement).removeData(colorbox).removeClass(boxElement);
	};

	publicMethod.position = function (speed, loadedCallback) {
        var top = 0, left = 0, offset = jq_163box.offset();
        
        jq_163window.unbind('resize.' + prefix);

        // remove the modal so that it doesn't influence the document width/height        
        jq_163box.css({top: -99999, left: -99999});

        if (settings.fixed && !isIE6) {
            jq_163box.css({position: 'fixed'});
        } else {
            top = jq_163window.scrollTop();
            left = jq_163window.scrollLeft();
            jq_163box.css({position: 'absolute'});
        }

		// keeps the top and left positions within the browser's viewport.
        if (settings.right !== false) {
            left += Math.max(jq_163window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
        } else if (settings.left !== false) {
            left += setSize(settings.left, 'x');
        } else {
            left += Math.round(Math.max(jq_163window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
        }
        
        if (settings.bottom !== false) {
            top += Math.max(jq_163window.height() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
        } else if (settings.top !== false) {
            top += setSize(settings.top, 'y');
        } else {
            top += Math.round(Math.max(jq_163window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
        }
        
        jq_163box.css({top: offset.top, left: offset.left});
        
		// setting the speed to 0 to reduce the delay between same-sized content.
		speed = (jq_163box.width() === settings.w + loadedWidth && jq_163box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
        
		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
		// it can invoke an obscure IE bug when using iframes.
		jq_163wrap[0].style.width = jq_163wrap[0].style.height = "9999px";
		
		function modalDimensions(that) {
			// loading overlay height has to be explicitly set for IE6.
			jq_163topBorder[0].style.width = jq_163bottomBorder[0].style.width = jq_163content[0].style.width = that.style.width;
			jq_163loadingOverlay[0].style.height = jq_163loadingOverlay[1].style.height = jq_163content[0].style.height = jq_163leftBorder[0].style.height = jq_163rightBorder[0].style.height = that.style.height;
		}
		
		jq_163box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
			duration: speed,
			complete: function () {
				modalDimensions(this);
				
				active = false;
				
				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
				jq_163wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
				jq_163wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
				
				if (loadedCallback) {
					loadedCallback();
				}
                
                setTimeout(function () {  // small delay before binding onresize due to an IE8 bug.
                    jq_163window.bind('resize.' + prefix, publicMethod.position);
                }, 1);
			},
			step: function () {
				modalDimensions(this);
			}
		});
	};

	publicMethod.resize = function (options) {
		if (open) {
			options = options || {};
			
			if (options.width) {
				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
			}
			if (options.innerWidth) {
				settings.w = setSize(options.innerWidth, 'x');
			}
			jq_163loaded.css({width: settings.w});
			
			if (options.height) {
				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
			}
			if (options.innerHeight) {
				settings.h = setSize(options.innerHeight, 'y');
			}
			if (!options.innerHeight && !options.height) {
				jq_163loaded.css({height: "auto"});
				settings.h = jq_163loaded.height();
			}
			jq_163loaded.css({height: settings.h});
			
			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
		}
	};

	publicMethod.prep = function (object) {
		if (!open) {
			return;
		}
		
		var callback, speed = settings.transition === "none" ? 0 : settings.speed;
		
		jq_163loaded.remove();
		jq_163loaded = jq_163tag(div, 'LoadedContent').append(object);
		
		function getWidth() {
			settings.w = settings.w || jq_163loaded.width();
			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
			return settings.w;
		}
		function getHeight() {
			settings.h = settings.h || jq_163loaded.height();
			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
			return settings.h;
		}
		
		jq_163loaded.hide()
		.appendTo(jq_163loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
		.prependTo(jq_163content);
		
		jq_163loadingBay.hide();
		
		// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
		//jq_163(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
		
        jq_163(photo).css({'float': 'none'});
        
		// Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
		if (isIE6) {
			jq_163('select').not(jq_163box.find('select')).filter(function () {
				return this.style.visibility !== 'hidden';
			}).css({'visibility': 'hidden'}).one(event_cleanup, function () {
				this.style.visibility = 'inherit';
			});
		}
		
		callback = function () {
            var preload, i, total = jq_163related.length, iframe, frameBorder = 'frameBorder', allowTransparency = 'allowTransparency', complete, src, img;
            
            if (!open) {
                return;
            }
            
            function removeFilter() {
                if (isIE) {
                    jq_163box[0].style.removeAttribute('filter');
                }
            }
            
            complete = function () {
                clearTimeout(loadingTimer);
                jq_163loadingOverlay.hide();
                trigger(event_complete, settings.onComplete);
            };
            
            if (isIE) {
                //This fadeIn helps the bicubic resampling to kick-in.
                if (photo) {
                    jq_163loaded.fadeIn(100);
                }
            }
            
            jq_163title.html(settings.title).add(jq_163loaded).show();
            
            if (total > 1) { // handle grouping
                if (typeof settings.current === "string") {
                    jq_163current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
                }
                
                jq_163next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
                jq_163prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
				
                if (settings.slideshow) {
                    jq_163slideshow.show();
                }
				
                // Preloads images within a rel group
                if (settings.preloading) {
					preload = [
						getIndex(-1),
						getIndex(1)
					];
					while ((i = jq_163related[preload.pop()])) {
						src = jq_163.data(i, colorbox).href || i.href;
						if (jq_163.isFunction(src)) {
							src = src.call(i);
						}
						if (isImage(src)) {
							img = new Image();
							img.src = src;
						}
					}
                }
            } else {
                jq_163groupControls.hide();
            }
            
            if (settings.iframe) {
                iframe = jq_163tag('iframe')[0];
                
                if (frameBorder in iframe) {
                    iframe[frameBorder] = 0;
                }
                if (allowTransparency in iframe) {
                    iframe[allowTransparency] = "true";
                }
                // give the iframe a unique name to prevent caching
                iframe.name = prefix + (+new Date());
                if (settings.fastIframe) {
                    complete();
                } else {
                    jq_163(iframe).one('load', complete);
                }
                iframe.src = settings.href;
                if (!settings.scrolling) {
                    iframe.scrolling = "no";
                }
                jq_163(iframe).addClass(prefix + 'Iframe').appendTo(jq_163loaded).one(event_purge, function () {
                    iframe.src = "//about:blank";
                });
            } else {
                complete();
            }
            
            if (settings.transition === 'fade') {
                jq_163box.fadeTo(speed, 1, removeFilter);
            } else {
                removeFilter();
            }
		};
		
		if (settings.transition === 'fade') {
			jq_163box.fadeTo(speed, 0, function () {
				publicMethod.position(0, callback);
			});
		} else {
			publicMethod.position(speed, callback);
		}
	};

	publicMethod.load = function (launched) {
		var href, setResize, prep = publicMethod.prep;
		
		active = true;
		
		photo = false;
		
		element = jq_163related[index];
		
		if (!launched) {
			makeSettings();
		}
		
		trigger(event_purge);
		
		trigger(event_load, settings.onLoad);
		
		settings.h = settings.height ?
				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
				settings.innerHeight && setSize(settings.innerHeight, 'y');
		
		settings.w = settings.width ?
				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
				settings.innerWidth && setSize(settings.innerWidth, 'x');
		
		// Sets the minimum dimensions for use in image scaling
		settings.mw = settings.w;
		settings.mh = settings.h;
		
		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
		if (settings.maxWidth) {
			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
		}
		if (settings.maxHeight) {
			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
		}
		
		href = settings.href;
		
        loadingTimer = setTimeout(function () {
            jq_163loadingOverlay.show();
        }, 100);
        
		if (settings.inline) {
			// Inserts an empty placeholder where inline content is being pulled from.
			// An event is bound to put inline content back when ColorBox closes or loads new content.
			jq_163tag(div).hide().insertBefore(jq_163(href)[0]).one(event_purge, function () {
				jq_163(this).replaceWith(jq_163loaded.children());
			});
			prep(jq_163(href));
		} else if (settings.iframe) {
			// IFrame element won't be added to the DOM until it is ready to be displayed,
			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
			prep(" ");
		} else if (settings.html) {
			prep(settings.html);
		} else if (isImage(href)) {
			jq_163(photo = new Image())
			.addClass(prefix + 'Photo')
			.error(function () {
				settings.title = false;
				prep(jq_163tag(div, 'Error').text('This image could not be loaded'));
			})
			.load(function () {
				var percent;
				photo.onload = null; //stops animated gifs from firing the onload repeatedly.
				
				if (settings.scalePhotos) {
					setResize = function () {
						photo.height -= photo.height * percent;
						photo.width -= photo.width * percent;	
					};
					if (settings.mw && photo.width > settings.mw) {
						percent = (photo.width - settings.mw) / photo.width;
						setResize();
					}
					if (settings.mh && photo.height > settings.mh) {
						percent = (photo.height - settings.mh) / photo.height;
						setResize();
					}
				}
				
				if (settings.h) {
					photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
				}
				
				if (jq_163related[1] && (index < jq_163related.length - 1 || settings.loop)) {
					photo.style.cursor = 'pointer';
					photo.onclick = function () {
                        publicMethod.next();
                    };
				}
				
				if (isIE) {
					photo.style.msInterpolationMode = 'bicubic';
				}
				
				setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
					prep(photo);
				}, 1);
			});
			
			setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
				photo.src = href;
			}, 1);
		} else if (href) {
			jq_163loadingBay.load(href, settings.data, function (data, status, xhr) {
				prep(status === 'error' ? jq_163tag(div, 'Error').text('Request unsuccessful: ' + xhr.statusText) : jq_163(this).contents());
			});
		}
	};
        
	// Navigates to the next page/image in a set.
	publicMethod.next = function () {
		if (!active && jq_163related[1] && (index < jq_163related.length - 1 || settings.loop)) {
			index = getIndex(1);
			publicMethod.load();
		}
	};
	
	publicMethod.prev = function () {
		if (!active && jq_163related[1] && (index || settings.loop)) {
			index = getIndex(-1);
			publicMethod.load();
		}
	};

	// Note: to use this within an iframe use the following format: parent.jq_163.fn.colorbox.close();
	publicMethod.close = function () {
		if (open && !closing) {
			
			closing = true;
			
			open = false;
			
			trigger(event_cleanup, settings.onCleanup);
			
			jq_163window.unbind('.' + prefix + ' .' + event_ie6);
			
			jq_163overlay.fadeTo(200, 0);
			
			jq_163box.stop().fadeTo(300, 0, function () {
                 
				jq_163box.add(jq_163overlay).css({'opacity': 1, cursor: 'auto'}).hide();
				
				trigger(event_purge);
				
				jq_163loaded.remove();
				
				setTimeout(function () {
					closing = false;
					trigger(event_closed, settings.onClosed);
				}, 1);
			});
		}
	};

	// A method for fetching the current element ColorBox is referencing.
	// returns a jQuery object.
	publicMethod.element = function () {
		return jq_163(element);
	};

	publicMethod.settings = defaults;
    
	// Bind the live event before DOM-ready for maximum performance in IE6 & 7.
	jq_163('.' + boxElement, document).live('click', function (e) {
        // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
        // See: http://jacklmoore.com/notes/click-events/
        if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
            e.preventDefault();
            launch(this);
        }
    });

	// Setup ColorBox
	publicMethod.init();

});
