$(document).ready(function() {
	var currPage = window.location.href;
	var currTitle = document.title;
	jQuery.fn.exists = function() { return jQuery(this).length > 0; }
	cssLink = $('link[title="main"]').attr('href').split('/');
	currStyleSheet = cssLink[cssLink.length - 1].split('.');
	currStyleSheet = currStyleSheet[0];

	//--------------------------------------------------------
	// Report page individual report links expand
	//--------------------------------------------------------
	$("a.reportLink").click(function(e) {
	if ($(this).hasClass("up")) {
		$(this).next().slideDown('fast');
		$(this).prev().removeClass('arrowUp').addClass('arrowDown');
		$(this).removeClass("up").addClass("down");
	} else if ($(this).hasClass("down")) {
		$(this).next().slideUp('fast');
		$(this).prev().removeClass('arrowDown').addClass('arrowUp');
		$(this).removeClass("down").addClass("up");
	}
	e.preventDefault();
	});

	//--------------------------------------------------------
	// Report page expand all link
	//--------------------------------------------------------
		$("a.reportLink").next().slideUp('fast');
		$("a.reportLink").prev().removeClass('arrowDown').addClass('arrowUp');
		$("a.reportLink").removeClass("down").addClass("up");

	/*$("#products > p > a.expandLink").toggle(function() {
		$("a.reportLink").next().slideDown('slow');
		$("a.reportLink").prev().removeClass('arrowUp').addClass('arrowDown');
		$("a.reportLink").removeClass("up").addClass("down");
		$(this).text("hide all");
	}, function() {
		$("a.reportLink").next().slideUp('fast');
		$("a.reportLink").prev().removeClass('arrowDown').addClass('arrowUp');
		$("a.reportLink").removeClass("down").addClass("up");
		$(this).text("expand all");
	});
*/
	//--------------------------------------------------------
	// highlight active tab
	//--------------------------------------------------------
	var pageTitleH1 = $('h1').text();
	var pageTitleH2 = $('h2').text();
	var bCrumb = $('p.breadCrumbs, p.breadCrumbsImg').text();
	if ((pageTitleH1.indexOf("Sample") != -1) || (pageTitleH2.indexOf("Sample") != -1) || (bCrumb.indexOf('Sample') != -1)) {
		$('.mmpi2Link, .mmpi2').removeClass('inactive').addClass('active');
	}
	if ((pageTitleH1.indexOf('Publications') != -1) || (pageTitleH2.indexOf('Publications') != -1) || (bCrumb.indexOf('Publications') != -1)) {
		$('.productsLink, .products').removeClass('inactive').addClass('active');
	}
	if ((pageTitleH1.indexOf('Essays') != -1) || (pageTitleH2.indexOf('Essays') != -1) || (bCrumb.indexOf('Essays') != -1)) {
		$('.essaysLink, .essays').removeClass('inactive').addClass('active');
	}
	if ((pageTitleH1.indexOf('Continuing') != -1) || (pageTitleH2.indexOf('Continuing') != -1) || (bCrumb.indexOf('Continuing') != -1)) {
		$('.ceLink, .ce').removeClass('inactive').addClass('active');
	}

 	//--------------------------------------------------------
	// animate side bar on front page only
 	//--------------------------------------------------------
	if (currTitle.indexOf('MMPI-2 Reporting, Scoring, and Resources') != -1) {
		$('#prodSpot').show('fast', function() {
			$(this).next('div').show('fast', arguments.callee);
		});
		$('#prodSpot, #newClient, #contactUs').css({ display: 'block' });
	}

	//--------------------------------------------------------
	// needed for sample reports home page
	//--------------------------------------------------------
	$('.appsLink').hover(function() {
		$(this).css('background-color', '#CCC9C4');
	}, function() {
		$(this).css('background-image', 'url(images/blueTrans.png)');
		$(this).css('background-color', '');
	});
	
	//--------------------------------------------------------
	// more/less toggle link
	//--------------------------------------------------------
	$('.more').toggle(function(e) {
		$(this).parent().find('blockquote').show();
		e.preventDefault();
	}, function(e) {
		$(this).parent().find('blockquote').hide();
		e.preventDefault();
	});
	
	//--------------------------------------------------------
	// search box, make enter key do search as well
	//--------------------------------------------------------
	$('#searchButton').click(function() {
		var searchString = $('#q').attr('value');
		var searchURL = "http://www.caldwellreport.com/googlesearch.aspx?cx=017031868135475026973%3A8m6_cy9muoy&cof=FORID%3A11&ie=UTF-8&q=" + escape(searchString);
		$(window.location).attr('href', searchURL);
	});
	
	$('#q').keypress(function(e) {
		if (window.event)
			keycode = window.event.keyCode;
		else if (e)
			keycode = e.which;
		else
			return true;
		if (keycode == 13) {
			SearchSite();
			return false;
		}
		else
			return true;
	});
	
	//----------------------------------
	// Init colorbox for product images
	//----------------------------------
	$('a.productImg').colorbox();
	
	//--------------------------------------------------------
	// Create link for reading mode with a scrolling effect
	//--------------------------------------------------------
	$('#readingMode').live('click', function(e) {
		if ($('link[title="main"]').attr('href').indexOf(currStyleSheet + '.css') != -1) {
		var styleStr = $("link[title='main']").attr('href');
		styleStr = styleStr.replace(RegExp(currStyleSheet, 'i'), 'print');
		$('link[title="main"]').attr('href', styleStr);
		$(this).text('Back to Original');
		e.preventDefault();
	} else {
		var styleStr = $('link[title="main"]').attr('href');
		styleStr = styleStr.replace(/print/i, currStyleSheet);
		$('link[title="main"]').attr('href', styleStr);
		$(this).text('View in Plain Text');
		e.preventDefault();
	}
	});
	
	$('#readingMode').show('slow', 'easeInQuad');
		
	//---------------------------------------------
	// move Wizard next/prev buttons to bottom/top 
	//---------------------------------------------
	var pButton = $('#ctl00_CPH_content_mmpi2Test_FinishNavigationTemplateContainerID_FinishPreviousButton, #ctl00_CPH_content_mmpi2Test_StepNavigationTemplateContainerID_StepPreviousButton');
	var pParents = pButton.parents('tbody');
	pParents.each(function(i) {
		if (i == 1) {
			// $(this).prepend('<tr><td>');
			// $(this).children('tr:first-child').children('td:first-child').prepend(pButton);
			$(this).prepend(pButton);
			pButton.wrap('<tr><td>');
		}
	});
	var nButton = $('#ctl00_CPH_content_mmpi2Test_StartNavigationTemplateContainerID_StartNextButton, #ctl00_CPH_content_mmpi2Test_StepNavigationTemplateContainerID_StepNextButton, #ctl00_CPH_content_mmpi2Test_FinishNavigationTemplateContainerID_FinishButton');
	var nParents = nButton.parents('tr');
	nParents.each(function(i) { if (i == 1) { $(this).prev().children(0).append('<br /><br />').append(nButton); } });
	
	//----------------------
	// add navigation label
	//----------------------
	$('#ctl00_CPH_content_mmpi2Test_SideBarContainer_SideBarList').prepend('<th>Jump to <br />Questions:<br /></th>');
	
	//----------------------
	// Home page next link
	//----------------------
	$('a.nextLink').delay(5000).fadeIn(400).animate({ "right": "-=50px" }, 'slow', 'easeOutBounce');	
	
	//-------------------------------------------------------------------------------
	// Hide Nav Menu for all sample reports pages after the main sample reports page
	//-------------------------------------------------------------------------------
	if ((currTitle.indexOf('MMPI-2 Report Samples and Applications') != -1) &&
	(currPage.indexOf('sample_mmpi2_reports.aspx') == -1)) {
		$('#ul-left, #ul-right').hide();
		$('#mainOptions').css({ "height": "50px" });
		// $('#mainOptions').animate({ "height": "50px" }, 'slow');
		$('#mainOptions').hover(function() { $(this).removeAttr('style'); $('#ul-left, #ul-right').show(); },
		function() { $(this).css({ "height": "50px" }); $('#ul-left, #ul-right').hide(); });
	}	

	//--------------------------------------------------------------
	// Display Download Report link if this is a sample report page
	//--------------------------------------------------------------
	if (currPage.match(/\d\d\d\d_profile/g) != null) {
	$('#dlLink').show();
	$('#reportDownload').show().append($('#dlLink')).append('<img src="images/icons/pdf_icon.png" alt="pdf" width="20" height="20" style="float:none;">');
	}

	//---------------------------------------
	// New client and contact div scrolling
	//---------------------------------------
	var placeholder = $("#placeHolder");
	
	var newClient = $("#newClient");
	var contactUs = $("#contactUs");
	var reportDL  = $("#reportDownload");
	
	var view = $(window);
	var topCutOff = (reportDL.is(':visible')) ? 640 : 485;

	if (placeholder.exists()) {
		view.bind(
		"scroll resize",
		function() {
			var placeholderTop = placeholder.offset().top;
			var viewTop = view.scrollTop();
			if ((viewTop > placeholderTop) && !newClient.is(".fixedTop")) {
				placeholder.height( placeholder.height() );
				// Make the message fixed.
				contactUs.addClass("fixedTop");
				newClient.addClass("fixedOffset");
				if (reportDL.is(':visible')){reportDL.addClass("fixedOffset2");}
			} else if ((viewTop <= placeholderTop) && contactUs.is(".fixedTop")) {
				placeholder.css("height", "auto");				
				contactUs.removeClass("fixedTop");
				newClient.removeClass("fixedOffset");
				if (reportDL.is(':visible')){reportDL.removeClass("fixedOffset2");}
			}
			// adjust for small windows
			if ($(document).height() - $('#newClient').offset().top < topCutOff) {
				contactUs.removeClass("fixedTop");
				newClient.removeClass("fixedOffset");
				if (reportDL.is(':visible')){reportDL.removeClass("fixedOffset2");}
			}
		});
	}
	
	
	//------------------------------------------
	// highlight focus fields in contact page
	//------------------------------------------
	if ($('#ContactUsCaptchaWebForm').exists()) {
		$('input, textarea').focus(function() { $(this).parents('tr').css('background-color', '#FEF3D2'); });
		$('input, textarea').blur(function() { $(this).parents('tr').css('background-color', ''); });
	}
	
	//--------------------------------------------------------
	// do not display new client link on new client page
	//--------------------------------------------------------
	if (currTitle.indexOf("New Client Information") != -1) {
		$('#newClient').css('display','none');
	}
	if (currTitle.indexOf("Contact") != -1) {
		$('#contactUs').css('display','none');
	}
	
	
	//----------------------------------------------------------
	// MAC computers wrap "reports & publications" nav item
	//----------------------------------------------------------
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				   string: navigator.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();
	
//	if (BrowserDetect.OS == 'Mac') {
//		$('.navWrap').each(function(index) {
//			$(this).css('padding-top','20px');
			//if (BrowserDetect.browser != 'Firefox' && index == 1) {
//				$(this).css('padding-top','25px');
//			}
//		});
//	}
	if (BrowserDetect.OS == 'Mac' && BrowserDetect.browser == 'Firefox') {
		$('.sideContain img').css('top','-130px');
	}
	if (BrowserDetect.browser == 'Opera') {
		$('#menuBar, #c1, #shadowBar').css('left','-1px');
	}
}); // end $(document).ready()
	
