﻿/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  
var tb_pathToImage = "/images/loadingAnimation.gif";

// Lexus Customisation - removes wrap initialisation in a fucntion
// addition of ?page param to allow instantiation from page
// additional params for transparancy and curtain hiding
// trailing & and # clean up in iFrames
// addition to call pause and close on main_movie flash when rendered tb_show and tb_remove (flash optimisation)
// addition to resize/restyle iframes when longer than viewport

//on page load call tb_init
$(document).ready(function(){   
                tb_loadup();
});

function tb_loadup(){
	tb_init('a.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
}
// End Lexus customisation 

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){

                // Lexus Customisation - removes the onClick from CTAs
	$(domChunk).unbind("click");
	$(domChunk).removeAttr("onclick");
                // End Lexus customisation 

	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;

               // Hide the quicklinks before we display anything
               // Make sure that you updated quicklinks.ascx if you edit this code. 
               // They both contain coding to hide the quick links 
               if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
		$("div#quicklinks").animate({opacity: 0}, 0, 'swing');
	}
                $("div#quicklinks div.top").hide();
	$("div#quicklinks div.bottom").hide();
                $("div#quicklinks").css("border-bottom","none");
                $("div#quicklinks").hide();
	$("li#quicklinkscontainer a.quicklinks").css("padding-bottom","0px");

	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

// Lexus Customisation - kept for backwards compatibilty
function tb_getQueryStringParams(url)
{
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = tb_parseQuery( queryString );	
	return params;
}
// End Lexus customisation 


function returnCurtainsClass(url){
    var sReturn = "";
    var oQS = tb_getQueryStringParams(url);
	var sHideCurtains = (oQS['hidecurtains']) ? oQS['hidecurtains'] : "false";

    if(sHideCurtains == "true") {sReturn = "no-curtains-thickbox";}
		
    return sReturn;
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
        var sCurtainsClass = "class='" + returnCurtainsClass(url) + "'";  

		//AS2 flash video to be stopped on presentation of thickbox (legacy)
		if (typeof(flashInterface) == 'function')
		{	stopVideo('main_movie') //this value is hard-coded for the range and model page 
		}
		//AS3 flash application to be paused on presentation of thickbox for optimisation (level of 'pause' controlled by Flash)
		try{
				if (typeof(fiPageComm) == 'function')
				{	var oPause = {type: 'pause', flashID: 'main_movie'};
					fiPageComm(oPause);  
					oPause = null;
				}
		}
		catch(e){//alert('tb>pause error\n'+e);
		}
		
	try {
		if (typeof top.document.body.style.maxHeight === "undefined") {//if IE 6
			$("body", top.document).css({height: "100%", width: "100%"});
			$("html", top.document).css("overflow","hidden");
			if (top.document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body", top.document).append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window' " + sCurtainsClass + "></div>");
				$("#TB_overlay", top.document).click(tb_remove);
			}
		}else{//all others
			if(top.document.getElementById("TB_overlay") === null){
				$("body", top.document).append("<div id='TB_overlay'></div><div id='TB_window' " + sCurtainsClass + "></div>");
				$("#TB_overlay", top.document).click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay", top.document).addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay", top.document).addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body", top.document).append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load', top.document).show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window", top.document).append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img alt='' src='/images/popup-close-button.gif'/></a></div>"); 		
			
			$("#TB_closeWindowButton", top.document).click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(top.document).unbind("click",goPrev)){$(top.document).unbind("click",goPrev);}
					$("#TB_window", top.document).remove();
					$("body", top.document).append("<div id='TB_window' " + sCurtainsClass + "></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev", top.document).click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window", top.document).remove();
					$("body", top.document).append("<div id='TB_window' " + sCurtainsClass + "></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next", top.document).click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load", top.document).remove();
			$("#TB_ImageOff", top.document).click(tb_remove);
			$("#TB_window", top.document).css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					
					try {//remove trailing ampersand as can corrupt deeplinks for flash etc.
						urlNoQuery[0]=urlNoQuery[0].replace(/&$/,"");}
					catch(e){
					}
					$("#TB_iframeContent", top.document).remove();

					// Lexus Customisation - modal turned off until CTA can be brought in sync
					//if(params['modal'] != "true"){//iframe no modal

						$("#TB_window", top.document).append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img alt='' src='/images/popup-close-button.gif'/></a></div></div><iframe " + (params['transparency'] != 'true' ? '' : 'allowTransparency=true') + " frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					//}else{//iframe modal
					//$("#TB_overlay").unbind();
					//	$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					//}
					// End Lexus customisation

			}else{// not an iframe, ajax
					if($("#TB_window", top.document).css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window", top.document).append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><img alt='' src='/images/popup-close-button.gif'/></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay", top.document).unbind();
						$("#TB_window", top.document).append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent", top.document)[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent", top.document)[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent", top.document)[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle", top.document).html(caption);
					}
			}
					
			$("#TB_closeWindowButton", top.document).click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent", top.document).append($('#' + params['inlineId']).children());
					$("#TB_window", top.document).unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent", top.document).children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load", top.document).remove();
					$("#TB_window", top.document).css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load", top.document).remove();
						$("#TB_window", top.document).css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent", top.document).load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load", top.document).remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window", top.document).css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
                $("#map2", top.document).css({margin:"0 0 0 900px"});

	$("#TB_load", top.document).remove();
	$("#TB_window", top.document).css({display:"block"});
}

