
/*** File "libs.js" starts here. ***/

/*@cc_on _d=document;eval('var document=_d')

var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),
i = e.length;
while (i--) {
	document.createElement(e[i])
}

@*/

$.fn.markCurrentLocation = function() {
	var path = window.location.href
	return this.each(function(){
		var self = $(this);
		var href = self.attr('href');
		if(path == href){
			var linkLabel = self.text();
			self
				.before('<em><span class="emcontent">'+linkLabel+'</span></em>')
				.remove()
		}else if(RegExp(href).test(path)){
			self
				.wrap('<em></em>')
		}
	})
};

$.fn.orderedFigure = function() {
	return this.each(function(){
		var self = $(this);
		var cont = self.html();
		var cont2 = cont.replace(/(\d)(st|nd|rd|th)/g,'$1<sup>$2</sup>')
		self.html(cont2);
	})
};

$.fn.notify = function(type) {
	var to = {backgroundColor: "white"};
	var duration = 1000;
	switch(type){
		case 'alert':
			var from = {backgroundColor:'#ff9797'};
			break;
		default:
			var from = {backgroundColor:'#fef794'};
			break;
	}
	return this.each(function(){
		$(this).css(from).stop().animate(to,duration,function(){$(this).removeAttr('style')});
	});
};

/**
 * @param query {RegExp}
 * @wrapElement wrapElement {jQuery}
 **/
$.fn.highlightText = function(query,wrapElement){
	var REtag = '<\\/?[^>]+?\\/?>';
	var REtagDivider = new RegExp(REtag+'|[^<>]*','gi');
	return this.each(function(){
		var elem = $(this);

		var srcs = elem.html().match(REtagDivider);
		for(var i=0,l=srcs.length;i<l;i++){
			var obj = srcs[i];
			if(!RegExp(REtag).test(obj)){
				srcs[i] = obj.replace(query,function(matched){
					return $('<div />').append(wrapElement.html(matched)).html();
				})
			}
		}
		elem.html(srcs.join(''));
	})
}

/**
 * @example $('em.highlight').removeOuterTag()
 * @description will turn 'text1 <em class="highlight">text2</em> text3' into 'text1 text2 text3'
 **/
$.fn.removeOuterTag = function(){
	return this.each(function(){
		$(this).replaceWith($(this).html())
	})
}

var iaMobileNavInit = function(){
	$('<div id="shield" />')
		.appendTo('body')
		.css('height',$(document).height()+6)
		.click(function(){
			$(this).toggle();
			$('header nav').hide();
			$('.forRMB').removeClass('focus')
		})
		.hide();

	$('#iMenu')
		.click(function(){
			$('#shield').toggle();
			$(this).toggleClass('focus')
			$('#iLang').removeClass('focus')
			$('.langSelector').hide()
			$('.mainNav').toggle()
			return false;
		})

	$('#iLang')
		.click(function(){
			$('#shield').toggle();
			$(this).toggleClass('focus')
			$('#iMenu').removeClass('focus')
			$('.mainNav').hide()
			$('.langSelector').toggle()
			return false;
		})
};



/*** File "jquery.browser.addEnvClass.js" starts here. ***/