function SearchSite() {
	var searchString = $('#q').attr('value');
	var searchURL = "http://www.caldwellreport.com/googlesearch.aspx?cx=017031868135475026973%3A8m6_cy9muoy&cof=FORID%3A11&ie=UTF-8&q=" + escape(searchString);
	$(window.location).attr('href', searchURL);
}

//----------------------
// ajax addthis setup
//----------------------
function initAddThis() {
	var addthis_config = {
	data_track_clickback: true
	}
	if (addthis) {
		addthis.init()
	}
}

function timedRefresh(timeoutPeriod) {
	setTimeout('location.reload(true);', timeoutPeriod);
}

function translate(lan) {
	window.open('http://www.windowslivetranslator.com/BV.aspx?ref=AddIn&lp='+lan+'&a='+encodeURIComponent(location.href) );
}

/*
* jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
*
* Uses the built In easIng capabilities added In jQuery 1.1
* to offer multiple easIng options
*
* Copyright (c) 2007 George Smith
* Licensed under the MIT License:
*   http://www.opensource.org/licenses/mit-license.php
*/

// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend( jQuery.easing,
{
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
}
});

//IEpngFIX
var IEPNGFix=window.IEPNGFix||{};IEPNGFix.tileBG=function(elm,pngSrc,ready){var data=this.data[elm.uniqueID],elmW=Math.max(elm.clientWidth,elm.scrollWidth),elmH=Math.max(elm.clientHeight,elm.scrollHeight),bgX=elm.currentStyle.backgroundPositionX,bgY=elm.currentStyle.backgroundPositionY,bgR=elm.currentStyle.backgroundRepeat;if(!data.tiles){data.tiles={elm:elm,src:'',cache:[],img:new Image(),old:{}}}var tiles=data.tiles,pngW=tiles.img.width,pngH=tiles.img.height;if(pngSrc){if(!ready&&pngSrc!=tiles.src){tiles.img.onload=function(){this.onload=null;IEPNGFix.tileBG(elm,pngSrc,1)};return tiles.img.src=pngSrc}}else{if(tiles.src)ready=1;pngW=pngH=0}tiles.src=pngSrc;if(!ready&&elmW==tiles.old.w&&elmH==tiles.old.h&&bgX==tiles.old.x&&bgY==tiles.old.y&&bgR==tiles.old.r){return}var pos={top:'0%',left:'0%',center:'50%',bottom:'100%',right:'100%'},x,y,pc;x=pos[bgX]||bgX;y=pos[bgY]||bgY;if(pc=x.match(/(\d+)%/)){x=Math.round((elmW-pngW)*(parseInt(pc[1])/100))}if(pc=y.match(/(\d+)%/)){y=Math.round((elmH-pngH)*(parseInt(pc[1])/100))}x=parseInt(x);y=parseInt(y);var repeatX={'repeat':1,'repeat-x':1}[bgR],repeatY={'repeat':1,'repeat-y':1}[bgR];if(repeatX){x%=pngW;if(x>0)x-=pngW}if(repeatY){y%=pngH;if(y>0)y-=pngH}this.hook.enabled=0;if(!({relative:1,absolute:1}[elm.currentStyle.position])){elm.style.position='relative'}var count=0,xPos,maxX=repeatX?elmW:x+0.1,yPos,maxY=repeatY?elmH:y+0.1,d,s,isNew;if(pngW&&pngH){for(xPos=x;xPos<maxX;xPos+=pngW){for(yPos=y;yPos<maxY;yPos+=pngH){isNew=0;if(!tiles.cache[count]){tiles.cache[count]=document.createElement('div');isNew=1}var clipR=Math.max(0,xPos+pngW>elmW?elmW-xPos:pngW),clipB=Math.max(0,yPos+pngH>elmH?elmH-yPos:pngH);d=tiles.cache[count];s=d.style;s.behavior='none';s.left=(xPos-parseInt(elm.currentStyle.paddingLeft))+'px';s.top=yPos+'px';s.width=clipR+'px';s.height=clipB+'px';s.clip='rect('+(yPos<0?0-yPos:0)+'px,'+clipR+'px,'+clipB+'px,'+(xPos<0?0-xPos:0)+'px)';s.display='block';if(isNew){s.position='absolute';s.zIndex=-999;if(elm.firstChild){elm.insertBefore(d,elm.firstChild)}else{elm.appendChild(d)}}this.fix(d,pngSrc,0);count++}}}while(count<tiles.cache.length){this.fix(tiles.cache[count],'',0);tiles.cache[count++].style.display='none'}this.hook.enabled=1;tiles.old={w:elmW,h:elmH,x:bgX,y:bgY,r:bgR}};IEPNGFix.update=function(){for(var i in IEPNGFix.data){var t=IEPNGFix.data[i].tiles;if(t&&t.elm&&t.src){IEPNGFix.tileBG(t.elm,t.src)}}};IEPNGFix.update.timer=0;if(window.attachEvent&&!window.opera){window.attachEvent('onresize',function(){clearTimeout(IEPNGFix.update.timer);IEPNGFix.update.timer=setTimeout(IEPNGFix.update,100)})}