// Lexus Customisation - expose pre-close method to iframe content
var tb_obj={} //must be created here to allow scope to add function in form    
tb_obj.preCloseFunction = null;
tb_obj.removeiFrameContent = false;
// END Lexus Customisation - expose pre-close method to iframe content

function tb_remove() {
    // Lexus Customisation - expose pre-close method to iframe content
    if(typeof(tb_obj.preCloseFunction) == 'function')
    {   if (tb_obj.preCloseFunction() == false)
        {   return false;
        }
    }
    
    tb_obj.preCloseFunction = null; //reset as null we don't want any other form to inherit passed (past) functions
    
    if(tb_obj.removeiFrameContent)
    {   $("#TB_iframeContent", top.document).remove();    
        tb_obj.removeiFrameContent = false; //reset as false we don't want any other form to inherit passed (past) values
    }
    // END Lexus Customisation - expose pre-close method to iframe content

    $("#TB_imageOff", top.document).unbind("click");
    $("#TB_closeWindowButton", top.document).unbind("click");
    $("#TB_window", top.document).fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect', top.document).trigger("unload").unbind().remove();});
    $("#TB_load", top.document).remove();
    if (typeof top.document.body.style.maxHeight == "undefined") {//if IE 6
	    $("body", top.document).css({height: "auto", width: "auto"});
	    $("html", top.document).css("overflow","");
    }

    document.onkeydown = "";
    document.onkeyup = "";
    $("#map2", top.document).css({margin:"0 0 0 0"});

	//AS3 flash application to be paused on presentation of thickbox for optimisation (level of 'pause' controlled by Flash)
	try{
			if (typeof(fiPageComm) == 'function')
			{	var oRestart = {type: 'restart', flashID: 'main_movie'};
				fiPageComm(oRestart);  
				oRestart = null;
			}
	}
	catch(e){//alert('tb> restart error\n'+e);
	}
	

    return false;
}