(function(){
	var ua = navigator.userAgent;
	var b = jQuery.browser;
	b.engine = '';
	b.mobile = false;

	if(/Windows/.test(ua)){
		b.os = 'win';
		b.win = true;
	}else if(/Mac/.test(ua)){
		b.os = 'mac';
		b.mac = true;
	}else if(/iPhone/.test(ua)){
		b.os = 'iphone';
		b.iphone = true;
	}

	if(/Chrome/.test(ua)){
		b.safari = false;
		b.chrome = true;
	}

	if(/Gecko/.test(ua)){
		b.gecko = true;
		b.engine = 'gecko'
	}if(/WebKit/.test(ua)){
		b.gecko = false;
		b.webkit = true;
		b.engine = 'webkit'
	}

	if(/Mobile/i.test(ua)){
		b.mobile = true;
	}
	
	if(b.msie){
		b.name = 'msie';
	}else if(b.opera){
		b.name = 'opera';
	}else if(b.safari){
		b.name = 'safari';
	}else if(b.chrome){
		b.name = 'chrome';
	}else if(b.mozilla){
		b.name = 'mozilla';
	}

	if(b.msie){
		b.ver = /MSIE (\d(.\d+)?)/.exec(ua)[1];
	}else if(b.mozilla){
		b.ver = /Firefox\/(\d(.\d+)?)/.exec(ua)[1];
	}else if(b.opera){
		b.ver = /Opera\/? ?(\d(\.\d+)?)/.exec(ua)[1];
	}else if(b.safari){
		b.ver = /Version\/(\d(\.\d+)+)/.exec(ua)[1];
	}else if(b.chrome){
		b.ver = /Chrome\/(\d(\.\d+)+)/.exec(ua)[1];
	}
})()

jQuery.fn.addEnvClass = function() {
	return this.each(function(){
		var self = jQuery(this);
		var b = jQuery.browser;
		self
			.addClass('js')
			.addClass(b.os)
			.addClass(b.name)
			.addClass(b.engine)
			.addClass('ver'+b.ver);
	
		if(b.msie){
			self.addClass('ie' + parseInt(b.ver));
		}
	})
};

jQuery('html').addEnvClass();



/*** File "jquery.color.js" starts here. ***/

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);


/*** File "jquery.initInput.js" starts here. ***/

(function($) {
	jQuery.initInput = {
		defaultValue: '',
		errorMessage: '',
		wdmClassName: 'with-default-message'
	}

	jQuery.fn.initInput = function(arg1,arg2) {

		return this.each(function(){
			var elem = $(this);
			var form = elem.parents('form');
			var wdm = $.initInput.wdmClassName;
			
			if(elem.attr('placeholder')){
				var msg = elem.attr('placeholder');
				var emsg = arg1 || $.initInput.errorMessage;
			}else{
				var msg = arg1 || $.initInput.defaultValue;
				var emsg = arg2 || $.initInput.errorMessage;
			}

			//init
			var init = function(){
				if(elem.val() == '' || elem.val() == msg){
					elem.val(msg).addClass(wdm);
				}
			}

			//set event
			var setEvent = function(){
				elem.focus(function(){
					elem.removeClass(wdm);
					if(elem.val() == msg){
						elem.val('');
					}
				}).blur(init);

				form.submit(function(){
					if(emsg == ''){
						//Allaw empty
						if(elem.val() == msg){
							elem.val('');
						}
					}else{
						//Disallow empty
						if(elem.val() == '' || elem.val() == msg){
							alert(emsg);
							elem.notify('alert');
							return false;
						}
					}
					return true;
				});
			}

			//fire function
			init();
			setEvent();

		});
	};
})(jQuery);

/*** File "jquery.addFileInfo.js" starts here. ***/

