bgneal@106: /*!
bgneal@106:  * fancyBox - jQuery Plugin
bgneal@106:  * version: 2.1.5 (Fri, 14 Jun 2013)
bgneal@106:  * @requires jQuery v1.6 or later
bgneal@106:  *
bgneal@106:  * Examples at http://fancyapps.com/fancybox/
bgneal@106:  * License: www.fancyapps.com/fancybox/#license
bgneal@106:  *
bgneal@106:  * Copyright 2012 Janis Skarnelis - janis@fancyapps.com
bgneal@106:  *
bgneal@106:  */
bgneal@106: 
bgneal@106: (function (window, document, $, undefined) {
bgneal@106: 	"use strict";
bgneal@106: 
bgneal@106: 	var H = $("html"),
bgneal@106: 		W = $(window),
bgneal@106: 		D = $(document),
bgneal@106: 		F = $.fancybox = function () {
bgneal@106: 			F.open.apply( this, arguments );
bgneal@106: 		},
bgneal@106: 		IE =  navigator.userAgent.match(/msie/i),
bgneal@106: 		didUpdate	= null,
bgneal@106: 		isTouch		= document.createTouch !== undefined,
bgneal@106: 
bgneal@106: 		isQuery	= function(obj) {
bgneal@106: 			return obj && obj.hasOwnProperty && obj instanceof $;
bgneal@106: 		},
bgneal@106: 		isString = function(str) {
bgneal@106: 			return str && $.type(str) === "string";
bgneal@106: 		},
bgneal@106: 		isPercentage = function(str) {
bgneal@106: 			return isString(str) && str.indexOf('%') > 0;
bgneal@106: 		},
bgneal@106: 		isScrollable = function(el) {
bgneal@106: 			return (el && !(el.style.overflow && el.style.overflow === 'hidden') && ((el.clientWidth && el.scrollWidth > el.clientWidth) || (el.clientHeight && el.scrollHeight > el.clientHeight)));
bgneal@106: 		},
bgneal@106: 		getScalar = function(orig, dim) {
bgneal@106: 			var value = parseInt(orig, 10) || 0;
bgneal@106: 
bgneal@106: 			if (dim && isPercentage(orig)) {
bgneal@106: 				value = F.getViewport()[ dim ] / 100 * value;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			return Math.ceil(value);
bgneal@106: 		},
bgneal@106: 		getValue = function(value, dim) {
bgneal@106: 			return getScalar(value, dim) + 'px';
bgneal@106: 		};
bgneal@106: 
bgneal@106: 	$.extend(F, {
bgneal@106: 		// The current version of fancyBox
bgneal@106: 		version: '2.1.5',
bgneal@106: 
bgneal@106: 		defaults: {
bgneal@106: 			padding : 15,
bgneal@106: 			margin  : 20,
bgneal@106: 
bgneal@106: 			width     : 800,
bgneal@106: 			height    : 600,
bgneal@106: 			minWidth  : 100,
bgneal@106: 			minHeight : 100,
bgneal@106: 			maxWidth  : 9999,
bgneal@106: 			maxHeight : 9999,
bgneal@106: 			pixelRatio: 1, // Set to 2 for retina display support
bgneal@106: 
bgneal@106: 			autoSize   : true,
bgneal@106: 			autoHeight : false,
bgneal@106: 			autoWidth  : false,
bgneal@106: 
bgneal@106: 			autoResize  : true,
bgneal@106: 			autoCenter  : !isTouch,
bgneal@106: 			fitToView   : true,
bgneal@106: 			aspectRatio : false,
bgneal@106: 			topRatio    : 0.5,
bgneal@106: 			leftRatio   : 0.5,
bgneal@106: 
bgneal@106: 			scrolling : 'auto', // 'auto', 'yes' or 'no'
bgneal@106: 			wrapCSS   : '',
bgneal@106: 
bgneal@106: 			arrows     : true,
bgneal@106: 			closeBtn   : true,
bgneal@106: 			closeClick : false,
bgneal@106: 			nextClick  : false,
bgneal@106: 			mouseWheel : true,
bgneal@106: 			autoPlay   : false,
bgneal@106: 			playSpeed  : 3000,
bgneal@106: 			preload    : 3,
bgneal@106: 			modal      : false,
bgneal@106: 			loop       : true,
bgneal@106: 
bgneal@106: 			ajax  : {
bgneal@106: 				dataType : 'html',
bgneal@106: 				headers  : { 'X-fancyBox': true }
bgneal@106: 			},
bgneal@106: 			iframe : {
bgneal@106: 				scrolling : 'auto',
bgneal@106: 				preload   : true
bgneal@106: 			},
bgneal@106: 			swf : {
bgneal@106: 				wmode: 'transparent',
bgneal@106: 				allowfullscreen   : 'true',
bgneal@106: 				allowscriptaccess : 'always'
bgneal@106: 			},
bgneal@106: 
bgneal@106: 			keys  : {
bgneal@106: 				next : {
bgneal@106: 					13 : 'left', // enter
bgneal@106: 					34 : 'up',   // page down
bgneal@106: 					39 : 'left', // right arrow
bgneal@106: 					40 : 'up'    // down arrow
bgneal@106: 				},
bgneal@106: 				prev : {
bgneal@106: 					8  : 'right',  // backspace
bgneal@106: 					33 : 'down',   // page up
bgneal@106: 					37 : 'right',  // left arrow
bgneal@106: 					38 : 'down'    // up arrow
bgneal@106: 				},
bgneal@106: 				close  : [27], // escape key
bgneal@106: 				play   : [32], // space - start/stop slideshow
bgneal@106: 				toggle : [70]  // letter "f" - toggle fullscreen
bgneal@106: 			},
bgneal@106: 
bgneal@106: 			direction : {
bgneal@106: 				next : 'left',
bgneal@106: 				prev : 'right'
bgneal@106: 			},
bgneal@106: 
bgneal@106: 			scrollOutside  : true,
bgneal@106: 
bgneal@106: 			// Override some properties
bgneal@106: 			index   : 0,
bgneal@106: 			type    : null,
bgneal@106: 			href    : null,
bgneal@106: 			content : null,
bgneal@106: 			title   : null,
bgneal@106: 
bgneal@106: 			// HTML templates
bgneal@106: 			tpl: {
bgneal@106: 				wrap     : '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
bgneal@106: 				image    : '<img class="fancybox-image" src="{href}" alt="" />',
bgneal@106: 				iframe   : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen' + (IE ? ' allowtransparency="true"' : '') + '></iframe>',
bgneal@106: 				error    : '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
bgneal@106: 				closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
bgneal@106: 				next     : '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
bgneal@106: 				prev     : '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
bgneal@106: 			},
bgneal@106: 
bgneal@106: 			// Properties for each animation type
bgneal@106: 			// Opening fancyBox
bgneal@106: 			openEffect  : 'fade', // 'elastic', 'fade' or 'none'
bgneal@106: 			openSpeed   : 250,
bgneal@106: 			openEasing  : 'swing',
bgneal@106: 			openOpacity : true,
bgneal@106: 			openMethod  : 'zoomIn',
bgneal@106: 
bgneal@106: 			// Closing fancyBox
bgneal@106: 			closeEffect  : 'fade', // 'elastic', 'fade' or 'none'
bgneal@106: 			closeSpeed   : 250,
bgneal@106: 			closeEasing  : 'swing',
bgneal@106: 			closeOpacity : true,
bgneal@106: 			closeMethod  : 'zoomOut',
bgneal@106: 
bgneal@106: 			// Changing next gallery item
bgneal@106: 			nextEffect : 'elastic', // 'elastic', 'fade' or 'none'
bgneal@106: 			nextSpeed  : 250,
bgneal@106: 			nextEasing : 'swing',
bgneal@106: 			nextMethod : 'changeIn',
bgneal@106: 
bgneal@106: 			// Changing previous gallery item
bgneal@106: 			prevEffect : 'elastic', // 'elastic', 'fade' or 'none'
bgneal@106: 			prevSpeed  : 250,
bgneal@106: 			prevEasing : 'swing',
bgneal@106: 			prevMethod : 'changeOut',
bgneal@106: 
bgneal@106: 			// Enable default helpers
bgneal@106: 			helpers : {
bgneal@106: 				overlay : true,
bgneal@106: 				title   : true
bgneal@106: 			},
bgneal@106: 
bgneal@106: 			// Callbacks
bgneal@106: 			onCancel     : $.noop, // If canceling
bgneal@106: 			beforeLoad   : $.noop, // Before loading
bgneal@106: 			afterLoad    : $.noop, // After loading
bgneal@106: 			beforeShow   : $.noop, // Before changing in current item
bgneal@106: 			afterShow    : $.noop, // After opening
bgneal@106: 			beforeChange : $.noop, // Before changing gallery item
bgneal@106: 			beforeClose  : $.noop, // Before closing
bgneal@106: 			afterClose   : $.noop  // After closing
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		//Current state
bgneal@106: 		group    : {}, // Selected group
bgneal@106: 		opts     : {}, // Group options
bgneal@106: 		previous : null,  // Previous element
bgneal@106: 		coming   : null,  // Element being loaded
bgneal@106: 		current  : null,  // Currently loaded element
bgneal@106: 		isActive : false, // Is activated
bgneal@106: 		isOpen   : false, // Is currently open
bgneal@106: 		isOpened : false, // Have been fully opened at least once
bgneal@106: 
bgneal@106: 		wrap  : null,
bgneal@106: 		skin  : null,
bgneal@106: 		outer : null,
bgneal@106: 		inner : null,
bgneal@106: 
bgneal@106: 		player : {
bgneal@106: 			timer    : null,
bgneal@106: 			isActive : false
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Loaders
bgneal@106: 		ajaxLoad   : null,
bgneal@106: 		imgPreload : null,
bgneal@106: 
bgneal@106: 		// Some collections
bgneal@106: 		transitions : {},
bgneal@106: 		helpers     : {},
bgneal@106: 
bgneal@106: 		/*
bgneal@106: 		 *	Static methods
bgneal@106: 		 */
bgneal@106: 
bgneal@106: 		open: function (group, opts) {
bgneal@106: 			if (!group) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!$.isPlainObject(opts)) {
bgneal@106: 				opts = {};
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Close if already active
bgneal@106: 			if (false === F.close(true)) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Normalize group
bgneal@106: 			if (!$.isArray(group)) {
bgneal@106: 				group = isQuery(group) ? $(group).get() : [group];
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Recheck if the type of each element is `object` and set content type (image, ajax, etc)
bgneal@106: 			$.each(group, function(i, element) {
bgneal@106: 				var obj = {},
bgneal@106: 					href,
bgneal@106: 					title,
bgneal@106: 					content,
bgneal@106: 					type,
bgneal@106: 					rez,
bgneal@106: 					hrefParts,
bgneal@106: 					selector;
bgneal@106: 
bgneal@106: 				if ($.type(element) === "object") {
bgneal@106: 					// Check if is DOM element
bgneal@106: 					if (element.nodeType) {
bgneal@106: 						element = $(element);
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					if (isQuery(element)) {
bgneal@106: 						obj = {
bgneal@106: 							href    : element.data('fancybox-href') || element.attr('href'),
bgneal@106: 							title   : element.data('fancybox-title') || element.attr('title'),
bgneal@106: 							isDom   : true,
bgneal@106: 							element : element
bgneal@106: 						};
bgneal@106: 
bgneal@106: 						if ($.metadata) {
bgneal@106: 							$.extend(true, obj, element.metadata());
bgneal@106: 						}
bgneal@106: 
bgneal@106: 					} else {
bgneal@106: 						obj = element;
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				href  = opts.href  || obj.href || (isString(element) ? element : null);
bgneal@106: 				title = opts.title !== undefined ? opts.title : obj.title || '';
bgneal@106: 
bgneal@106: 				content = opts.content || obj.content;
bgneal@106: 				type    = content ? 'html' : (opts.type  || obj.type);
bgneal@106: 
bgneal@106: 				if (!type && obj.isDom) {
bgneal@106: 					type = element.data('fancybox-type');
bgneal@106: 
bgneal@106: 					if (!type) {
bgneal@106: 						rez  = element.prop('class').match(/fancybox\.(\w+)/);
bgneal@106: 						type = rez ? rez[1] : null;
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (isString(href)) {
bgneal@106: 					// Try to guess the content type
bgneal@106: 					if (!type) {
bgneal@106: 						if (F.isImage(href)) {
bgneal@106: 							type = 'image';
bgneal@106: 
bgneal@106: 						} else if (F.isSWF(href)) {
bgneal@106: 							type = 'swf';
bgneal@106: 
bgneal@106: 						} else if (href.charAt(0) === '#') {
bgneal@106: 							type = 'inline';
bgneal@106: 
bgneal@106: 						} else if (isString(element)) {
bgneal@106: 							type    = 'html';
bgneal@106: 							content = element;
bgneal@106: 						}
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					// Split url into two pieces with source url and content selector, e.g,
bgneal@106: 					// "/mypage.html #my_id" will load "/mypage.html" and display element having id "my_id"
bgneal@106: 					if (type === 'ajax') {
bgneal@106: 						hrefParts = href.split(/\s+/, 2);
bgneal@106: 						href      = hrefParts.shift();
bgneal@106: 						selector  = hrefParts.shift();
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (!content) {
bgneal@106: 					if (type === 'inline') {
bgneal@106: 						if (href) {
bgneal@106: 							content = $( isString(href) ? href.replace(/.*(?=#[^\s]+$)/, '') : href ); //strip for ie7
bgneal@106: 
bgneal@106: 						} else if (obj.isDom) {
bgneal@106: 							content = element;
bgneal@106: 						}
bgneal@106: 
bgneal@106: 					} else if (type === 'html') {
bgneal@106: 						content = href;
bgneal@106: 
bgneal@106: 					} else if (!type && !href && obj.isDom) {
bgneal@106: 						type    = 'inline';
bgneal@106: 						content = element;
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				$.extend(obj, {
bgneal@106: 					href     : href,
bgneal@106: 					type     : type,
bgneal@106: 					content  : content,
bgneal@106: 					title    : title,
bgneal@106: 					selector : selector
bgneal@106: 				});
bgneal@106: 
bgneal@106: 				group[ i ] = obj;
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			// Extend the defaults
bgneal@106: 			F.opts = $.extend(true, {}, F.defaults, opts);
bgneal@106: 
bgneal@106: 			// All options are merged recursive except keys
bgneal@106: 			if (opts.keys !== undefined) {
bgneal@106: 				F.opts.keys = opts.keys ? $.extend({}, F.defaults.keys, opts.keys) : false;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.group = group;
bgneal@106: 
bgneal@106: 			return F._start(F.opts.index);
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Cancel image loading or abort ajax request
bgneal@106: 		cancel: function () {
bgneal@106: 			var coming = F.coming;
bgneal@106: 
bgneal@106: 			if (!coming || false === F.trigger('onCancel')) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.hideLoading();
bgneal@106: 
bgneal@106: 			if (F.ajaxLoad) {
bgneal@106: 				F.ajaxLoad.abort();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.ajaxLoad = null;
bgneal@106: 
bgneal@106: 			if (F.imgPreload) {
bgneal@106: 				F.imgPreload.onload = F.imgPreload.onerror = null;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (coming.wrap) {
bgneal@106: 				coming.wrap.stop(true, true).trigger('onReset').remove();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.coming = null;
bgneal@106: 
bgneal@106: 			// If the first item has been canceled, then clear everything
bgneal@106: 			if (!F.current) {
bgneal@106: 				F._afterZoomOut( coming );
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Start closing animation if is open; remove immediately if opening/closing
bgneal@106: 		close: function (event) {
bgneal@106: 			F.cancel();
bgneal@106: 
bgneal@106: 			if (false === F.trigger('beforeClose')) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.unbindEvents();
bgneal@106: 
bgneal@106: 			if (!F.isActive) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!F.isOpen || event === true) {
bgneal@106: 				$('.fancybox-wrap').stop(true).trigger('onReset').remove();
bgneal@106: 
bgneal@106: 				F._afterZoomOut();
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				F.isOpen = F.isOpened = false;
bgneal@106: 				F.isClosing = true;
bgneal@106: 
bgneal@106: 				$('.fancybox-item, .fancybox-nav').remove();
bgneal@106: 
bgneal@106: 				F.wrap.stop(true, true).removeClass('fancybox-opened');
bgneal@106: 
bgneal@106: 				F.transitions[ F.current.closeMethod ]();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Manage slideshow:
bgneal@106: 		//   $.fancybox.play(); - toggle slideshow
bgneal@106: 		//   $.fancybox.play( true ); - start
bgneal@106: 		//   $.fancybox.play( false ); - stop
bgneal@106: 		play: function ( action ) {
bgneal@106: 			var clear = function () {
bgneal@106: 					clearTimeout(F.player.timer);
bgneal@106: 				},
bgneal@106: 				set = function () {
bgneal@106: 					clear();
bgneal@106: 
bgneal@106: 					if (F.current && F.player.isActive) {
bgneal@106: 						F.player.timer = setTimeout(F.next, F.current.playSpeed);
bgneal@106: 					}
bgneal@106: 				},
bgneal@106: 				stop = function () {
bgneal@106: 					clear();
bgneal@106: 
bgneal@106: 					D.unbind('.player');
bgneal@106: 
bgneal@106: 					F.player.isActive = false;
bgneal@106: 
bgneal@106: 					F.trigger('onPlayEnd');
bgneal@106: 				},
bgneal@106: 				start = function () {
bgneal@106: 					if (F.current && (F.current.loop || F.current.index < F.group.length - 1)) {
bgneal@106: 						F.player.isActive = true;
bgneal@106: 
bgneal@106: 						D.bind({
bgneal@106: 							'onCancel.player beforeClose.player' : stop,
bgneal@106: 							'onUpdate.player'   : set,
bgneal@106: 							'beforeLoad.player' : clear
bgneal@106: 						});
bgneal@106: 
bgneal@106: 						set();
bgneal@106: 
bgneal@106: 						F.trigger('onPlayStart');
bgneal@106: 					}
bgneal@106: 				};
bgneal@106: 
bgneal@106: 			if (action === true || (!F.player.isActive && action !== false)) {
bgneal@106: 				start();
bgneal@106: 			} else {
bgneal@106: 				stop();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Navigate to next gallery item
bgneal@106: 		next: function ( direction ) {
bgneal@106: 			var current = F.current;
bgneal@106: 
bgneal@106: 			if (current) {
bgneal@106: 				if (!isString(direction)) {
bgneal@106: 					direction = current.direction.next;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				F.jumpto(current.index + 1, direction, 'next');
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Navigate to previous gallery item
bgneal@106: 		prev: function ( direction ) {
bgneal@106: 			var current = F.current;
bgneal@106: 
bgneal@106: 			if (current) {
bgneal@106: 				if (!isString(direction)) {
bgneal@106: 					direction = current.direction.prev;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				F.jumpto(current.index - 1, direction, 'prev');
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Navigate to gallery item by index
bgneal@106: 		jumpto: function ( index, direction, router ) {
bgneal@106: 			var current = F.current;
bgneal@106: 
bgneal@106: 			if (!current) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			index = getScalar(index);
bgneal@106: 
bgneal@106: 			F.direction = direction || current.direction[ (index >= current.index ? 'next' : 'prev') ];
bgneal@106: 			F.router    = router || 'jumpto';
bgneal@106: 
bgneal@106: 			if (current.loop) {
bgneal@106: 				if (index < 0) {
bgneal@106: 					index = current.group.length + (index % current.group.length);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				index = index % current.group.length;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (current.group[ index ] !== undefined) {
bgneal@106: 				F.cancel();
bgneal@106: 
bgneal@106: 				F._start(index);
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Center inside viewport and toggle position type to fixed or absolute if needed
bgneal@106: 		reposition: function (e, onlyAbsolute) {
bgneal@106: 			var current = F.current,
bgneal@106: 				wrap    = current ? current.wrap : null,
bgneal@106: 				pos;
bgneal@106: 
bgneal@106: 			if (wrap) {
bgneal@106: 				pos = F._getPosition(onlyAbsolute);
bgneal@106: 
bgneal@106: 				if (e && e.type === 'scroll') {
bgneal@106: 					delete pos.position;
bgneal@106: 
bgneal@106: 					wrap.stop(true, true).animate(pos, 200);
bgneal@106: 
bgneal@106: 				} else {
bgneal@106: 					wrap.css(pos);
bgneal@106: 
bgneal@106: 					current.pos = $.extend({}, current.dim, pos);
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		update: function (e) {
bgneal@106: 			var type = (e && e.type),
bgneal@106: 				anyway = !type || type === 'orientationchange';
bgneal@106: 
bgneal@106: 			if (anyway) {
bgneal@106: 				clearTimeout(didUpdate);
bgneal@106: 
bgneal@106: 				didUpdate = null;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!F.isOpen || didUpdate) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			didUpdate = setTimeout(function() {
bgneal@106: 				var current = F.current;
bgneal@106: 
bgneal@106: 				if (!current || F.isClosing) {
bgneal@106: 					return;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				F.wrap.removeClass('fancybox-tmp');
bgneal@106: 
bgneal@106: 				if (anyway || type === 'load' || (type === 'resize' && current.autoResize)) {
bgneal@106: 					F._setDimension();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (!(type === 'scroll' && current.canShrink)) {
bgneal@106: 					F.reposition(e);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				F.trigger('onUpdate');
bgneal@106: 
bgneal@106: 				didUpdate = null;
bgneal@106: 
bgneal@106: 			}, (anyway && !isTouch ? 0 : 300));
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Shrink content to fit inside viewport or restore if resized
bgneal@106: 		toggle: function ( action ) {
bgneal@106: 			if (F.isOpen) {
bgneal@106: 				F.current.fitToView = $.type(action) === "boolean" ? action : !F.current.fitToView;
bgneal@106: 
bgneal@106: 				// Help browser to restore document dimensions
bgneal@106: 				if (isTouch) {
bgneal@106: 					F.wrap.removeAttr('style').addClass('fancybox-tmp');
bgneal@106: 
bgneal@106: 					F.trigger('onUpdate');
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				F.update();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		hideLoading: function () {
bgneal@106: 			D.unbind('.loading');
bgneal@106: 
bgneal@106: 			$('#fancybox-loading').remove();
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		showLoading: function () {
bgneal@106: 			var el, viewport;
bgneal@106: 
bgneal@106: 			F.hideLoading();
bgneal@106: 
bgneal@106: 			el = $('<div id="fancybox-loading"><div></div></div>').click(F.cancel).appendTo('body');
bgneal@106: 
bgneal@106: 			// If user will press the escape-button, the request will be canceled
bgneal@106: 			D.bind('keydown.loading', function(e) {
bgneal@106: 				if ((e.which || e.keyCode) === 27) {
bgneal@106: 					e.preventDefault();
bgneal@106: 
bgneal@106: 					F.cancel();
bgneal@106: 				}
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			if (!F.defaults.fixed) {
bgneal@106: 				viewport = F.getViewport();
bgneal@106: 
bgneal@106: 				el.css({
bgneal@106: 					position : 'absolute',
bgneal@106: 					top  : (viewport.h * 0.5) + viewport.y,
bgneal@106: 					left : (viewport.w * 0.5) + viewport.x
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		getViewport: function () {
bgneal@106: 			var locked = (F.current && F.current.locked) || false,
bgneal@106: 				rez    = {
bgneal@106: 					x: W.scrollLeft(),
bgneal@106: 					y: W.scrollTop()
bgneal@106: 				};
bgneal@106: 
bgneal@106: 			if (locked) {
bgneal@106: 				rez.w = locked[0].clientWidth;
bgneal@106: 				rez.h = locked[0].clientHeight;
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				// See http://bugs.jquery.com/ticket/6724
bgneal@106: 				rez.w = isTouch && window.innerWidth  ? window.innerWidth  : W.width();
bgneal@106: 				rez.h = isTouch && window.innerHeight ? window.innerHeight : W.height();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			return rez;
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Unbind the keyboard / clicking actions
bgneal@106: 		unbindEvents: function () {
bgneal@106: 			if (F.wrap && isQuery(F.wrap)) {
bgneal@106: 				F.wrap.unbind('.fb');
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			D.unbind('.fb');
bgneal@106: 			W.unbind('.fb');
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		bindEvents: function () {
bgneal@106: 			var current = F.current,
bgneal@106: 				keys;
bgneal@106: 
bgneal@106: 			if (!current) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Changing document height on iOS devices triggers a 'resize' event,
bgneal@106: 			// that can change document height... repeating infinitely
bgneal@106: 			W.bind('orientationchange.fb' + (isTouch ? '' : ' resize.fb') + (current.autoCenter && !current.locked ? ' scroll.fb' : ''), F.update);
bgneal@106: 
bgneal@106: 			keys = current.keys;
bgneal@106: 
bgneal@106: 			if (keys) {
bgneal@106: 				D.bind('keydown.fb', function (e) {
bgneal@106: 					var code   = e.which || e.keyCode,
bgneal@106: 						target = e.target || e.srcElement;
bgneal@106: 
bgneal@106: 					// Skip esc key if loading, because showLoading will cancel preloading
bgneal@106: 					if (code === 27 && F.coming) {
bgneal@106: 						return false;
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					// Ignore key combinations and key events within form elements
bgneal@106: 					if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey && !(target && (target.type || $(target).is('[contenteditable]')))) {
bgneal@106: 						$.each(keys, function(i, val) {
bgneal@106: 							if (current.group.length > 1 && val[ code ] !== undefined) {
bgneal@106: 								F[ i ]( val[ code ] );
bgneal@106: 
bgneal@106: 								e.preventDefault();
bgneal@106: 								return false;
bgneal@106: 							}
bgneal@106: 
bgneal@106: 							if ($.inArray(code, val) > -1) {
bgneal@106: 								F[ i ] ();
bgneal@106: 
bgneal@106: 								e.preventDefault();
bgneal@106: 								return false;
bgneal@106: 							}
bgneal@106: 						});
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if ($.fn.mousewheel && current.mouseWheel) {
bgneal@106: 				F.wrap.bind('mousewheel.fb', function (e, delta, deltaX, deltaY) {
bgneal@106: 					var target = e.target || null,
bgneal@106: 						parent = $(target),
bgneal@106: 						canScroll = false;
bgneal@106: 
bgneal@106: 					while (parent.length) {
bgneal@106: 						if (canScroll || parent.is('.fancybox-skin') || parent.is('.fancybox-wrap')) {
bgneal@106: 							break;
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						canScroll = isScrollable( parent[0] );
bgneal@106: 						parent    = $(parent).parent();
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					if (delta !== 0 && !canScroll) {
bgneal@106: 						if (F.group.length > 1 && !current.canShrink) {
bgneal@106: 							if (deltaY > 0 || deltaX > 0) {
bgneal@106: 								F.prev( deltaY > 0 ? 'down' : 'left' );
bgneal@106: 
bgneal@106: 							} else if (deltaY < 0 || deltaX < 0) {
bgneal@106: 								F.next( deltaY < 0 ? 'up' : 'right' );
bgneal@106: 							}
bgneal@106: 
bgneal@106: 							e.preventDefault();
bgneal@106: 						}
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		trigger: function (event, o) {
bgneal@106: 			var ret, obj = o || F.coming || F.current;
bgneal@106: 
bgneal@106: 			if (!obj) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if ($.isFunction( obj[event] )) {
bgneal@106: 				ret = obj[event].apply(obj, Array.prototype.slice.call(arguments, 1));
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (ret === false) {
bgneal@106: 				return false;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (obj.helpers) {
bgneal@106: 				$.each(obj.helpers, function (helper, opts) {
bgneal@106: 					if (opts && F.helpers[helper] && $.isFunction(F.helpers[helper][event])) {
bgneal@106: 						F.helpers[helper][event]($.extend(true, {}, F.helpers[helper].defaults, opts), obj);
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			D.trigger(event);
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		isImage: function (str) {
bgneal@106: 			return isString(str) && str.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i);
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		isSWF: function (str) {
bgneal@106: 			return isString(str) && str.match(/\.(swf)((\?|#).*)?$/i);
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_start: function (index) {
bgneal@106: 			var coming = {},
bgneal@106: 				obj,
bgneal@106: 				href,
bgneal@106: 				type,
bgneal@106: 				margin,
bgneal@106: 				padding;
bgneal@106: 
bgneal@106: 			index = getScalar( index );
bgneal@106: 			obj   = F.group[ index ] || null;
bgneal@106: 
bgneal@106: 			if (!obj) {
bgneal@106: 				return false;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			coming = $.extend(true, {}, F.opts, obj);
bgneal@106: 
bgneal@106: 			// Convert margin and padding properties to array - top, right, bottom, left
bgneal@106: 			margin  = coming.margin;
bgneal@106: 			padding = coming.padding;
bgneal@106: 
bgneal@106: 			if ($.type(margin) === 'number') {
bgneal@106: 				coming.margin = [margin, margin, margin, margin];
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if ($.type(padding) === 'number') {
bgneal@106: 				coming.padding = [padding, padding, padding, padding];
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// 'modal' propery is just a shortcut
bgneal@106: 			if (coming.modal) {
bgneal@106: 				$.extend(true, coming, {
bgneal@106: 					closeBtn   : false,
bgneal@106: 					closeClick : false,
bgneal@106: 					nextClick  : false,
bgneal@106: 					arrows     : false,
bgneal@106: 					mouseWheel : false,
bgneal@106: 					keys       : null,
bgneal@106: 					helpers: {
bgneal@106: 						overlay : {
bgneal@106: 							closeClick : false
bgneal@106: 						}
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// 'autoSize' property is a shortcut, too
bgneal@106: 			if (coming.autoSize) {
bgneal@106: 				coming.autoWidth = coming.autoHeight = true;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (coming.width === 'auto') {
bgneal@106: 				coming.autoWidth = true;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (coming.height === 'auto') {
bgneal@106: 				coming.autoHeight = true;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			/*
bgneal@106: 			 * Add reference to the group, so it`s possible to access from callbacks, example:
bgneal@106: 			 * afterLoad : function() {
bgneal@106: 			 *     this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
bgneal@106: 			 * }
bgneal@106: 			 */
bgneal@106: 
bgneal@106: 			coming.group  = F.group;
bgneal@106: 			coming.index  = index;
bgneal@106: 
bgneal@106: 			// Give a chance for callback or helpers to update coming item (type, title, etc)
bgneal@106: 			F.coming = coming;
bgneal@106: 
bgneal@106: 			if (false === F.trigger('beforeLoad')) {
bgneal@106: 				F.coming = null;
bgneal@106: 
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			type = coming.type;
bgneal@106: 			href = coming.href;
bgneal@106: 
bgneal@106: 			if (!type) {
bgneal@106: 				F.coming = null;
bgneal@106: 
bgneal@106: 				//If we can not determine content type then drop silently or display next/prev item if looping through gallery
bgneal@106: 				if (F.current && F.router && F.router !== 'jumpto') {
bgneal@106: 					F.current.index = index;
bgneal@106: 
bgneal@106: 					return F[ F.router ]( F.direction );
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				return false;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.isActive = true;
bgneal@106: 
bgneal@106: 			if (type === 'image' || type === 'swf') {
bgneal@106: 				coming.autoHeight = coming.autoWidth = false;
bgneal@106: 				coming.scrolling  = 'visible';
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (type === 'image') {
bgneal@106: 				coming.aspectRatio = true;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (type === 'iframe' && isTouch) {
bgneal@106: 				coming.scrolling = 'scroll';
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Build the neccessary markup
bgneal@106: 			coming.wrap = $(coming.tpl.wrap).addClass('fancybox-' + (isTouch ? 'mobile' : 'desktop') + ' fancybox-type-' + type + ' fancybox-tmp ' + coming.wrapCSS).appendTo( coming.parent || 'body' );
bgneal@106: 
bgneal@106: 			$.extend(coming, {
bgneal@106: 				skin  : $('.fancybox-skin',  coming.wrap),
bgneal@106: 				outer : $('.fancybox-outer', coming.wrap),
bgneal@106: 				inner : $('.fancybox-inner', coming.wrap)
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			$.each(["Top", "Right", "Bottom", "Left"], function(i, v) {
bgneal@106: 				coming.skin.css('padding' + v, getValue(coming.padding[ i ]));
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			F.trigger('onReady');
bgneal@106: 
bgneal@106: 			// Check before try to load; 'inline' and 'html' types need content, others - href
bgneal@106: 			if (type === 'inline' || type === 'html') {
bgneal@106: 				if (!coming.content || !coming.content.length) {
bgneal@106: 					return F._error( 'content' );
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else if (!href) {
bgneal@106: 				return F._error( 'href' );
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (type === 'image') {
bgneal@106: 				F._loadImage();
bgneal@106: 
bgneal@106: 			} else if (type === 'ajax') {
bgneal@106: 				F._loadAjax();
bgneal@106: 
bgneal@106: 			} else if (type === 'iframe') {
bgneal@106: 				F._loadIframe();
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				F._afterLoad();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_error: function ( type ) {
bgneal@106: 			$.extend(F.coming, {
bgneal@106: 				type       : 'html',
bgneal@106: 				autoWidth  : true,
bgneal@106: 				autoHeight : true,
bgneal@106: 				minWidth   : 0,
bgneal@106: 				minHeight  : 0,
bgneal@106: 				scrolling  : 'no',
bgneal@106: 				hasError   : type,
bgneal@106: 				content    : F.coming.tpl.error
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			F._afterLoad();
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_loadImage: function () {
bgneal@106: 			// Reset preload image so it is later possible to check "complete" property
bgneal@106: 			var img = F.imgPreload = new Image();
bgneal@106: 
bgneal@106: 			img.onload = function () {
bgneal@106: 				this.onload = this.onerror = null;
bgneal@106: 
bgneal@106: 				F.coming.width  = this.width / F.opts.pixelRatio;
bgneal@106: 				F.coming.height = this.height / F.opts.pixelRatio;
bgneal@106: 
bgneal@106: 				F._afterLoad();
bgneal@106: 			};
bgneal@106: 
bgneal@106: 			img.onerror = function () {
bgneal@106: 				this.onload = this.onerror = null;
bgneal@106: 
bgneal@106: 				F._error( 'image' );
bgneal@106: 			};
bgneal@106: 
bgneal@106: 			img.src = F.coming.href;
bgneal@106: 
bgneal@106: 			if (img.complete !== true) {
bgneal@106: 				F.showLoading();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_loadAjax: function () {
bgneal@106: 			var coming = F.coming;
bgneal@106: 
bgneal@106: 			F.showLoading();
bgneal@106: 
bgneal@106: 			F.ajaxLoad = $.ajax($.extend({}, coming.ajax, {
bgneal@106: 				url: coming.href,
bgneal@106: 				error: function (jqXHR, textStatus) {
bgneal@106: 					if (F.coming && textStatus !== 'abort') {
bgneal@106: 						F._error( 'ajax', jqXHR );
bgneal@106: 
bgneal@106: 					} else {
bgneal@106: 						F.hideLoading();
bgneal@106: 					}
bgneal@106: 				},
bgneal@106: 				success: function (data, textStatus) {
bgneal@106: 					if (textStatus === 'success') {
bgneal@106: 						coming.content = data;
bgneal@106: 
bgneal@106: 						F._afterLoad();
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 			}));
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_loadIframe: function() {
bgneal@106: 			var coming = F.coming,
bgneal@106: 				iframe = $(coming.tpl.iframe.replace(/\{rnd\}/g, new Date().getTime()))
bgneal@106: 					.attr('scrolling', isTouch ? 'auto' : coming.iframe.scrolling)
bgneal@106: 					.attr('src', coming.href);
bgneal@106: 
bgneal@106: 			// This helps IE
bgneal@106: 			$(coming.wrap).bind('onReset', function () {
bgneal@106: 				try {
bgneal@106: 					$(this).find('iframe').hide().attr('src', '//about:blank').end().empty();
bgneal@106: 				} catch (e) {}
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			if (coming.iframe.preload) {
bgneal@106: 				F.showLoading();
bgneal@106: 
bgneal@106: 				iframe.one('load', function() {
bgneal@106: 					$(this).data('ready', 1);
bgneal@106: 
bgneal@106: 					// iOS will lose scrolling if we resize
bgneal@106: 					if (!isTouch) {
bgneal@106: 						$(this).bind('load.fb', F.update);
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					// Without this trick:
bgneal@106: 					//   - iframe won't scroll on iOS devices
bgneal@106: 					//   - IE7 sometimes displays empty iframe
bgneal@106: 					$(this).parents('.fancybox-wrap').width('100%').removeClass('fancybox-tmp').show();
bgneal@106: 
bgneal@106: 					F._afterLoad();
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			coming.content = iframe.appendTo( coming.inner );
bgneal@106: 
bgneal@106: 			if (!coming.iframe.preload) {
bgneal@106: 				F._afterLoad();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_preloadImages: function() {
bgneal@106: 			var group   = F.group,
bgneal@106: 				current = F.current,
bgneal@106: 				len     = group.length,
bgneal@106: 				cnt     = current.preload ? Math.min(current.preload, len - 1) : 0,
bgneal@106: 				item,
bgneal@106: 				i;
bgneal@106: 
bgneal@106: 			for (i = 1; i <= cnt; i += 1) {
bgneal@106: 				item = group[ (current.index + i ) % len ];
bgneal@106: 
bgneal@106: 				if (item.type === 'image' && item.href) {
bgneal@106: 					new Image().src = item.href;
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_afterLoad: function () {
bgneal@106: 			var coming   = F.coming,
bgneal@106: 				previous = F.current,
bgneal@106: 				placeholder = 'fancybox-placeholder',
bgneal@106: 				current,
bgneal@106: 				content,
bgneal@106: 				type,
bgneal@106: 				scrolling,
bgneal@106: 				href,
bgneal@106: 				embed;
bgneal@106: 
bgneal@106: 			F.hideLoading();
bgneal@106: 
bgneal@106: 			if (!coming || F.isActive === false) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (false === F.trigger('afterLoad', coming, previous)) {
bgneal@106: 				coming.wrap.stop(true).trigger('onReset').remove();
bgneal@106: 
bgneal@106: 				F.coming = null;
bgneal@106: 
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (previous) {
bgneal@106: 				F.trigger('beforeChange', previous);
bgneal@106: 
bgneal@106: 				previous.wrap.stop(true).removeClass('fancybox-opened')
bgneal@106: 					.find('.fancybox-item, .fancybox-nav')
bgneal@106: 					.remove();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.unbindEvents();
bgneal@106: 
bgneal@106: 			current   = coming;
bgneal@106: 			content   = coming.content;
bgneal@106: 			type      = coming.type;
bgneal@106: 			scrolling = coming.scrolling;
bgneal@106: 
bgneal@106: 			$.extend(F, {
bgneal@106: 				wrap  : current.wrap,
bgneal@106: 				skin  : current.skin,
bgneal@106: 				outer : current.outer,
bgneal@106: 				inner : current.inner,
bgneal@106: 				current  : current,
bgneal@106: 				previous : previous
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			href = current.href;
bgneal@106: 
bgneal@106: 			switch (type) {
bgneal@106: 				case 'inline':
bgneal@106: 				case 'ajax':
bgneal@106: 				case 'html':
bgneal@106: 					if (current.selector) {
bgneal@106: 						content = $('<div>').html(content).find(current.selector);
bgneal@106: 
bgneal@106: 					} else if (isQuery(content)) {
bgneal@106: 						if (!content.data(placeholder)) {
bgneal@106: 							content.data(placeholder, $('<div class="' + placeholder + '"></div>').insertAfter( content ).hide() );
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						content = content.show().detach();
bgneal@106: 
bgneal@106: 						current.wrap.bind('onReset', function () {
bgneal@106: 							if ($(this).find(content).length) {
bgneal@106: 								content.hide().replaceAll( content.data(placeholder) ).data(placeholder, false);
bgneal@106: 							}
bgneal@106: 						});
bgneal@106: 					}
bgneal@106: 				break;
bgneal@106: 
bgneal@106: 				case 'image':
bgneal@106: 					content = current.tpl.image.replace('{href}', href);
bgneal@106: 				break;
bgneal@106: 
bgneal@106: 				case 'swf':
bgneal@106: 					content = '<object id="fancybox-swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"><param name="movie" value="' + href + '"></param>';
bgneal@106: 					embed   = '';
bgneal@106: 
bgneal@106: 					$.each(current.swf, function(name, val) {
bgneal@106: 						content += '<param name="' + name + '" value="' + val + '"></param>';
bgneal@106: 						embed   += ' ' + name + '="' + val + '"';
bgneal@106: 					});
bgneal@106: 
bgneal@106: 					content += '<embed src="' + href + '" type="application/x-shockwave-flash" width="100%" height="100%"' + embed + '></embed></object>';
bgneal@106: 				break;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!(isQuery(content) && content.parent().is(current.inner))) {
bgneal@106: 				current.inner.append( content );
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Give a chance for helpers or callbacks to update elements
bgneal@106: 			F.trigger('beforeShow');
bgneal@106: 
bgneal@106: 			// Set scrolling before calculating dimensions
bgneal@106: 			current.inner.css('overflow', scrolling === 'yes' ? 'scroll' : (scrolling === 'no' ? 'hidden' : scrolling));
bgneal@106: 
bgneal@106: 			// Set initial dimensions and start position
bgneal@106: 			F._setDimension();
bgneal@106: 
bgneal@106: 			F.reposition();
bgneal@106: 
bgneal@106: 			F.isOpen = false;
bgneal@106: 			F.coming = null;
bgneal@106: 
bgneal@106: 			F.bindEvents();
bgneal@106: 
bgneal@106: 			if (!F.isOpened) {
bgneal@106: 				$('.fancybox-wrap').not( current.wrap ).stop(true).trigger('onReset').remove();
bgneal@106: 
bgneal@106: 			} else if (previous.prevMethod) {
bgneal@106: 				F.transitions[ previous.prevMethod ]();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.transitions[ F.isOpened ? current.nextMethod : current.openMethod ]();
bgneal@106: 
bgneal@106: 			F._preloadImages();
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_setDimension: function () {
bgneal@106: 			var viewport   = F.getViewport(),
bgneal@106: 				steps      = 0,
bgneal@106: 				canShrink  = false,
bgneal@106: 				canExpand  = false,
bgneal@106: 				wrap       = F.wrap,
bgneal@106: 				skin       = F.skin,
bgneal@106: 				inner      = F.inner,
bgneal@106: 				current    = F.current,
bgneal@106: 				width      = current.width,
bgneal@106: 				height     = current.height,
bgneal@106: 				minWidth   = current.minWidth,
bgneal@106: 				minHeight  = current.minHeight,
bgneal@106: 				maxWidth   = current.maxWidth,
bgneal@106: 				maxHeight  = current.maxHeight,
bgneal@106: 				scrolling  = current.scrolling,
bgneal@106: 				scrollOut  = current.scrollOutside ? current.scrollbarWidth : 0,
bgneal@106: 				margin     = current.margin,
bgneal@106: 				wMargin    = getScalar(margin[1] + margin[3]),
bgneal@106: 				hMargin    = getScalar(margin[0] + margin[2]),
bgneal@106: 				wPadding,
bgneal@106: 				hPadding,
bgneal@106: 				wSpace,
bgneal@106: 				hSpace,
bgneal@106: 				origWidth,
bgneal@106: 				origHeight,
bgneal@106: 				origMaxWidth,
bgneal@106: 				origMaxHeight,
bgneal@106: 				ratio,
bgneal@106: 				width_,
bgneal@106: 				height_,
bgneal@106: 				maxWidth_,
bgneal@106: 				maxHeight_,
bgneal@106: 				iframe,
bgneal@106: 				body;
bgneal@106: 
bgneal@106: 			// Reset dimensions so we could re-check actual size
bgneal@106: 			wrap.add(skin).add(inner).width('auto').height('auto').removeClass('fancybox-tmp');
bgneal@106: 
bgneal@106: 			wPadding = getScalar(skin.outerWidth(true)  - skin.width());
bgneal@106: 			hPadding = getScalar(skin.outerHeight(true) - skin.height());
bgneal@106: 
bgneal@106: 			// Any space between content and viewport (margin, padding, border, title)
bgneal@106: 			wSpace = wMargin + wPadding;
bgneal@106: 			hSpace = hMargin + hPadding;
bgneal@106: 
bgneal@106: 			origWidth  = isPercentage(width)  ? (viewport.w - wSpace) * getScalar(width)  / 100 : width;
bgneal@106: 			origHeight = isPercentage(height) ? (viewport.h - hSpace) * getScalar(height) / 100 : height;
bgneal@106: 
bgneal@106: 			if (current.type === 'iframe') {
bgneal@106: 				iframe = current.content;
bgneal@106: 
bgneal@106: 				if (current.autoHeight && iframe.data('ready') === 1) {
bgneal@106: 					try {
bgneal@106: 						if (iframe[0].contentWindow.document.location) {
bgneal@106: 							inner.width( origWidth ).height(9999);
bgneal@106: 
bgneal@106: 							body = iframe.contents().find('body');
bgneal@106: 
bgneal@106: 							if (scrollOut) {
bgneal@106: 								body.css('overflow-x', 'hidden');
bgneal@106: 							}
bgneal@106: 
bgneal@106: 							origHeight = body.outerHeight(true);
bgneal@106: 						}
bgneal@106: 
bgneal@106: 					} catch (e) {}
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else if (current.autoWidth || current.autoHeight) {
bgneal@106: 				inner.addClass( 'fancybox-tmp' );
bgneal@106: 
bgneal@106: 				// Set width or height in case we need to calculate only one dimension
bgneal@106: 				if (!current.autoWidth) {
bgneal@106: 					inner.width( origWidth );
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (!current.autoHeight) {
bgneal@106: 					inner.height( origHeight );
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (current.autoWidth) {
bgneal@106: 					origWidth = inner.width();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (current.autoHeight) {
bgneal@106: 					origHeight = inner.height();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				inner.removeClass( 'fancybox-tmp' );
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			width  = getScalar( origWidth );
bgneal@106: 			height = getScalar( origHeight );
bgneal@106: 
bgneal@106: 			ratio  = origWidth / origHeight;
bgneal@106: 
bgneal@106: 			// Calculations for the content
bgneal@106: 			minWidth  = getScalar(isPercentage(minWidth) ? getScalar(minWidth, 'w') - wSpace : minWidth);
bgneal@106: 			maxWidth  = getScalar(isPercentage(maxWidth) ? getScalar(maxWidth, 'w') - wSpace : maxWidth);
bgneal@106: 
bgneal@106: 			minHeight = getScalar(isPercentage(minHeight) ? getScalar(minHeight, 'h') - hSpace : minHeight);
bgneal@106: 			maxHeight = getScalar(isPercentage(maxHeight) ? getScalar(maxHeight, 'h') - hSpace : maxHeight);
bgneal@106: 
bgneal@106: 			// These will be used to determine if wrap can fit in the viewport
bgneal@106: 			origMaxWidth  = maxWidth;
bgneal@106: 			origMaxHeight = maxHeight;
bgneal@106: 
bgneal@106: 			if (current.fitToView) {
bgneal@106: 				maxWidth  = Math.min(viewport.w - wSpace, maxWidth);
bgneal@106: 				maxHeight = Math.min(viewport.h - hSpace, maxHeight);
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			maxWidth_  = viewport.w - wMargin;
bgneal@106: 			maxHeight_ = viewport.h - hMargin;
bgneal@106: 
bgneal@106: 			if (current.aspectRatio) {
bgneal@106: 				if (width > maxWidth) {
bgneal@106: 					width  = maxWidth;
bgneal@106: 					height = getScalar(width / ratio);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (height > maxHeight) {
bgneal@106: 					height = maxHeight;
bgneal@106: 					width  = getScalar(height * ratio);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (width < minWidth) {
bgneal@106: 					width  = minWidth;
bgneal@106: 					height = getScalar(width / ratio);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (height < minHeight) {
bgneal@106: 					height = minHeight;
bgneal@106: 					width  = getScalar(height * ratio);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				width = Math.max(minWidth, Math.min(width, maxWidth));
bgneal@106: 
bgneal@106: 				if (current.autoHeight && current.type !== 'iframe') {
bgneal@106: 					inner.width( width );
bgneal@106: 
bgneal@106: 					height = inner.height();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				height = Math.max(minHeight, Math.min(height, maxHeight));
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Try to fit inside viewport (including the title)
bgneal@106: 			if (current.fitToView) {
bgneal@106: 				inner.width( width ).height( height );
bgneal@106: 
bgneal@106: 				wrap.width( width + wPadding );
bgneal@106: 
bgneal@106: 				// Real wrap dimensions
bgneal@106: 				width_  = wrap.width();
bgneal@106: 				height_ = wrap.height();
bgneal@106: 
bgneal@106: 				if (current.aspectRatio) {
bgneal@106: 					while ((width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight) {
bgneal@106: 						if (steps++ > 19) {
bgneal@106: 							break;
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						height = Math.max(minHeight, Math.min(maxHeight, height - 10));
bgneal@106: 						width  = getScalar(height * ratio);
bgneal@106: 
bgneal@106: 						if (width < minWidth) {
bgneal@106: 							width  = minWidth;
bgneal@106: 							height = getScalar(width / ratio);
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						if (width > maxWidth) {
bgneal@106: 							width  = maxWidth;
bgneal@106: 							height = getScalar(width / ratio);
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						inner.width( width ).height( height );
bgneal@106: 
bgneal@106: 						wrap.width( width + wPadding );
bgneal@106: 
bgneal@106: 						width_  = wrap.width();
bgneal@106: 						height_ = wrap.height();
bgneal@106: 					}
bgneal@106: 
bgneal@106: 				} else {
bgneal@106: 					width  = Math.max(minWidth,  Math.min(width,  width  - (width_  - maxWidth_)));
bgneal@106: 					height = Math.max(minHeight, Math.min(height, height - (height_ - maxHeight_)));
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (scrollOut && scrolling === 'auto' && height < origHeight && (width + wPadding + scrollOut) < maxWidth_) {
bgneal@106: 				width += scrollOut;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			inner.width( width ).height( height );
bgneal@106: 
bgneal@106: 			wrap.width( width + wPadding );
bgneal@106: 
bgneal@106: 			width_  = wrap.width();
bgneal@106: 			height_ = wrap.height();
bgneal@106: 
bgneal@106: 			canShrink = (width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight;
bgneal@106: 			canExpand = current.aspectRatio ? (width < origMaxWidth && height < origMaxHeight && width < origWidth && height < origHeight) : ((width < origMaxWidth || height < origMaxHeight) && (width < origWidth || height < origHeight));
bgneal@106: 
bgneal@106: 			$.extend(current, {
bgneal@106: 				dim : {
bgneal@106: 					width	: getValue( width_ ),
bgneal@106: 					height	: getValue( height_ )
bgneal@106: 				},
bgneal@106: 				origWidth  : origWidth,
bgneal@106: 				origHeight : origHeight,
bgneal@106: 				canShrink  : canShrink,
bgneal@106: 				canExpand  : canExpand,
bgneal@106: 				wPadding   : wPadding,
bgneal@106: 				hPadding   : hPadding,
bgneal@106: 				wrapSpace  : height_ - skin.outerHeight(true),
bgneal@106: 				skinSpace  : skin.height() - height
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			if (!iframe && current.autoHeight && height > minHeight && height < maxHeight && !canExpand) {
bgneal@106: 				inner.height('auto');
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_getPosition: function (onlyAbsolute) {
bgneal@106: 			var current  = F.current,
bgneal@106: 				viewport = F.getViewport(),
bgneal@106: 				margin   = current.margin,
bgneal@106: 				width    = F.wrap.width()  + margin[1] + margin[3],
bgneal@106: 				height   = F.wrap.height() + margin[0] + margin[2],
bgneal@106: 				rez      = {
bgneal@106: 					position: 'absolute',
bgneal@106: 					top  : margin[0],
bgneal@106: 					left : margin[3]
bgneal@106: 				};
bgneal@106: 
bgneal@106: 			if (current.autoCenter && current.fixed && !onlyAbsolute && height <= viewport.h && width <= viewport.w) {
bgneal@106: 				rez.position = 'fixed';
bgneal@106: 
bgneal@106: 			} else if (!current.locked) {
bgneal@106: 				rez.top  += viewport.y;
bgneal@106: 				rez.left += viewport.x;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			rez.top  = getValue(Math.max(rez.top,  rez.top  + ((viewport.h - height) * current.topRatio)));
bgneal@106: 			rez.left = getValue(Math.max(rez.left, rez.left + ((viewport.w - width)  * current.leftRatio)));
bgneal@106: 
bgneal@106: 			return rez;
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_afterZoomIn: function () {
bgneal@106: 			var current = F.current;
bgneal@106: 
bgneal@106: 			if (!current) {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.isOpen = F.isOpened = true;
bgneal@106: 
bgneal@106: 			F.wrap.css('overflow', 'visible').addClass('fancybox-opened');
bgneal@106: 
bgneal@106: 			F.update();
bgneal@106: 
bgneal@106: 			// Assign a click event
bgneal@106: 			if ( current.closeClick || (current.nextClick && F.group.length > 1) ) {
bgneal@106: 				F.inner.css('cursor', 'pointer').bind('click.fb', function(e) {
bgneal@106: 					if (!$(e.target).is('a') && !$(e.target).parent().is('a')) {
bgneal@106: 						e.preventDefault();
bgneal@106: 
bgneal@106: 						F[ current.closeClick ? 'close' : 'next' ]();
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Create a close button
bgneal@106: 			if (current.closeBtn) {
bgneal@106: 				$(current.tpl.closeBtn).appendTo(F.skin).bind('click.fb', function(e) {
bgneal@106: 					e.preventDefault();
bgneal@106: 
bgneal@106: 					F.close();
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Create navigation arrows
bgneal@106: 			if (current.arrows && F.group.length > 1) {
bgneal@106: 				if (current.loop || current.index > 0) {
bgneal@106: 					$(current.tpl.prev).appendTo(F.outer).bind('click.fb', F.prev);
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				if (current.loop || current.index < F.group.length - 1) {
bgneal@106: 					$(current.tpl.next).appendTo(F.outer).bind('click.fb', F.next);
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.trigger('afterShow');
bgneal@106: 
bgneal@106: 			// Stop the slideshow if this is the last item
bgneal@106: 			if (!current.loop && current.index === current.group.length - 1) {
bgneal@106: 				F.play( false );
bgneal@106: 
bgneal@106: 			} else if (F.opts.autoPlay && !F.player.isActive) {
bgneal@106: 				F.opts.autoPlay = false;
bgneal@106: 
bgneal@106: 				F.play();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		_afterZoomOut: function ( obj ) {
bgneal@106: 			obj = obj || F.current;
bgneal@106: 
bgneal@106: 			$('.fancybox-wrap').trigger('onReset').remove();
bgneal@106: 
bgneal@106: 			$.extend(F, {
bgneal@106: 				group  : {},
bgneal@106: 				opts   : {},
bgneal@106: 				router : false,
bgneal@106: 				current   : null,
bgneal@106: 				isActive  : false,
bgneal@106: 				isOpened  : false,
bgneal@106: 				isOpen    : false,
bgneal@106: 				isClosing : false,
bgneal@106: 				wrap   : null,
bgneal@106: 				skin   : null,
bgneal@106: 				outer  : null,
bgneal@106: 				inner  : null
bgneal@106: 			});
bgneal@106: 
bgneal@106: 			F.trigger('afterClose', obj);
bgneal@106: 		}
bgneal@106: 	});
bgneal@106: 
bgneal@106: 	/*
bgneal@106: 	 *	Default transitions
bgneal@106: 	 */
bgneal@106: 
bgneal@106: 	F.transitions = {
bgneal@106: 		getOrigPosition: function () {
bgneal@106: 			var current  = F.current,
bgneal@106: 				element  = current.element,
bgneal@106: 				orig     = current.orig,
bgneal@106: 				pos      = {},
bgneal@106: 				width    = 50,
bgneal@106: 				height   = 50,
bgneal@106: 				hPadding = current.hPadding,
bgneal@106: 				wPadding = current.wPadding,
bgneal@106: 				viewport = F.getViewport();
bgneal@106: 
bgneal@106: 			if (!orig && current.isDom && element.is(':visible')) {
bgneal@106: 				orig = element.find('img:first');
bgneal@106: 
bgneal@106: 				if (!orig.length) {
bgneal@106: 					orig = element;
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (isQuery(orig)) {
bgneal@106: 				pos = orig.offset();
bgneal@106: 
bgneal@106: 				if (orig.is('img')) {
bgneal@106: 					width  = orig.outerWidth();
bgneal@106: 					height = orig.outerHeight();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				pos.top  = viewport.y + (viewport.h - height) * current.topRatio;
bgneal@106: 				pos.left = viewport.x + (viewport.w - width)  * current.leftRatio;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (F.wrap.css('position') === 'fixed' || current.locked) {
bgneal@106: 				pos.top  -= viewport.y;
bgneal@106: 				pos.left -= viewport.x;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			pos = {
bgneal@106: 				top     : getValue(pos.top  - hPadding * current.topRatio),
bgneal@106: 				left    : getValue(pos.left - wPadding * current.leftRatio),
bgneal@106: 				width   : getValue(width  + wPadding),
bgneal@106: 				height  : getValue(height + hPadding)
bgneal@106: 			};
bgneal@106: 
bgneal@106: 			return pos;
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		step: function (now, fx) {
bgneal@106: 			var ratio,
bgneal@106: 				padding,
bgneal@106: 				value,
bgneal@106: 				prop       = fx.prop,
bgneal@106: 				current    = F.current,
bgneal@106: 				wrapSpace  = current.wrapSpace,
bgneal@106: 				skinSpace  = current.skinSpace;
bgneal@106: 
bgneal@106: 			if (prop === 'width' || prop === 'height') {
bgneal@106: 				ratio = fx.end === fx.start ? 1 : (now - fx.start) / (fx.end - fx.start);
bgneal@106: 
bgneal@106: 				if (F.isClosing) {
bgneal@106: 					ratio = 1 - ratio;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				padding = prop === 'width' ? current.wPadding : current.hPadding;
bgneal@106: 				value   = now - padding;
bgneal@106: 
bgneal@106: 				F.skin[ prop ](  getScalar( prop === 'width' ?  value : value - (wrapSpace * ratio) ) );
bgneal@106: 				F.inner[ prop ]( getScalar( prop === 'width' ?  value : value - (wrapSpace * ratio) - (skinSpace * ratio) ) );
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		zoomIn: function () {
bgneal@106: 			var current  = F.current,
bgneal@106: 				startPos = current.pos,
bgneal@106: 				effect   = current.openEffect,
bgneal@106: 				elastic  = effect === 'elastic',
bgneal@106: 				endPos   = $.extend({opacity : 1}, startPos);
bgneal@106: 
bgneal@106: 			// Remove "position" property that breaks older IE
bgneal@106: 			delete endPos.position;
bgneal@106: 
bgneal@106: 			if (elastic) {
bgneal@106: 				startPos = this.getOrigPosition();
bgneal@106: 
bgneal@106: 				if (current.openOpacity) {
bgneal@106: 					startPos.opacity = 0.1;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else if (effect === 'fade') {
bgneal@106: 				startPos.opacity = 0.1;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.wrap.css(startPos).animate(endPos, {
bgneal@106: 				duration : effect === 'none' ? 0 : current.openSpeed,
bgneal@106: 				easing   : current.openEasing,
bgneal@106: 				step     : elastic ? this.step : null,
bgneal@106: 				complete : F._afterZoomIn
bgneal@106: 			});
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		zoomOut: function () {
bgneal@106: 			var current  = F.current,
bgneal@106: 				effect   = current.closeEffect,
bgneal@106: 				elastic  = effect === 'elastic',
bgneal@106: 				endPos   = {opacity : 0.1};
bgneal@106: 
bgneal@106: 			if (elastic) {
bgneal@106: 				endPos = this.getOrigPosition();
bgneal@106: 
bgneal@106: 				if (current.closeOpacity) {
bgneal@106: 					endPos.opacity = 0.1;
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			F.wrap.animate(endPos, {
bgneal@106: 				duration : effect === 'none' ? 0 : current.closeSpeed,
bgneal@106: 				easing   : current.closeEasing,
bgneal@106: 				step     : elastic ? this.step : null,
bgneal@106: 				complete : F._afterZoomOut
bgneal@106: 			});
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		changeIn: function () {
bgneal@106: 			var current   = F.current,
bgneal@106: 				effect    = current.nextEffect,
bgneal@106: 				startPos  = current.pos,
bgneal@106: 				endPos    = { opacity : 1 },
bgneal@106: 				direction = F.direction,
bgneal@106: 				distance  = 200,
bgneal@106: 				field;
bgneal@106: 
bgneal@106: 			startPos.opacity = 0.1;
bgneal@106: 
bgneal@106: 			if (effect === 'elastic') {
bgneal@106: 				field = direction === 'down' || direction === 'up' ? 'top' : 'left';
bgneal@106: 
bgneal@106: 				if (direction === 'down' || direction === 'right') {
bgneal@106: 					startPos[ field ] = getValue(getScalar(startPos[ field ]) - distance);
bgneal@106: 					endPos[ field ]   = '+=' + distance + 'px';
bgneal@106: 
bgneal@106: 				} else {
bgneal@106: 					startPos[ field ] = getValue(getScalar(startPos[ field ]) + distance);
bgneal@106: 					endPos[ field ]   = '-=' + distance + 'px';
bgneal@106: 				}
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			// Workaround for http://bugs.jquery.com/ticket/12273
bgneal@106: 			if (effect === 'none') {
bgneal@106: 				F._afterZoomIn();
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				F.wrap.css(startPos).animate(endPos, {
bgneal@106: 					duration : current.nextSpeed,
bgneal@106: 					easing   : current.nextEasing,
bgneal@106: 					complete : F._afterZoomIn
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		changeOut: function () {
bgneal@106: 			var previous  = F.previous,
bgneal@106: 				effect    = previous.prevEffect,
bgneal@106: 				endPos    = { opacity : 0.1 },
bgneal@106: 				direction = F.direction,
bgneal@106: 				distance  = 200;
bgneal@106: 
bgneal@106: 			if (effect === 'elastic') {
bgneal@106: 				endPos[ direction === 'down' || direction === 'up' ? 'top' : 'left' ] = ( direction === 'up' || direction === 'left' ? '-' : '+' ) + '=' + distance + 'px';
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			previous.wrap.animate(endPos, {
bgneal@106: 				duration : effect === 'none' ? 0 : previous.prevSpeed,
bgneal@106: 				easing   : previous.prevEasing,
bgneal@106: 				complete : function () {
bgneal@106: 					$(this).trigger('onReset').remove();
bgneal@106: 				}
bgneal@106: 			});
bgneal@106: 		}
bgneal@106: 	};
bgneal@106: 
bgneal@106: 	/*
bgneal@106: 	 *	Overlay helper
bgneal@106: 	 */
bgneal@106: 
bgneal@106: 	F.helpers.overlay = {
bgneal@106: 		defaults : {
bgneal@106: 			closeClick : true,      // if true, fancyBox will be closed when user clicks on the overlay
bgneal@106: 			speedOut   : 200,       // duration of fadeOut animation
bgneal@106: 			showEarly  : true,      // indicates if should be opened immediately or wait until the content is ready
bgneal@106: 			css        : {},        // custom CSS properties
bgneal@106: 			locked     : !isTouch,  // if true, the content will be locked into overlay
bgneal@106: 			fixed      : true       // if false, the overlay CSS position property will not be set to "fixed"
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		overlay : null,      // current handle
bgneal@106: 		fixed   : false,     // indicates if the overlay has position "fixed"
bgneal@106: 		el      : $('html'), // element that contains "the lock"
bgneal@106: 
bgneal@106: 		// Public methods
bgneal@106: 		create : function(opts) {
bgneal@106: 			opts = $.extend({}, this.defaults, opts);
bgneal@106: 
bgneal@106: 			if (this.overlay) {
bgneal@106: 				this.close();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			this.overlay = $('<div class="fancybox-overlay"></div>').appendTo( F.coming ? F.coming.parent : opts.parent );
bgneal@106: 			this.fixed   = false;
bgneal@106: 
bgneal@106: 			if (opts.fixed && F.defaults.fixed) {
bgneal@106: 				this.overlay.addClass('fancybox-overlay-fixed');
bgneal@106: 
bgneal@106: 				this.fixed = true;
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		open : function(opts) {
bgneal@106: 			var that = this;
bgneal@106: 
bgneal@106: 			opts = $.extend({}, this.defaults, opts);
bgneal@106: 
bgneal@106: 			if (this.overlay) {
bgneal@106: 				this.overlay.unbind('.overlay').width('auto').height('auto');
bgneal@106: 
bgneal@106: 			} else {
bgneal@106: 				this.create(opts);
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!this.fixed) {
bgneal@106: 				W.bind('resize.overlay', $.proxy( this.update, this) );
bgneal@106: 
bgneal@106: 				this.update();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (opts.closeClick) {
bgneal@106: 				this.overlay.bind('click.overlay', function(e) {
bgneal@106: 					if ($(e.target).hasClass('fancybox-overlay')) {
bgneal@106: 						if (F.isActive) {
bgneal@106: 							F.close();
bgneal@106: 						} else {
bgneal@106: 							that.close();
bgneal@106: 						}
bgneal@106: 
bgneal@106: 						return false;
bgneal@106: 					}
bgneal@106: 				});
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			this.overlay.css( opts.css ).show();
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		close : function() {
bgneal@106: 			var scrollV, scrollH;
bgneal@106: 
bgneal@106: 			W.unbind('resize.overlay');
bgneal@106: 
bgneal@106: 			if (this.el.hasClass('fancybox-lock')) {
bgneal@106: 				$('.fancybox-margin').removeClass('fancybox-margin');
bgneal@106: 
bgneal@106: 				scrollV = W.scrollTop();
bgneal@106: 				scrollH = W.scrollLeft();
bgneal@106: 
bgneal@106: 				this.el.removeClass('fancybox-lock');
bgneal@106: 
bgneal@106: 				W.scrollTop( scrollV ).scrollLeft( scrollH );
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			$('.fancybox-overlay').remove().hide();
bgneal@106: 
bgneal@106: 			$.extend(this, {
bgneal@106: 				overlay : null,
bgneal@106: 				fixed   : false
bgneal@106: 			});
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// Private, callbacks
bgneal@106: 
bgneal@106: 		update : function () {
bgneal@106: 			var width = '100%', offsetWidth;
bgneal@106: 
bgneal@106: 			// Reset width/height so it will not mess
bgneal@106: 			this.overlay.width(width).height('100%');
bgneal@106: 
bgneal@106: 			// jQuery does not return reliable result for IE
bgneal@106: 			if (IE) {
bgneal@106: 				offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);
bgneal@106: 
bgneal@106: 				if (D.width() > offsetWidth) {
bgneal@106: 					width = D.width();
bgneal@106: 				}
bgneal@106: 
bgneal@106: 			} else if (D.width() > W.width()) {
bgneal@106: 				width = D.width();
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			this.overlay.width(width).height(D.height());
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		// This is where we can manipulate DOM, because later it would cause iframes to reload
bgneal@106: 		onReady : function (opts, obj) {
bgneal@106: 			var overlay = this.overlay;
bgneal@106: 
bgneal@106: 			$('.fancybox-overlay').stop(true, true);
bgneal@106: 
bgneal@106: 			if (!overlay) {
bgneal@106: 				this.create(opts);
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (opts.locked && this.fixed && obj.fixed) {
bgneal@106: 				if (!overlay) {
bgneal@106: 					this.margin = D.height() > W.height() ? $('html').css('margin-right').replace("px", "") : false;
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				obj.locked = this.overlay.append( obj.wrap );
bgneal@106: 				obj.fixed  = false;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (opts.showEarly === true) {
bgneal@106: 				this.beforeShow.apply(this, arguments);
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		beforeShow : function(opts, obj) {
bgneal@106: 			var scrollV, scrollH;
bgneal@106: 
bgneal@106: 			if (obj.locked) {
bgneal@106: 				if (this.margin !== false) {
bgneal@106: 					$('*').filter(function(){
bgneal@106: 						return ($(this).css('position') === 'fixed' && !$(this).hasClass("fancybox-overlay") && !$(this).hasClass("fancybox-wrap") );
bgneal@106: 					}).addClass('fancybox-margin');
bgneal@106: 
bgneal@106: 					this.el.addClass('fancybox-margin');
bgneal@106: 				}
bgneal@106: 
bgneal@106: 				scrollV = W.scrollTop();
bgneal@106: 				scrollH = W.scrollLeft();
bgneal@106: 
bgneal@106: 				this.el.addClass('fancybox-lock');
bgneal@106: 
bgneal@106: 				W.scrollTop( scrollV ).scrollLeft( scrollH );
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			this.open(opts);
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		onUpdate : function() {
bgneal@106: 			if (!this.fixed) {
bgneal@106: 				this.update();
bgneal@106: 			}
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		afterClose: function (opts) {
bgneal@106: 			// Remove overlay if exists and fancyBox is not opening
bgneal@106: 			// (e.g., it is not being open using afterClose callback)
bgneal@106: 			//if (this.overlay && !F.isActive) {
bgneal@106: 			if (this.overlay && !F.coming) {
bgneal@106: 				this.overlay.fadeOut(opts.speedOut, $.proxy( this.close, this ));
bgneal@106: 			}
bgneal@106: 		}
bgneal@106: 	};
bgneal@106: 
bgneal@106: 	/*
bgneal@106: 	 *	Title helper
bgneal@106: 	 */
bgneal@106: 
bgneal@106: 	F.helpers.title = {
bgneal@106: 		defaults : {
bgneal@106: 			type     : 'float', // 'float', 'inside', 'outside' or 'over',
bgneal@106: 			position : 'bottom' // 'top' or 'bottom'
bgneal@106: 		},
bgneal@106: 
bgneal@106: 		beforeShow: function (opts) {
bgneal@106: 			var current = F.current,
bgneal@106: 				text    = current.title,
bgneal@106: 				type    = opts.type,
bgneal@106: 				title,
bgneal@106: 				target;
bgneal@106: 
bgneal@106: 			if ($.isFunction(text)) {
bgneal@106: 				text = text.call(current.element, current);
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			if (!isString(text) || $.trim(text) === '') {
bgneal@106: 				return;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			title = $('<div class="fancybox-title fancybox-title-' + type + '-wrap">' + text + '</div>');
bgneal@106: 
bgneal@106: 			switch (type) {
bgneal@106: 				case 'inside':
bgneal@106: 					target = F.skin;
bgneal@106: 				break;
bgneal@106: 
bgneal@106: 				case 'outside':
bgneal@106: 					target = F.wrap;
bgneal@106: 				break;
bgneal@106: 
bgneal@106: 				case 'over':
bgneal@106: 					target = F.inner;
bgneal@106: 				break;
bgneal@106: 
bgneal@106: 				default: // 'float'
bgneal@106: 					target = F.skin;
bgneal@106: 
bgneal@106: 					title.appendTo('body');
bgneal@106: 
bgneal@106: 					if (IE) {
bgneal@106: 						title.width( title.width() );
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					title.wrapInner('<span class="child"></span>');
bgneal@106: 
bgneal@106: 					//Increase bottom margin so this title will also fit into viewport
bgneal@106: 					F.current.margin[2] += Math.abs( getScalar(title.css('margin-bottom')) );
bgneal@106: 				break;
bgneal@106: 			}
bgneal@106: 
bgneal@106: 			title[ (opts.position === 'top' ? 'prependTo'  : 'appendTo') ](target);
bgneal@106: 		}
bgneal@106: 	};
bgneal@106: 
bgneal@106: 	// jQuery plugin initialization
bgneal@106: 	$.fn.fancybox = function (options) {
bgneal@106: 		var index,
bgneal@106: 			that     = $(this),
bgneal@106: 			selector = this.selector || '',
bgneal@106: 			run      = function(e) {
bgneal@106: 				var what = $(this).blur(), idx = index, relType, relVal;
bgneal@106: 
bgneal@106: 				if (!(e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) && !what.is('.fancybox-wrap')) {
bgneal@106: 					relType = options.groupAttr || 'data-fancybox-group';
bgneal@106: 					relVal  = what.attr(relType);
bgneal@106: 
bgneal@106: 					if (!relVal) {
bgneal@106: 						relType = 'rel';
bgneal@106: 						relVal  = what.get(0)[ relType ];
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					if (relVal && relVal !== '' && relVal !== 'nofollow') {
bgneal@106: 						what = selector.length ? $(selector) : that;
bgneal@106: 						what = what.filter('[' + relType + '="' + relVal + '"]');
bgneal@106: 						idx  = what.index(this);
bgneal@106: 					}
bgneal@106: 
bgneal@106: 					options.index = idx;
bgneal@106: 
bgneal@106: 					// Stop an event from bubbling if everything is fine
bgneal@106: 					if (F.open(what, options) !== false) {
bgneal@106: 						e.preventDefault();
bgneal@106: 					}
bgneal@106: 				}
bgneal@106: 			};
bgneal@106: 
bgneal@106: 		options = options || {};
bgneal@106: 		index   = options.index || 0;
bgneal@106: 
bgneal@106: 		if (!selector || options.live === false) {
bgneal@106: 			that.unbind('click.fb-start').bind('click.fb-start', run);
bgneal@106: 
bgneal@106: 		} else {
bgneal@106: 			D.undelegate(selector, 'click.fb-start').delegate(selector + ":not('.fancybox-item, .fancybox-nav')", 'click.fb-start', run);
bgneal@106: 		}
bgneal@106: 
bgneal@106: 		this.filter('[data-fancybox-start=1]').trigger('click');
bgneal@106: 
bgneal@106: 		return this;
bgneal@106: 	};
bgneal@106: 
bgneal@106: 	// Tests that need a body at doc ready
bgneal@106: 	D.ready(function() {
bgneal@106: 		var w1, w2;
bgneal@106: 
bgneal@106: 		if ( $.scrollbarWidth === undefined ) {
bgneal@106: 			// http://benalman.com/projects/jquery-misc-plugins/#scrollbarwidth
bgneal@106: 			$.scrollbarWidth = function() {
bgneal@106: 				var parent = $('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body'),
bgneal@106: 					child  = parent.children(),
bgneal@106: 					width  = child.innerWidth() - child.height( 99 ).innerWidth();
bgneal@106: 
bgneal@106: 				parent.remove();
bgneal@106: 
bgneal@106: 				return width;
bgneal@106: 			};
bgneal@106: 		}
bgneal@106: 
bgneal@106: 		if ( $.support.fixedPosition === undefined ) {
bgneal@106: 			$.support.fixedPosition = (function() {
bgneal@106: 				var elem  = $('<div style="position:fixed;top:20px;"></div>').appendTo('body'),
bgneal@106: 					fixed = ( elem[0].offsetTop === 20 || elem[0].offsetTop === 15 );
bgneal@106: 
bgneal@106: 				elem.remove();
bgneal@106: 
bgneal@106: 				return fixed;
bgneal@106: 			}());
bgneal@106: 		}
bgneal@106: 
bgneal@106: 		$.extend(F.defaults, {
bgneal@106: 			scrollbarWidth : $.scrollbarWidth(),
bgneal@106: 			fixed  : $.support.fixedPosition,
bgneal@106: 			parent : $('body')
bgneal@106: 		});
bgneal@106: 
bgneal@106: 		//Get real width of page scroll-bar
bgneal@106: 		w1 = $(window).width();
bgneal@106: 
bgneal@106: 		H.addClass('fancybox-lock-test');
bgneal@106: 
bgneal@106: 		w2 = $(window).width();
bgneal@106: 
bgneal@106: 		H.removeClass('fancybox-lock-test');
bgneal@106: 
bgneal@106: 		$("<style type='text/css'>.fancybox-margin{margin-right:" + (w2 - w1) + "px;}</style>").appendTo("head");
bgneal@106: 	});
bgneal@106: 
bgneal@106: }(window, document, jQuery));