function tb_position() {
$("#TB_window", top.document).css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window", top.document).css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

/* Code for TB overlay */

// Parse the current page's querystring
var q,u,w,h;
// We'll use Thickbox's querystring parser, so a dependency here on thickbox.js
q = tb_getQueryStringParams(window.location.href);  

// Defaults
dh = "463";
dw = "610";
dm = "true";
dt = "false";
dhc = "false";

u = (q['page']) ? q['page'] : "";
h = (q['height']) ? q['height'] : dh;
w = (q['width']) ? q['width'] : dw;  
m = (q['modal']) ? q['modal'] : dm;  

t = (q['transparency']) ? q['transparency'] : dt;  //MS: added for default transparency (to allow override)
hc = (q['hidecurtains']) ? q['hidecurtains'] : dhc;  //MS: added for default hidecurtains (to allow override)

if ((parseInt(h) > 1000) || (isNaN(h))) { h = q['height'] = dh; }
if ((parseInt(w) > 1000) || (isNaN(w))) { w = q['width'] = dw; }
if ((m != "true") && (m != "false")) { m = q['modal'] = dm; }

// Have to use this as $(document).ready() due to issues with SWFObject
$(document).ready(function() {
    if ((u != "") && (/^[\/|http]{1}/.test(u))) {
        /*  page=[must be URL Encoded for querystring params to function]  */
        u = unescape(u); //we need to check page param has querystring indicator already
        //see if we have ? in order to append the TB_iframe params prefixed with ? or &
        if(u.indexOf("?")!==-1){ u += '&'; }
        else { u += '?'; }

        var form = u + "TB_iframe=true&height=" + h + "&width=" + w + "&modal=" + m +"&transparency=" + t + "&hidecurtains=" + hc

        tb_show('', form);
    } 
});


// opens an overlay window - default is thickbox script directly - used for Flash overlays
function openOverlay(jObj)
{   var url = jObj.params.url;
    var title = typeof(jObj.params.title) != 'undefined' ? jObj.params.title : null;
    var overlayType = typeof(jObj.params.overlayType) != 'undefined' ? jObj.params.overlayType : "thickbox";
    
    if(overlayType == "thickbox");
    {   try {
            var p=tb_getQueryStringParams(url);
            tb_show(title||null,url,false,p);
            return false;
        }
        catch(e){}
    }
    //extend for other overlay types here
}

//This script will resize the thickbox overlay iframe such that if the requested height is > than the available area will fix to top of view
$(document).ready(function(){
	var theHeight = $(window).height();
	var boxHeights = new Array();
	var minHeight = 0;	$('a.thickbox').each(function()
	{	linkParams = this.href.split('&');
		for(var i=0; i<linkParams.length; i++)
		{	if(linkParams[i].indexOf('height=') >= 0)
			{	boxHeights.push(linkParams[i].substr(7, linkParams[i].length));
			}
		}
	});

	boxHeights.sort(function(a,b){return a - b});
	minHeight = boxHeights[boxHeights.length-1];
	
	$(window).bind('load resize', function()
	{	theHeight = $(window).height();
		if(theHeight < minHeight)
		{	if($.browser.msie && $.browser.version <= 6)
			{	//call this function as we have issues acquiring heights etc in IE6 at this point
				tb_ie6resize();
			}
			else
			{	$('#TB_window').css(
				{	'margin-top' : '0px',
						'top' : $(window).scrollTop() + 'px',
						'position' : 'absolute'
				});
			}
		}
		else
		{	if($.browser.msie && $.browser.version <= 6)
			{	//call this function as we have issues acquiring heights etc in IE6 at this point
				tb_ie6resize();
			}
			else
			{	$('#TB_window').css(
				{	'position' : 'fixed',
					'margin-top' : '-' + $('#TB_window').outerHeight() / 2 + 'px',
					'top' : '50%'
				});
			}
		}

		$('a.thickbox').click(function()
		{	linkParams = this.href.split('&');
			for(var i=0; i<linkParams.length; i++)
			{	if(linkParams[i].indexOf('height=') >= 0)
				{	minHeight = linkParams[i].substr(7, linkParams[i].length);
				}
			}	if(theHeight < minHeight)
			{	$('#TB_window').css(
				{	'margin-top' : '0px',
					'top' : $(window).scrollTop() + 'px',
					'position' : 'absolute'
				});
			}
		});
	});
});

function tb_ie6resize()
{	$('a.thickbox').each(function(){
		var text = $(this).attr("href");
		var height = /oh=(\d+)*/i.exec(text);
		var width = /ow=(\d+)*/i.exec(text);
		if (height == null && width == null){
			var height = /height=(\d+)*/i.exec(text);
			var width = /width=(\d+)*/i.exec(text);

			text = text + "&amp;oh=" + height[1] + "&amp;ow=" + width[1];
		}
		if ($(window).height() < height[1]){
			text = text.replace(/height=[0-9]*/,'height=' + ($(window).height() - 50));
			text = text.replace(/width=[0-9]*/,'width=' + (Math.round(width[1]) + 10));
		} else {
			text = text.replace(/height=[0-9]*/,'height=' + height[1]);
			text = text.replace(/width=[0-9]*/,'width=' + width[1]);
		}
		$(this).attr("href", text);
	});
}










/*
 * 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 '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 '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 '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);