//jQuery colorbox
// ColorBox v1.3.9 - a full featured, light-weight, customizable lightbox based on jQuery 1.3
// c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
(function(b,gb){var v="none",t="click",N="LoadedContent",d=false,x="resize.",o="y",u="auto",f=true,M="nofollow",q="on",n="x";function e(a,c){a=a?' id="'+k+a+'"':"";c=c?' style="'+c+'"':"";return b("<div"+a+c+"/>")}function p(a,b){b=b===n?m.width():m.height();return typeof a==="string"?Math.round(a.match(/%/)?b/100*parseInt(a,10):parseInt(a,10)):a}function Q(c){c=b.isFunction(c)?c.call(h):c;return a.photo||c.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function cb(){for(var c in a)if(b.isFunction(a[c])&&c.substring(0,2)!==q)a[c]=a[c].call(h);a.rel=a.rel||h.rel||M;a.href=a.href||b(h).attr("href");a.title=a.title||h.title}function db(d){h=d;a=b.extend({},b(h).data(r));cb();if(a.rel!==M){i=b("."+H).filter(function(){return (b(this).data(r).rel||this.rel)===a.rel});g=i.index(h);if(g===-1){i=i.add(h);g=i.length-1}}else{i=b(h);g=0}if(!w){w=F=f;R=h;try{R.blur()}catch(e){}b.event.trigger(hb);a.onOpen&&a.onOpen.call(h);y.css({opacity:+a.opacity,cursor:a.overlayClose?"pointer":u}).show();a.w=p(a.initialWidth,n);a.h=p(a.initialHeight,o);c.position(0);S&&m.bind(x+O+" scroll."+O,function(){y.css({width:m.width(),height:m.height(),top:m.scrollTop(),left:m.scrollLeft()})}).trigger("scroll."+O)}T.add(I).add(J).add(z).add(U).hide();V.html(a.close).show();c.slideshow();c.load()}var eb={transition:"elastic",speed:300,width:d,initialWidth:"600",innerWidth:d,maxWidth:d,height:d,initialHeight:"450",innerHeight:d,maxHeight:d,scalePhotos:f,scrolling:f,inline:d,html:d,iframe:d,photo:d,href:d,title:d,rel:d,opacity:.9,preloading:f,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:d,loop:f,slideshow:d,slideshowAuto:f,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:d,onLoad:d,onComplete:d,onCleanup:d,onClosed:d,overlayClose:f,escKey:f,arrowKey:f},r="colorbox",k="cbox",hb=k+"_open",P=k+"_load",W=k+"_complete",X=k+"_cleanup",fb=k+"_closed",G=b.browser.msie&&!b.support.opacity,S=G&&b.browser.version<7,O=k+"_IE6",y,j,E,s,Y,Z,ab,bb,i,m,l,K,L,U,T,z,J,I,V,C,D,A,B,h,R,g,a,w,F,c,H=k+"Element";c=b.fn[r]=b[r]=function(c,d){var a=this;if(!a[0]&&a.selector)return a;c=c||{};if(d)c.onComplete=d;if(!a[0]||a.selector===undefined){a=b("<a/>");c.open=f}a.each(function(){b(this).data(r,b.extend({},b(this).data(r)||eb,c)).addClass(H)});c.open&&db(a[0]);return a};c.init=function(){var h="hover";m=b(gb);j=e().attr({id:r,"class":G?k+"IE":""});y=e("Overlay",S?"position:absolute":"").hide();E=e("Wrapper");s=e("Content").append(l=e(N,"width:0; height:0"),L=e("LoadingOverlay").add(e("LoadingGraphic")),U=e("Title"),T=e("Current"),J=e("Next"),I=e("Previous"),z=e("Slideshow"),V=e("Close"));E.append(e().append(e("TopLeft"),Y=e("TopCenter"),e("TopRight")),e().append(Z=e("MiddleLeft"),s,ab=e("MiddleRight")),e().append(e("BottomLeft"),bb=e("BottomCenter"),e("BottomRight"))).children().children().css({"float":"left"});K=e(d,"position:absolute; width:9999px; visibility:hidden; display:none");b("body").prepend(y,j.append(E,K));s.children().hover(function(){b(this).addClass(h)},function(){b(this).removeClass(h)}).addClass(h);C=Y.height()+bb.height()+s.outerHeight(f)-s.height();D=Z.width()+ab.width()+s.outerWidth(f)-s.width();A=l.outerHeight(f);B=l.outerWidth(f);j.css({"padding-bottom":C,"padding-right":D}).hide();J.click(c.next);I.click(c.prev);V.click(c.close);s.children().removeClass(h);b("."+H).live(t,function(a){if(a.button!==0&&typeof a.button!=="undefined"||a.ctrlKey||a.shiftKey||a.altKey)return f;else{db(this);return d}});y.click(function(){a.overlayClose&&c.close()});b(document).bind("keydown",function(b){if(w&&a.escKey&&b.keyCode===27){b.preventDefault();c.close()}if(w&&a.arrowKey&&!F&&i[1])if(b.keyCode===37&&(g||a.loop)){b.preventDefault();I.click()}else if(b.keyCode===39&&(g<i.length-1||a.loop)){b.preventDefault();J.click()}})};c.remove=function(){j.add(y).remove();b("."+H).die(t).removeData(r).removeClass(H)};c.position=function(f,b){function c(a){Y[0].style.width=bb[0].style.width=s[0].style.width=a.style.width;L[0].style.height=L[1].style.height=s[0].style.height=Z[0].style.height=ab[0].style.height=a.style.height}var e,h=Math.max(m.height()-a.h-A-C,0)/2+m.scrollTop(),g=Math.max(m.width()-a.w-B-D,0)/2+m.scrollLeft();e=j.width()===a.w+B&&j.height()===a.h+A?0:f;E[0].style.width=E[0].style.height="9999px";j.dequeue().animate({width:a.w+B,height:a.h+A,top:h,left:g},{duration:e,complete:function(){c(this);F=d;E[0].style.width=a.w+B+D+"px";E[0].style.height=a.h+A+C+"px";b&&b()},step:function(){c(this)}})};c.resize=function(b){if(w){b=b||{};if(b.width)a.w=p(b.width,n)-B-D;if(b.innerWidth)a.w=p(b.innerWidth,n);l.css({width:a.w});if(b.height)a.h=p(b.height,o)-A-C;if(b.innerHeight)a.h=p(b.innerHeight,o);if(!b.innerHeight&&!b.height){b=l.wrapInner("<div style='overflow:auto'></div>").children();a.h=b.height();b.replaceWith(b.children())}l.css({height:a.h});c.position(a.transition===v?0:a.speed)}};c.prep=function(o){var d="hidden";function n(t){var o,q,s,n,d=i.length,e=a.loop;c.position(t,function(){function t(){G&&j[0].style.removeAttribute("filter")}if(w){G&&p&&l.fadeIn(100);a.iframe&&b("<iframe frameborder=0"+(a.scrolling?"":" scrolling='no'")+(G?" allowtransparency='true'":"")+"/>").attr({src:a.href,name:(new Date).getTime()}).appendTo(l);l.show();U.show().html(a.title);if(d>1){T.html(a.current.replace(/\{current\}/,g+1).replace(/\{total\}/,d)).show();J[e||g<d-1?"show":"hide"]().html(a.next);I[e||g?"show":"hide"]().html(a.previous);o=g?i[g-1]:i[d-1];s=g<d-1?i[g+1]:i[0];if(a.slideshow){z.show();g===d-1&&!e&&j.is("."+k+"Slideshow_on")&&z.click()}if(a.preloading){n=b(s).data(r).href||s.href;q=b(o).data(r).href||o.href;if(Q(n))b("<img/>")[0].src=n;if(Q(q))b("<img/>")[0].src=q}}L.hide();a.transition==="fade"?j.fadeTo(f,1,function(){t()}):t();m.bind(x+k,function(){c.position(0)});b.event.trigger(W);a.onComplete&&a.onComplete.call(h)}})}if(w){var p,f=a.transition===v?0:a.speed;m.unbind(x+k);l.remove();l=e(N).html(o);l.hide().appendTo(K.show()).css({width:function(){a.w=a.w||l.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}(),overflow:a.scrolling?u:d}).css({height:function(){a.h=a.h||l.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}()}).prependTo(s);K.hide();b("#"+k+"Photo").css({cssFloat:v});S&&b("select").not(j.find("select")).filter(function(){return this.style.visibility!==d}).css({visibility:d}).one(X,function(){this.style.visibility="inherit"});a.transition==="fade"?j.fadeTo(f,0,function(){n(0)}):n(f)}};c.load=function(){var j,d,q,m=c.prep;F=f;h=i[g];a=b.extend({},b(h).data(r));cb();b.event.trigger(P);a.onLoad&&a.onLoad.call(h);a.h=a.height?p(a.height,o)-A-C:a.innerHeight&&p(a.innerHeight,o);a.w=a.width?p(a.width,n)-B-D:a.innerWidth&&p(a.innerWidth,n);a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=p(a.maxWidth,n)-B-D;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=p(a.maxHeight,o)-A-C;a.mh=a.h&&a.h<a.mh?a.h:a.mh}j=a.href;L.show();if(a.inline){e("InlineTemp").hide().insertBefore(b(j)[0]).bind(P+" "+X,function(){b(this).replaceWith(l.children())});m(b(j))}else if(a.iframe)m(" ");else if(a.html)m(a.html);else if(Q(j)){d=new Image;d.onload=function(){var e;d.onload=null;d.id=k+"Photo";b(d).css({margin:u,border:v,display:"block",cssFloat:"left"});if(a.scalePhotos){q=function(){d.height-=d.height*e;d.width-=d.width*e};if(a.mw&&d.width>a.mw){e=(d.width-a.mw)/d.width;q()}if(a.mh&&d.height>a.mh){e=(d.height-a.mh)/d.height;q()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";setTimeout(function(){m(d)},1);i[1]&&(g<i.length-1||a.loop)&&b(d).css({cursor:"pointer"}).click(c.next);if(G)d.style.msInterpolationMode="bicubic"};d.src=j}else e().appendTo(K).load(j,function(c,a,b){m(a==="error"?"Request unsuccessful: "+b.statusText:this)})};c.next=function(){if(!F){g=g<i.length-1?g+1:0;c.load()}};c.prev=function(){if(!F){g=g?g-1:i.length-1;c.load()}};c.slideshow=function(){function f(){z.text(a.slideshowStop).bind(W,function(){d=setTimeout(c.next,a.slideshowSpeed)}).bind(P,function(){clearTimeout(d)}).one(t,function(){e()});j.removeClass(b+"off").addClass(b+q)}var e,d,b=k+"Slideshow_";z.bind(fb,function(){z.unbind();clearTimeout(d);j.removeClass(b+"off "+b+q)});e=function(){clearTimeout(d);z.text(a.slideshowStart).unbind(W+" "+P).one(t,function(){f();d=setTimeout(c.next,a.slideshowSpeed)});j.removeClass(b+q).addClass(b+"off")};if(a.slideshow&&i[1])a.slideshowAuto?f():e()};c.close=function(){if(w){w=d;b.event.trigger(X);a.onCleanup&&a.onCleanup.call(h);m.unbind("."+k+" ."+O);y.fadeTo("fast",0);j.stop().fadeTo("fast",0,function(){j.find("iframe").attr("src","about:blank");l.remove();j.add(y).css({opacity:1,cursor:u}).hide();try{R.focus()}catch(c){}setTimeout(function(){b.event.trigger(fb);a.onClosed&&a.onClosed.call(h)},1)})}};c.element=function(){return b(h)};c.settings=eb;b(c.init)})(jQuery,this)