(function($) {
	if(typeof ActiveXObject == "function" && typeof XMLHttpRequest == "undefined"){
		XMLHttpRequest = function(){
			try {
				return new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				return new ActiveXObject('Microsoft.XMLHTTP');
			}
		}
	}
		
	//Setting valiables
	var fileLinkClass = "file";
	var fileTypeClass = "fileType";
	var fileSizeClass = "fileSize";
	var imageLinkClass = "imageLink";
	var originalTextClass = "originalText";
	var notFoundClass = 'notFound';
	var notFoundText = 'Not Found';
	var fileClasses = '(pdf|od[tspdgf]|xlsx?|docx?|pptx?|zip|tar(\.gz)?)';
	var fileExtention = '\\.'+fileClasses+'$';

	//Get path to phpfile
	var helperPHP = $('script[src]:last').attr('src').replace(/\.js/,'.php');
	
	/**
	 * Amendments for iA template, for use with bundle.js.php
	**/
	if(new RegExp(/bundle\.js\.php/).test($('script[src]:last').attr('src'))) {
		var helperPHP = $('script[src]:last').attr('src').replace(/bundle\.js\.php/,'jquery.addFileInfo.php');
	}

	/**
	 * @sample $('article a').addFileInfo()
	 * @descriptoin If the elements have class or file extention defined as fileClasses and fileExtention, or have fileLinkClass class, it will automatically have fancy file type label before the original text, and the size after. This order is considederd from accessibility perspective.
	 * 
	 * @sample $('a.pdf').addFileInfo()
	 * @desctription 'A' elements which have fileTypeClass will be affected. This class decide displayed file type.
	 * 
	 * @sample $('a.file').addFileInfo()
	 * @desctription 'A' elements which have fileLinkClass will be affected. File type is detected automatically.
	 * 
	 * @returns {jQuery}
	 */
	$.fn.addFileInfo = function(){
		return this.each(function(){

			var elem = $(this);
			var href = elem.get(0).href;
			var fileType = '';
			var fileSize = 0;
			var fileMatch = RegExp(fileExtention).exec(href.replace(/#.+$/,''));
			var classMatch = RegExp(fileClasses).exec(elem.attr('class'));
			if(fileMatch){
				fileType = fileMatch[1];
			}else if(classMatch){
				fileType = classMatch[1];
			}else if(!elem.is('.'+fileLinkClass)){
				return;
			}
			
			var setFileInfo = function(json){
				var contentLength = json['Content-Length'];

				if(!fileType){
					fileType = (/(\/|-)([^-]+)$/.exec(json['Content-Type'])[2]);
				}

				if(String(contentLength-0) != 'NaN'){
					fileSize = Math.round(contentLength / 1024);
					if(fileSize >= 1000){
						fileSize = (Math.round(fileSize / 102.4) / 10) + 'MB';
					}else{
						fileSize = fileSize + 'KB';
					}
				}
					
				elem
					.addClass(fileLinkClass)
					.addClass(fileType)

				if(elem.find('.'+originalTextClass).size() == 0){
					elem.wrapInner('<span class="'+originalTextClass+'" />')
				}

				if(/404/.test(json[0])){
					fileSize = notFoundText;
					elem.find('.'+originalTextClass).addClass(notFoundClass);
				}else{
					elem.prepend('<span class="'+ fileTypeClass +'">'+ fileType.toUpperCase() +'</span> ')
				}


				if(elem.is('*:has(img)')){
					elem.addClass(imageLinkClass)
					$('.'+fileTypeClass,elem).append(' ('+fileSize+')');
				}else{
					elem.append(' <span class="'+fileSizeClass+'">('+fileSize+')</span>');
				}
				
			}
			
			var outset = function(){
				var fte = $('.'+fileTypeClass,elem);
				if(fte.parents('ul').size()){
					var ml = fte.width()
					+ parseInt(fte.css('padding-left').replace(/px/,''))
					+ parseInt(fte.css('padding-right').replace(/px/,''))
					fte.parents('li').css({
						position: 'relative'
					})
					fte.css({
						position: 'absolute',
						marginTop: '.2em',
						marginLeft: -ml -4 + 'px'
					});
				}
			}
			
			var main = function(){
				if(/https?:\/\/(.+?)\//.exec(href)[1] == location.host){
					var req = new XMLHttpRequest();
					req.open('HEAD',href,true);
					req.onreadystatechange = function(){
						if(req.readyState == 4){
							if(req.getResponseHeader("Content-Length")){
								setFileInfo({
									"0": req.getResponseHeader("0"),
									"Content-Type": req.getResponseHeader("Content-Type"),
									"Content-Length": req.getResponseHeader("Content-Length")
								});
							}else{
								$.post(helperPHP,{url:href},setFileInfo,'json')
							}
							req.abort();
						}
					}
					req.send(null);
				}else{
					$.post(helperPHP,{url:href},setFileInfo,'json')
				}
			}

			main();
			outset();

		});
	};
})(jQuery);


/*** File "jquery.incrementalFilter.js" starts here. ***/

(function($) {
	var IncrementalFilter = function(params){
		var setting = this.setting = {
			input: undefined,
			items: undefined,
			searchScope: '*',
			minChars: 2,
			useHighlight: true,
			foundCounter: undefined,
			totalCounter: undefined,
			highlightElem: $('<em class="highlight" />'),
			foundClass: 'found',
			zeroClass: 'zero'
		}
		$.extend(setting,params)
	
		this.input = $(setting.input);
		this.items = $(setting.items);
		this.minChars = setting.minChars;
		if(setting.foundCounter){
			this.totalCounter = setting.totalCounter;
			this.foundCounter = new IncrementalFilter.Counter(setting);
		}
		this.formerQuery = '';
		this.itemData = [];
		this.init();
	}
	
	IncrementalFilter.prototype = {
	
		makeData: function(){
			var that = this;
			this.items.each(function(){
				var obj = [$(this)]
				if($(this).is('dt')){
					obj.push($(this).next())
				}
				that.itemData.push(new IncrementalFilter.SearchedItem(obj,that.setting));
			})
			if(this.foundCounter){
				this.foundCounter.refresh(this.itemData.length);
				if(this.totalCounter){
					$(this.totalCounter).html(this.foundCounter.all)
				}
			}
		},
		
		processQuery: function(query){
			var tempq = this.escapeQuery(query)
			tempq = $.trim(tempq).split(/\s+/);
			var queries = []
		
			for(var i=0,l=tempq.length;i<l;i++){
				for(var j=0,m=tempq.length;j<m;j++){
					if(i!=j && tempq[i] && (tempq[i] == tempq[j]
					   || RegExp(tempq[i]).test(tempq[j])
					   || tempq[i].length < this.minChars)){
						tempq.splice(i,1)
						l = m = tempq.length;
					}
				}
				if(tempq[i]){
					queries.push(tempq[i])
				}
			}
	
			if(queries.join(' ') != this.formerQuery){
				this.search(queries);
				this.formerQuery = queries.join(' ');
			}
		},
		
		escapeQuery: function(query){
			var escapeChars = '.+*^$?()[]{}';
			var res = query;
			for(var i=0,l=escapeChars.length;i<l;i++){
				var ec = escapeChars.charAt(i);
				res = res.replace(RegExp('\\'+ec,'g'),'\\'+ec);
			}
			return res;
		},
	
		search: function(queries){
			var that = this;
			var count = 0;
			$(that.itemData).each(function(){
				var self = this;
				var matchCount = 0;
				$.each(queries,function(){
					if(RegExp(this,'i').test(self.text))
						matchCount++;
				})
				if(matchCount == queries.length){
					this.showItem()
					this.clearHighlight(function(){
						$.each(queries,function(){
							self.highlightWord(this)
						})
					});
					count++;
				}else{
					this.hideItem();
				}
			})
			if(this.foundCounter){
				this.foundCounter.refresh(count)
			}
		},
		
		reset: function(){
			var that = this;
			$(this.itemData).each(function(){
				this.showItem();
				this.clearHighlight();
				if(that.foundCounter){
					that.foundCounter.reset();
				}
			})
		},
	
		setEvent: function(){
			var that = this;
			this.input.bind('keyup',function(){
				var val = $(this).val();
				if(val.length >= that.minChars){
					that.processQuery(val)
				}else{
					that.reset();
				}
			})
		},
	
		init: function(){
			this.makeData();
			this.setEvent();
			if(this.input.val().length >= this.minChars){
				this.processQuery(this.input.val())
			}
		}
	}
	
	/**
	 *@param obj {array}
	 **/
	IncrementalFilter.SearchedItem = function(obj,setting){
		this.useHighlight = (setting.useHighlight && $.fn.highlightText && $.fn.removeOuterTag)
		if(this.useHighlight){
			this.highlightElem = setting.highlightElem || $('<em class="highlight" />');
			this.highlightExpr = /^<(\w+)/.exec($('<div />').append(this.highlightElem).html())[1]
							   + '.'+this.highlightElem.attr('class').split(/\s/).join('.');
		}
		this.text = '';
		this.obj = [];
		for(var i=0,l=obj.length;i<l;i++){
			var temp = obj[i];
			this.obj[i] = {'elem':temp,'orgsrc':temp.html()}
			this.text += obj[i].text();
		}
	}
	
	IncrementalFilter.SearchedItem.prototype = {
		hideItem: function(){
			$(this.obj).each(function(){
				this.elem.hide();
			})
			return this;
		},
	
		showItem: function(){
			$(this.obj).each(function(){
				this.elem.show();
			})
			return this;
		},
	
		clearHighlight: function(callback){
			if(!this.useHighlight) return this;
			var that = this;
			$(this.obj).each(function(){
				$(that.highlightExpr,this.elem).removeOuterTag()
			})
			if(callback) callback();
			return this;
		},
	
		highlightWord: function(word){
			if(!this.useHighlight) return this;
			var that = this;
			var query = new RegExp(word,'gi')
			$(this.obj).each(function(){
				this.elem.highlightText(query,that.highlightElem)
			})
			return this;
		}
	}
	
	IncrementalFilter.Counter = function(setting){
		if(!setting || !setting.foundCounter) return undefined;
		this.obj = $(setting.foundCounter);
		this.foundClass = setting.foundClass || 'found';
		this.zeroClass = setting.zeroClass || 'zero';
		this.all = undefined;
		
		this.refresh = function(count){
			this.obj.html(count);
			if(!this.all){
				this.all = count;
			}
			
			if(count == 0){
				this.zero()
			}else if(count < this.all){
				this.highlight();
			}
		}
	
		this.reset = function(){
			this.refresh(this.all);
			this.obj
				.removeClass(this.foundClass)
				.removeClass(this.zeroClass)
		}
	
		this.highlight = function(){
			this.obj
				.removeClass(this.zeroClass)
				.addClass(this.foundClass)
		}
	
		this.zero = function(){
			this.obj
				.removeClass(this.foundClass)
				.addClass(this.zeroClass)
		}
		
		return this;
	}

	$.fn.incrementalFilter = function(params){
		return this.each(function(){
			if(typeof params == 'string' || params.size){
				new IncrementalFilter({input:$(this),items:params})
			}else if(typeof params == 'object'){
				params.input = $(this);
				new IncrementalFilter(params)
			}
		});
	};
})(jQuery);

/*** File "init.js" starts here. ***/

$(function(){
	$('header nav a').markCurrentLocation();
	$('form.sitesearch :text').initInput('Enter some keyword');
	$('#darth_vader').initInput('It\'s empty!')
	$('.contentBody .date, .contentBody cite').orderedFigure();
	$('article a').addFileInfo();


	if($.browser.mobile){
		iaMobileNavInit();
	}

	if($.browser.msie){
		$('.lu:first-child').addClass('first-child')
	}

})

/*** File "jquery.fancybox-1.3.1.js" starts here. ***/

/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 *
 * Version: 1.3.1 (05/03/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {

	var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,

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

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

		loadingTimer, loadingFrame = 1,

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

		isIE6 = !$.support.opacity && !window.XMLHttpRequest,

		/*
		 * Private methods 
		 */

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

			imgPreloader.onerror = imgPreloader.onload = null;

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

			tmp.empty();
		},

		fancybox_error = function() {
			$.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
				'scrolling'		: 'no',
				'padding'		: 20,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'
			});
		},

		fancybox_get_viewport = function() {
			return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
		},

		fancybox_get_zoom_to = function () {
			var view	= fancybox_get_viewport(),
				to		= {},

				margin = currentOpts.margin,
				resize = currentOpts.autoScale,

				horizontal_space	= (shadow + margin) * 2,
				vertical_space		= (shadow + margin) * 2,
				double_padding		= (currentOpts.padding * 2),
				
				ratio;

			if (currentOpts.width.toString().indexOf('%') > -1) {
				to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
				resize = false;

			} else {
				to.width = currentOpts.width + double_padding;
			}

			if (currentOpts.height.toString().indexOf('%') > -1) {
				to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
				resize = false;

			} else {
				to.height = currentOpts.height + double_padding;
			}

			if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
				if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
					horizontal_space	+= double_padding;
					vertical_space		+= double_padding;

					ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);

					to.width	= Math.round(ratio * (to.width	- double_padding)) + double_padding;
					to.height	= Math.round(ratio * (to.height	- double_padding)) + double_padding;

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

			to.top	= view[3] + ((view[1] - (to.height	+ (shadow * 2 ))) * 0.5);
			to.left	= view[2] + ((view[0] - (to.width	+ (shadow * 2 ))) * 0.5);

			if (currentOpts.autoScale === false) {
				to.top	= Math.max(view[3] + margin, to.top);
				to.left	= Math.max(view[2] + margin, to.left);
			}

			return to;
		},

		fancybox_format_title = function(title) {
			if (title && title.length) {
				switch (currentOpts.titlePosition) {
					case 'inside':
						return title;
					case 'over':
						return '<span id="fancybox-title-over">' + title + '</span>';
					default:
						return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
				}
			}

			return false;
		},

		fancybox_process_title = function() {
			var title	= currentOpts.title,
				width	= final_pos.width - (currentOpts.padding * 2),
				titlec	= 'fancybox-title-' + currentOpts.titlePosition;
				
			$('#fancybox-title').remove();

			titleh = 0;

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

			title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);

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

			$('<div id="fancybox-title" class="' + titlec + '" />').css({
				'width'			: width,
				'paddingLeft'	: currentOpts.padding,
				'paddingRight'	: currentOpts.padding
			}).html(title).appendTo('body');

			switch (currentOpts.titlePosition) {
				case 'inside':
					titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
					final_pos.height += titleh;
				break;

				case 'over':
					$('#fancybox-title').css('bottom', currentOpts.padding);
				break;

				default:
					$('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
				break;
			}

			$('#fancybox-title').appendTo( outer ).hide();
		},

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

				} else if (e.keyCode == 37) {
					e.preventDefault();
					$.fancybox.prev();

				} else if (e.keyCode == 39) {
					e.preventDefault();
					$.fancybox.next();
				}
			});

			if ($.fn.mousewheel) {
				wrap.unbind('mousewheel.fb');

				if (currentArray.length > 1) {
					wrap.bind('mousewheel.fb', function(e, delta) {
						e.preventDefault();

						if (busy || delta === 0) {
							return;
						}

						if (delta > 0) {
							$.fancybox.prev();
						} else {
							$.fancybox.next();
						}
					});
				}
			}

			if (!currentOpts.showNavArrows) { return; }

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

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

		fancybox_preload_images = function() {
			var href, 
				objNext;
				
			if ((currentArray.length -1) > currentIndex) {
				href = currentArray[ currentIndex + 1 ].href;

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

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

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

		_finish = function () {
			inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));

			if (!$.support.opacity) {
				inner.get(0).style.removeAttribute('filter');
				wrap.get(0).style.removeAttribute('filter');
			}

			$('#fancybox-title').show();

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

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

			fancybox_set_navigation();

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

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

			if ($.isFunction(currentOpts.onComplete)) {
				currentOpts.onComplete(currentArray, currentIndex, currentOpts);
			}

			busy = false;

			fancybox_preload_images();
		},

		fancybox_draw = function(pos) {
			var width	= Math.round(start_pos.width	+ (final_pos.width	- start_pos.width)	* pos),
				height	= Math.round(start_pos.height	+ (final_pos.height	- start_pos.height)	* pos),

				top		= Math.round(start_pos.top	+ (final_pos.top	- start_pos.top)	* pos),
				left	= Math.round(start_pos.left	+ (final_pos.left	- start_pos.left)	* pos);

			wrap.css({
				'width'		: width		+ 'px',
				'height'	: height	+ 'px',
				'top'		: top		+ 'px',
				'left'		: left		+ 'px'
			});

			width	= Math.max(width - currentOpts.padding * 2, 0);
			height	= Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);

			inner.css({
				'width'		: width		+ 'px',
				'height'	: height	+ 'px'
			});

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

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

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

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

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

			return pos;
		},

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

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

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

				from = {
					width	: 1,
					height	: 1,
					top		: view[3] + view[1] * 0.5,
					left	: view[2] + view[0] * 0.5
				};
			}

			return from;
		},

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

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

					busy = false;
					return;
				}
			}

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

			inner.get(0).scrollTop	= 0;
			inner.get(0).scrollLeft	= 0;

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

				overlay.css({
					'background-color'	: currentOpts.overlayColor,
					'opacity'			: currentOpts.overlayOpacity
				}).unbind().show();
			}

			final_pos = fancybox_get_zoom_to();

			fancybox_process_title();

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

				var pos = wrap.position(),
					equal;

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

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

				inner.fadeOut(currentOpts.changeFade, function() {
					var finish_resizing = function() {
						inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
					};
					
					$.event.trigger('fancybox-change');

					inner.empty().css('overflow', 'hidden');

					if (equal) {
						inner.css({
							top			: currentOpts.padding,
							left		: currentOpts.padding,
							width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
							height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
						});
						
						finish_resizing();

					} else {
						inner.css({
							top			: currentOpts.padding,
							left		: currentOpts.padding,
							width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
							height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
						});
						
						fx.prop = 0;

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

				return;
			}

			wrap.css('opacity', 1);

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

				inner.css({
						top			: currentOpts.padding,
						left		: currentOpts.padding,
						width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
						height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
					})
					.html( tmp.contents() );

				wrap.css(start_pos).show();

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

				fx.prop = 0;

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

			} else {
				inner.css({
						top			: currentOpts.padding,
						left		: currentOpts.padding,
						width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
						height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
					})
					.html( tmp.contents() );

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

		fancybox_process_inline = function() {
			tmp.width(	selectedOpts.width );
			tmp.height(	selectedOpts.height );

			if (selectedOpts.width	== 'auto') {
				selectedOpts.width = tmp.width();
			}
			if (selectedOpts.height	== 'auto') {
				selectedOpts.height	= tmp.height();
			}

			fancybox_show();
		},
		
		fancybox_process_image = function() {
			busy = true;

			selectedOpts.width	= imgPreloader.width;
			selectedOpts.height	= imgPreloader.height;

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

			fancybox_show();
		},

		fancybox_start = function() {
			fancybox_abort();

			var obj	= selectedArray[ selectedIndex ],
				href, 
				type, 
				title,
				str,
				emb,
				selector,
				data;

			selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
			title = obj.title || $(obj).title || selectedOpts.title || '';
			
			if (obj.nodeName && !selectedOpts.orig) {
				selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
			}

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

			if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
				href = selectedOpts.href || null;
			} else {
				href = selectedOpts.href || obj.href || null;
			}

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

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

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

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

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

				} else if (href.match(/#/)) {
					obj = href.substr(href.indexOf("#"));

					type = $(obj).length > 0 ? 'inline' : 'ajax';
				} else {
					type = 'ajax';
				}
			} else {
				type = 'inline';
			}

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

			if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
				selectedOpts.width		= 'auto';
				selectedOpts.height		= 'auto';
			}

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

			if ($.isFunction(selectedOpts.onStart)) {
				if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
					busy = false;
					return;
				}
			}

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

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

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

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

					$(obj).appendTo(tmp);

					fancybox_process_inline();
				break;

				case 'image':
					busy = false;

					$.fancybox.showActivity();

					imgPreloader = new Image();

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

					imgPreloader.onload = function() {
						imgPreloader.onerror = null;
						imgPreloader.onload = null;
						fancybox_process_image();
					};

					imgPreloader.src = href;
		
				break;

				case 'swf':
					str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
					emb = '';
					
					$.each(selectedOpts.swf, function(name, val) {
						str += '<param name="' + name + '" value="' + val + '"></param>';
						emb += ' ' + name + '="' + val + '"';
					});

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

					tmp.html(str);

					fancybox_process_inline();
				break;

				case 'ajax':
					selector	= href.split('#', 2);
					data		= selectedOpts.ajax.data || {};

					if (selector.length > 1) {
						href = selector[0];

						if (typeof data == "string") {
							data += '&selector=' + selector[1];
						} else {
							data.selector = selector[1];
						}
					}

					busy = false;
					$.fancybox.showActivity();

					ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
						url		: href,
						data	: data,
						error	: fancybox_error,
						success : function(data, textStatus, XMLHttpRequest) {
							if (ajaxLoader.status == 200) {
								tmp.html( data );
								fancybox_process_inline();
							}
						}
					}));

				break;

				case 'iframe' :
					$('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
					fancybox_show();
				break;
			}
		},

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

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

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

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

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

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

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

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

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

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

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

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

			if (isIE6) {
				overlay.get(0).style.setExpression('height',	"document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
				loading.get(0).style.setExpression('top',		"(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");

				outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
			}
		};

	/*
	 * Public methods 
	 */

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

				if (busy) {
					return;
				}

				busy = true;

				$(this).blur();

				selectedArray	= [];
				selectedIndex	= 0;

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

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

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

				fancybox_start();

				return false;
			});

		return this;
	};

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

		busy = true;

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

		selectedArray	= [];
		selectedIndex	= opts.index || 0;

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

			selectedArray = jQuery.merge(selectedArray, obj);

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

			selectedArray.push(obj);
		}

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

		fancybox_start();
	};

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

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

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

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

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

		pos = parseInt(pos, 10);

		if (pos > -1 && currentArray.length > pos) {
			selectedIndex = pos;
			fancybox_start();
		}

		if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
			selectedIndex = currentArray.length - 1;
			fancybox_start();
		}

		if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
			selectedIndex = 0;
			fancybox_start();
		}

		return;
	};

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

		busy = true;

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

		fancybox_abort();

		if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
			selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
		}

		busy = false;
	};

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

		busy = true;

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

		fancybox_abort();

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

		$('#fancybox-title').remove();

		wrap.add(inner).add(overlay).unbind();

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

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

			wrap.hide();

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

			inner.empty();

			if ($.isFunction(currentOpts.onClosed)) {
				currentOpts.onClosed(currentArray, currentIndex, currentOpts);
			}

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

			busy = false;
		}

		inner.css('overflow', 'hidden');

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

			var pos = wrap.position();

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

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

			fx.prop = 1;

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

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

	$.fancybox.resize = function() {
		var c, h;
		
		if (busy || wrap.is(':hidden')) {
			return;
		}

		busy = true;

		c = inner.wrapInner("<div style='overflow:auto'></div>").children();
		h = c.height();

		wrap.css({height:	h + (currentOpts.padding * 2) + titleh});
		inner.css({height:	h});

		c.replaceWith(c.children());

		$.fancybox.center();
	};

	$.fancybox.center = function() {
		busy = true;

		var view	= fancybox_get_viewport(),
			margin	= currentOpts.margin,
			to		= {};

		to.top	= view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
		to.left	= view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);

		to.top	= Math.max(view[3] + margin, to.top);
		to.left	= Math.max(view[2] + margin, to.left);

		wrap.css(to);

		busy = false;
	};

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

		width				:	560,
		height				:	340,

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

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

		hideOnOverlayClick	:	true,
		hideOnContentClick	:	false,

		overlayShow			:	true,
		overlayOpacity		:	0.3,
		overlayColor		:	'#666',

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

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

		speedIn				:	300,
		speedOut			:	300,

		changeSpeed			:	300,
		changeFade			:	'fast',

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

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

		onStart				:	null,
		onCancel			:	null,
		onComplete			:	null,
		onCleanup			:	null,
		onClosed			:	null
	};

	$(document).ready(function() {
		fancybox_init();
	});

})(jQuery);