$(function(){
	$("#menu").tabs("#menu .sub_section", {tabs: 'h2', effect: 'slide', onClick: function(){ }});
	$("#photocontainer_home").photoCycle();
	$("a[rel='example1']").colorbox({opacity:0.9});
});

/*****************
 * BEGIN PLUGINS *
 *****************/

/**
* jQuery Google Map Helper
**/
(function(c){c.fn.googleMap=function(a){var e={address:!1,LatLng:[0,0],zoom:8,icon:!1,alt:!1,mapType:"roadmap",onGeocodeError:function(){}},a=c.extend(e,a);return this.each(function(){var f=c(this)[0],g=new google.maps.LatLng(a.LatLng[0],a.LatLng[1]),b;switch(a.mapType){case "roadmap":b=google.maps.MapTypeId.ROADMAP;break;case "satellite":b=google.maps.MapTypeId.SATELLITE;break;case "hybrid":b=google.maps.MapTypeId.HYBRID;break;case "terrain":b=google.maps.MapTypeId.TERRAIN}var d=new google.maps.Map(f, {zoom:a.zoom,center:g,mapTypeId:b});a.address&&(new google.maps.Geocoder).geocode({address:a.address},function(b,c){c==google.maps.GeocoderStatus.OK?(d.setCenter(b[0].geometry.location),a.icon?new google.maps.Marker({map:d,position:b[0].geometry.location,icon:a.icon}):new google.maps.Marker({map:d,position:b[0].geometry.location})):c==google.maps.GeocoderStatus.ZERO_RESULTS&&e.onGeocodeError.call(this)})})}})(jQuery);

/**
 * OTHER PLUG-INS
 */

/*
 * jQuery Tools 1.2.5 - The missing UI library for the Web
 * 
 * [tabs, tooltip, scrollable, overlay, toolbox.expose]
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * File generated: Wed Jan 12 21:20:57 GMT 2011
 */
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){this.getPanes().slideUp(200),this.getPanes().eq(a).slideDown(400,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c;a.tools.tabs.addEffect("horizontal",function(b,d){c||(c=this.getPanes().eq(0).width()),this.getCurrentPane().animate({width:0},function(){a(this).hide()}),this.getPanes().eq(b).animate({width:c},function(){a(this).show(),d.call()})});function d(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){b[e.effect].call(f,c,function(){d.type="onClick",g.trigger(d,[c])}),j=c,h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var e=this.data("tabs");e&&(e.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){e=new d(a(this),b,c),a(this).data("tabs",e)});return c.api?e:this}})(jQuery);




/**
 * BEGIN PHOTO CYCLE
 */
(function($) {  
	$.fn.photoCycle = function() {
		return this.each(function() {
			var limit = $(".photo").size();
			var delay = 5000;
			var timeoutDelay = 5000;
			var current = limit-1;
			var count = 0;
			var isForced = false;	
			var isPaused = false;
			var isAfterForced = false;
			var rotate;
			var timeout;
			var timeoutStatus;
			var currentPhoto;
			var nextPhoto;	
			
			if(limit > 1){
				$("#photo_nav_container a").bind("click", forceSwapPhoto);
				$("#icon_playpause").bind("click", toggleTimer);
			$("#photomove .photo").addClass("position2");
			createTimer();
			swapPhoto();
			} else {
				$("#icon_playpause").addClass("current");
				$("#photo_nav_container a:eq(0)").addClass("current");
				$("#photo_nav_container a").bind("click", function(){ return false; });
				$("#icon_playpause").bind("click", function(){ return false; });	
			}
			$("#photomove .photo .videolink").bind("click", swapVideo);

			function swapVideo(event){
				if(!isPaused){
					$("#icon_playpause").trigger("click");
				}
				var obj = $(event.currentTarget);
				obj.hide();
				obj.next().show();
				
				return false;
				}


			function swapPhoto() {
				currentPhoto = $("#photomove .photo:eq("+current+")");
				nextPhoto = $("#photomove .photo:eq("+count+")");
				currentPhoto.removeClass("position2").addClass("position0");
				nextPhoto.removeClass("position2").addClass("position1");
				$("#photo_nav_container a.current").removeClass("current");	
				$("#photo_nav_container a:eq("+count+")").addClass("current");				
				animatePhoto();
			}
			
			function forceSwapPhoto(event){
				delayTimer();
				var obj = $(event.currentTarget);
				var index = $("#photo_nav_container a").index(obj);
				if(count !== index){
					$("#photo_nav_container a").unbind("click", forceSwapPhoto);
					$("#photo_nav_container a").bind("click", function(){ return false; });
					isForced = true;
					current = count;
					count = index;
					swapPhoto();
					obj.blur();
				}
				return false;
			}
			
			function autoSwapPhoto() {
				controlCurrent("up");
				swapPhoto();
			}
			
			function animatePhoto(){
				$("#photomove").stop(true, true);
				$("#photomove").animate({"right":"444px"}, updatePosition);
			}
			
			function updatePosition(){
				$("#photomove").css({"right":"0"});
				nextPhoto.removeClass("position1").addClass("position0");
				currentPhoto.removeClass("position0").addClass("position2");
				if(isForced) {
					$("#photo_nav_container a").unbind("click");
					$("#photo_nav_container a").bind("click", forceSwapPhoto);	
					isForced = false;
					isAfterForced = true;
				}
				$("#photomove .photo").find(".videolink").show();
				$("#photomove .photo").find(".videoembed").hide();
			}
						
			function createTimer(){
				rotate = setInterval(autoSwapPhoto,delay);
			}
			
			function stopTimer(){
					clearInterval(rotate);
					if(typeof(timeout) != 'undefined'){
						clearTimeout(timeout);
					}
			}
			
			function delayTimer(){
				stopTimer();
				if(!isPaused){
					timeout = setTimeout(createTimer, timeoutDelay);
				}
			}
			
			function toggleTimer(event){
				var obj = $(event.currentTarget);				
				if(isPaused){
					createTimer();
					isPaused = false;	
					obj.removeClass("current");
				} else {
					stopTimer();
					isPaused = true;
					obj.addClass("current");
				}
				obj.blur();
				
				return false;
			}
			
			function controlCurrent(dir) {
				if(isAfterForced){
					current = count;
					count = current + 1;
					if(current == limit-1){
						count = 0;	
					}
					isAfterForced = false;
				} else if (current == limit-1 && dir == "up") {
					current = 0;
					count = 1;
				} else {
					current++;
					if(dir == "up" && current == 0){
						count = 1;
					} else if(dir == "up" && current == limit-1){
						count = 0;	
					} else if(dir == "up" && current > 0 && current < limit-1){
						count = current+1;
					}
				}
			}
		});
	}
})(jQuery);
/**
 * END PHOTO CYCLE
 */



/**
 * BEGIN FEATURED SCROLL
 */
(function($) {  
	$.fn.featureScroll = function(options) {
		defaults = {
			listDisplayUp: 1,
			navDisplayUp: 4,
			listScrollRate: 496,
			navScrollRate: 56,
			scrollInterval:5000,
			pauseTimeout:10000,
			offClass: "fade",
			nextBtn: "p.forward",
			prevBtn: "p.backward",
			prefix: "featured"
		}
		var options = $.extend(defaults, options);
		
		var listIndex = 0;
		var navIndex = 0;
		var moveIndex = 0;
		var total = $("#" + options.prefix + "-list td").length;
		var moveTotal = total-options.navDisplayUp;
		var intervalID;
		var timerID;
		
		var obj;
		var listDiv;
		var navDiv;
		
		return this.each(function() {
			obj = $(this);
			listDiv = obj.find("#" + options.prefix + "-list");
			navDiv = obj.find("#" + options.prefix + "-nav-list");
			
			obj.find("#" + options.prefix + "-nav").show();
			listDiv.css("overflow","hidden");
			listDiv.scrollLeft(0);
			navDiv.scrollLeft(0);
			obj.find(options.prevBtn).addClass(options.offClass);
			obj.find(options.nextBtn).addClass(options.offClass);
			
			navDiv.find("img").addClass(options.offClass);
			navDiv.find("img:eq(0)").removeClass(options.offClass);
			makeAutoScrollGo();
			navListControl();
			if(moveTotal>0){
				obj.find(options.nextBtn).removeClass(options.offClass);
			}
		});
		
		function makeAutoScrollGo(){
			intervalID = setInterval(autoMoveFeatured, options.scrollInterval);	
		}
		
		function autoMoveFeatured(){
			(listIndex < total-options.listDisplayUp) ? (listIndex++):(listIndex = 0);
			(navIndex < total-1) ? (navIndex++):(navIndex = 0);
			var listScrollAmount = options.listScrollRate*listIndex;
			var navScrollAmount = options.navScrollRate*navIndex;
			
			navDiv.find("img").addClass(options.offClass);
			navDiv.find("img:eq("+navIndex+")").removeClass(options.offClass);
			listDiv.animate({scrollLeft: listScrollAmount});
			navDiv.animate({scrollLeft: navScrollAmount});
			moveIndex = navIndex;
			checkArrows();
		}
		
		function checkArrows(){
			if(moveIndex > 0){
				obj.find(options.prevBtn).removeClass(options.offClass);	
			} else {
				obj.find(options.prevBtn).addClass(options.offClass);	
			}
			if(moveIndex >= moveTotal){
				moveIndex = moveTotal;
				obj.find(options.nextBtn).addClass(options.offClass);
			} else {
				obj.find(options.nextBtn).removeClass(options.offClass);	
			}
			if(moveTotal <= 0){
				obj.find(options.prevBtn).addClass(options.offClass);	
				obj.find(options.nextBtn).addClass(options.offClass);	

			}
		}
		
		function navListControl(){
			checkArrows();			
			navDiv.find("img").click(
				function(){
					clearTimeout(timerID);
					clearInterval(intervalID);
					timerID = setTimeout(makeAutoScrollGo,options.pauseTimeout);
					var clickIndex = navDiv.find("img").index(this);
					var clickListScrollAmount = options.listScrollRate * clickIndex;
					var clickNavScrollAmount = options.navScrollRate * clickIndex;
					
					navDiv.find("img").addClass(options.offClass);
					navDiv.find("img:eq("+clickIndex+")").removeClass(options.offClass);
					listDiv.animate({scrollLeft: clickListScrollAmount});
					navDiv.animate({scrollLeft: clickNavScrollAmount});
					
					listIndex = clickIndex;
					navIndex = clickIndex;
					moveIndex = clickIndex;
					checkArrows();
				}
			);
			obj.find(options.prevBtn).click(
				function(){
					moveNavList("previous");
				}
			);
			obj.find(options.nextBtn).click(
				function(){
					moveNavList("next");					
				}
			);
			function moveNavList(direction){
				clearTimeout(timerID);
				clearInterval(intervalID);
				timerID = setTimeout(makeAutoScrollGo,options.pauseTimeout);
				switch(direction){
					case "previous":
						obj.find(options.nextBtn).removeClass(options.offClass);
						(moveIndex > 0) ? (moveIndex--):(moveIndex = 0);
						if(moveIndex == 0){
							obj.find(options.prevBtn).addClass(options.offClass);	
						}
						break;
					case "next":
						obj.find(options.prevBtn).removeClass(options.offClass);
						(moveIndex < moveTotal) ?(moveIndex++):(moveIndex = moveTotal);
						if(moveIndex == moveTotal){
							obj.find(options.nextBtn).addClass(options.offClass);	
						}
						break;
				}
				var moveNavScrollAmount = options.navScrollRate * moveIndex;
				navDiv.animate({scrollLeft: moveNavScrollAmount});
				checkArrows();
			}
		}

	}
})(jQuery);  
/**
 * END FEATURED SCROLL
 */
 
 /**
  * Collapsable
  */
 (function($) {  
	$.fn.pressReadMore = function() {
		return this.each(function() {
		var obj = $(this);					  
		
		if(obj.height() > 120){
			obj.addClass("collapse");
			obj.after("<p class='readmore'>SHOW MORE</p><div class='clear'></div>");
			obj.next().bind("click", pressReadMore);
		}
		
		function pressReadMore(event){
			var currObj = $(event.currentTarget);
			var display = currObj.prev();
			if(display.hasClass("collapse")){
				display.removeClass("collapse");
				currObj.text("SHOW LESS");
			} else {
				display.addClass("collapse");
				currObj.text("SHOW MORE");	
			}
		}
	  });
	}
})(jQuery);
/**
  * END Collapsable
  */

/**
 * BEGIN PHOTO SCROLL
 */
(function($) {  
	$.fn.photoScroll = function(options) {
		var defaults = {
			scrollCount: 1, // Items to scroll per click, use this number to determine pages
			pxPerItem: 444, // the width of each item -- kev wants to calculate this
			displayUp: 1, // how many to display at a time
			totalOffset: 0, // This number represents any additional td tags that exist in photo scroll, but are not links
			offClass: "fade",
			nextBtn: ".forward",
			prevBtn: ".backward"
		}
		var options = $.extend(defaults, options);
		var obj;
		var scrollDiv;
		var index = 0;
		var total;
		var pages;
		var page;
		var pageIndex = 1;
		var photos; // holds all the photos
		return this.each(function() {
			
			photos = $("#photocontainer a");
			
			obj = $(this);
			scrollDiv = obj.find("#photocontainer");
			// total number of items
			total = obj.find("#photocontainer td").size()-options.totalOffset;
			// get total number of pages
			pages = Math.max(1, Math.ceil((total - (options.displayUp - options.scrollCount)) / options.scrollCount));
			// Make sure page number is within valid range.
			pageIndex = Math.max(1, pageIndex);
			pageIndex = Math.min(pages, pageIndex);

			scrollDiv.scrollLeft(0);
			scrollDiv.css("overflow","hidden");
			
			// disable prev and next nav items by default
			obj.find(options.prevBtn).addClass(options.offClass);
			obj.find(options.nextBtn).addClass(options.offClass);
			
			// check if prev and next nav items might be necessary
			if (pages > 1) {
				
				obj.find(options.nextBtn).removeClass(options.offClass);
				obj.find(options.prevBtn).click(
					function(){
						moveScroll("previous");
						$(this).blur();
						return false;
					}
				);
				obj.find(options.nextBtn).click(
					function(){
						moveScroll("next");
						$(this).blur();
						return false;
					}
				)
			}
		});
		function moveScroll(direction) {
			switch (direction) {
				case "previous":
					obj.find(options.nextBtn).removeClass(options.offClass);
					(pageIndex > 1) ? (pageIndex--) : (pageIndex = 1);
					if (pageIndex == 1) {
						obj.find(options.prevBtn).addClass(options.offClass);	
					}
					break;
				case "next":
					obj.find(options.prevBtn).removeClass(options.offClass);
					(pageIndex < pages) ? (pageIndex++) : (pageIndex = pages);
					if(pageIndex == pages){
						obj.find(options.nextBtn).addClass(options.offClass);	
					}
					
					// need to loop thru images to check if the a tag is empty
					// get start and end point
					start = (pageIndex * 6);
					end = start + 6;
					if (end > photos.size()) end = photos.size();
					
					for (i = start; i < end; i++) {
						if ($(photos[i]).children("img").size() == 0) {
							curid = $(photos[i]).attr("id");
							$(photos[i]).html("<img src=\"" + curid + "\" border=\"0\" width=\"118\" height=\"118\" class=\"thumb\">");
						}
					}
					
					break;
			}
			
			scrollAmount = (options.scrollCount * options.pxPerItem) * (pageIndex - 1);
			scrollDiv.animate({scrollLeft: scrollAmount},150 * options.scrollCount);
		}
	}
})(jQuery);
/**
 * END PHOTO SCROLL
 */
 
 
 
 
 // ColorBox v1.3.16 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
(function(a,b,c){function ba(b){if(!T){O=b,Z(a.extend(J,a.data(O,e))),x=a(O),P=0,J.rel!=="nofollow"&&(x=a("."+V).filter(function(){var b=a.data(this,e).rel||this.rel;return b===J.rel}),P=x.index(O),P===-1&&(x=x.add(O),P=x.length-1));if(!R){R=S=!0,q.show();if(J.returnFocus)try{O.blur(),a(O).one(k,function(){try{this.focus()}catch(a){}})}catch(c){}p.css({opacity:+J.opacity,cursor:J.overlayClose?"pointer":"auto"}).show(),J.w=X(J.initialWidth,"x"),J.h=X(J.initialHeight,"y"),U.position(0),n&&y.bind("resize."+o+" scroll."+o,function(){p.css({width:y.width(),height:y.height(),top:y.scrollTop(),left:y.scrollLeft()})}).trigger("resize."+o),$(g,J.onOpen),I.add(C).hide(),H.html(J.close).show()}U.load(!0)}}function _(){var a,b=f+"Slideshow_",c="click."+f,d,e,g;J.slideshow&&x[1]&&(d=function(){E.text(J.slideshowStop).unbind(c).bind(i,function(){if(P<x.length-1||J.loop)a=setTimeout(U.next,J.slideshowSpeed)}).bind(h,function(){clearTimeout(a)}).one(c+" "+j,e),q.removeClass(b+"off").addClass(b+"on"),a=setTimeout(U.next,J.slideshowSpeed)},e=function(){clearTimeout(a),E.text(J.slideshowStart).unbind([i,h,j,c].join(" ")).one(c,d),q.removeClass(b+"on").addClass(b+"off")},J.slideshowAuto?d():e())}function $(b,c){c&&c.call(O),a.event.trigger(b)}function Z(b){for(var c in b)a.isFunction(b[c])&&c.substring(0,2)!=="on"&&(b[c]=b[c].call(O));b.rel=b.rel||O.rel||"nofollow",b.href=a.trim(b.href||a(O).attr("href")),b.title=b.title||O.title}function Y(a){return J.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(a)}function X(a,b){b=b==="x"?y.width():y.height();return typeof a=="string"?Math.round(/%/.test(a)?b/100*parseInt(a,10):parseInt(a,10)):a}function W(c,d){var e=b.createElement("div");c&&(e.id=f+c),e.style.cssText=d||!1;return a(e)}var d={transition:"elastic",speed:300,width:!1,initialWidth:"600",innerWidth:!1,maxWidth:!1,height:!1,initialHeight:"450",innerHeight:!1,maxHeight:!1,scalePhotos:!0,scrolling:!0,inline:!1,html:!1,iframe:!1,fastIframe:!0,photo:!1,href:!1,title:!1,rel:!1,opacity:.9,preloading:!0,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:!1,returnFocus:!0,loop:!0,slideshow:!1,slideshowAuto:!0,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:!1,onLoad:!1,onComplete:!1,onCleanup:!1,onClosed:!1,overlayClose:!0,escKey:!0,arrowKey:!0},e="colorbox",f="cbox",g=f+"_open",h=f+"_load",i=f+"_complete",j=f+"_cleanup",k=f+"_closed",l=f+"_purge",m=a.browser.msie&&!a.support.opacity,n=m&&a.browser.version<7,o=f+"_IE6",p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K,L,M,N,O,P,Q,R,S,T=!1,U,V=f+"Element";U=a.fn[e]=a[e]=function(b,c){var f=this,g;if(!f[0]&&f.selector)return f;b=b||{},c&&(b.onComplete=c);if(!f[0]||f.selector===undefined)f=a("<a/>"),b.open=!0;f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b)),a(this).addClass(V)}),g=b.open,a.isFunction(g)&&(g=g.call(f)),g&&ba(f[0]);return f},U.init=function(){y=a(c),q=W().attr({id:e,"class":m?f+(n?"IE6":"IE"):""}),p=W("Overlay",n?"position:absolute":"").hide(),r=W("Wrapper"),s=W("Content").append(z=W("LoadedContent","width:0; height:0; overflow:hidden"),B=W("LoadingOverlay").add(W("LoadingGraphic")),C=W("Title"),D=W("Current"),F=W("Next"),G=W("Previous"),E=W("Slideshow").bind(g,_),H=W("Close")),r.append(W().append(W("TopLeft"),t=W("TopCenter"),W("TopRight")),W(!1,"clear:left").append(u=W("MiddleLeft"),s,v=W("MiddleRight")),W(!1,"clear:left").append(W("BottomLeft"),w=W("BottomCenter"),W("BottomRight"))).children().children().css({"float":"left"}),A=W(!1,"position:absolute; width:9999px; visibility:hidden; display:none"),a("body").prepend(p,q.append(r,A)),s.children().hover(function(){a(this).addClass("hover")},function(){a(this).removeClass("hover")}).addClass("hover"),K=t.height()+w.height()+s.outerHeight(!0)-s.height(),L=u.width()+v.width()+s.outerWidth(!0)-s.width(),M=z.outerHeight(!0),N=z.outerWidth(!0),q.css({"padding-bottom":K,"padding-right":L}).hide(),F.click(function(){U.next()}),G.click(function(){U.prev()}),H.click(function(){U.close()}),I=F.add(G).add(D).add(E),s.children().removeClass("hover"),a("."+V).live("click",function(a){a.button!==0&&typeof a.button!="undefined"||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),ba(this))}),p.click(function(){J.overlayClose&&U.close()}),a(b).bind("keydown."+f,function(a){var b=a.keyCode;R&&J.escKey&&b===27&&(a.preventDefault(),U.close()),R&&J.arrowKey&&x[1]&&(b===37?(a.preventDefault(),G.click()):b===39&&(a.preventDefault(),F.click()))})},U.remove=function(){q.add(p).remove(),a("."+V).die("click").removeData(e).removeClass(V)},U.position=function(a,c){function g(a){t[0].style.width=w[0].style.width=s[0].style.width=a.style.width,B[0].style.height=B[1].style.height=s[0].style.height=u[0].style.height=v[0].style.height=a.style.height}var d,e=Math.max(b.documentElement.clientHeight-J.h-M-K,0)/2+y.scrollTop(),f=Math.max(y.width()-J.w-N-L,0)/2+y.scrollLeft();d=q.width()===J.w+N&&q.height()===J.h+M?0:a,r[0].style.width=r[0].style.height="9999px",q.dequeue().animate({width:J.w+N,height:J.h+M,top:e,left:f},{duration:d,complete:function(){g(this),S=!1,r[0].style.width=J.w+N+L+"px",r[0].style.height=J.h+M+K+"px",c&&c()},step:function(){g(this)}})},U.resize=function(a){if(R){a=a||{},a.width&&(J.w=X(a.width,"x")-N-L),a.innerWidth&&(J.w=X(a.innerWidth,"x")),z.css({width:J.w}),a.height&&(J.h=X(a.height,"y")-M-K),a.innerHeight&&(J.h=X(a.innerHeight,"y"));if(!a.innerHeight&&!a.height){var b=z.wrapInner("<div style='overflow:auto'></div>").children();J.h=b.height(),b.replaceWith(b.children())}z.css({height:J.h}),U.position(J.transition==="none"?0:J.speed)}},U.prep=function(b){function h(b){U.position(b,function(){var b,d,g,h,j=x.length,k,n;!R||(n=function(){B.hide(),$(i,J.onComplete)},m&&Q&&z.fadeIn(100),C.html(J.title).add(z).show(),j>1?(typeof J.current=="string"&&D.html(J.current.replace(/\{current\}/,P+1).replace(/\{total\}/,j)).show(),F[J.loop||P<j-1?"show":"hide"]().html(J.next),G[J.loop||P?"show":"hide"]().html(J.previous),b=P?x[P-1]:x[j-1],g=P<j-1?x[P+1]:x[0],J.slideshow&&E.show(),J.preloading&&(h=a.data(g,e).href||g.href,d=a.data(b,e).href||b.href,h=a.isFunction(h)?h.call(g):h,d=a.isFunction(d)?d.call(b):d,Y(h)&&(a("<img/>")[0].src=h),Y(d)&&(a("<img/>")[0].src=d))):I.hide(),J.iframe?(k=a("<iframe/>").addClass(f+"Iframe")[0],J.fastIframe?n():a(k).load(n),k.name=f+ +(new Date),k.src=J.href,J.scrolling||(k.scrolling="no"),m&&(k.frameBorder=0,k.allowTransparency="true"),a(k).appendTo(z).one(l,function(){k.src="//about:blank"})):n(),J.transition==="fade"?q.fadeTo(c,1,function(){q[0].style.filter=""}):q[0].style.filter="",y.bind("resize."+f,function(){U.position(0)}))})}function g(){J.h=J.h||z.height(),J.h=J.mh&&J.mh<J.h?J.mh:J.h;return J.h}function d(){J.w=J.w||z.width(),J.w=J.mw&&J.mw<J.w?J.mw:J.w;return J.w}if(!!R){var c=J.transition==="none"?0:J.speed;y.unbind("resize."+f),z.remove(),z=W("LoadedContent").html(b),z.hide().appendTo(A.show()).css({width:d(),overflow:J.scrolling?"auto":"hidden"}).css({height:g()}).prependTo(s),A.hide(),a(Q).css({"float":"none"}),n&&a("select").not(q.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(j,function(){this.style.visibility="inherit"}),J.transition==="fade"?q.fadeTo(c,0,function(){h(0)}):h(c)}},U.load=function(b){var c,d,g=U.prep;S=!0,Q=!1,O=x[P],b||Z(a.extend(J,a.data(O,e))),$(l),$(h,J.onLoad),J.h=J.height?X(J.height,"y")-M-K:J.innerHeight&&X(J.innerHeight,"y"),J.w=J.width?X(J.width,"x")-N-L:J.innerWidth&&X(J.innerWidth,"x"),J.mw=J.w,J.mh=J.h,J.maxWidth&&(J.mw=X(J.maxWidth,"x")-N-L,J.mw=J.w&&J.w<J.mw?J.w:J.mw),J.maxHeight&&(J.mh=X(J.maxHeight,"y")-M-K,J.mh=J.h&&J.h<J.mh?J.h:J.mh),c=J.href,B.show(),J.inline?(W().hide().insertBefore(a(c)[0]).one(l,function(){a(this).replaceWith(z.children())}),g(a(c))):J.iframe?g(" "):J.html?g(J.html):Y(c)?(a(Q=new Image).addClass(f+"Photo").error(function(){J.title=!1,g(W("Error").text("This image could not be loaded"))}).load(function(){var a;Q.onload=null,J.scalePhotos&&(d=function(){Q.height-=Q.height*a,Q.width-=Q.width*a},J.mw&&Q.width>J.mw&&(a=(Q.width-J.mw)/Q.width,d()),J.mh&&Q.height>J.mh&&(a=(Q.height-J.mh)/Q.height,d())),J.h&&(Q.style.marginTop=Math.max(J.h-Q.height,0)/2+"px"),x[1]&&(P<x.length-1||J.loop)&&(Q.style.cursor="pointer",Q.onclick=function(){U.next()}),m&&(Q.style.msInterpolationMode="bicubic"),setTimeout(function(){g(Q)},1)}),setTimeout(function(){Q.src=c},1)):c&&A.load(c,function(b,c,d){g(c==="error"?W("Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},U.next=function(){!S&&x[1]&&(P<x.length-1||J.loop)&&(P=P<x.length-1?P+1:0,U.load())},U.prev=function(){!S&&x[1]&&(P||J.loop)&&(P=P?P-1:x.length-1,U.load())},U.close=function(){R&&!T&&(T=!0,R=!1,$(j,J.onCleanup),y.unbind("."+f+" ."+o),p.fadeTo(200,0),q.stop().fadeTo(300,0,function(){q.add(p).css({opacity:1,cursor:"auto"}).hide(),$(l),z.remove(),setTimeout(function(){T=!1,$(k,J.onClosed)},1)}))},U.element=function(){return a(O)},U.settings=d,a(U.init)})(jQuery,document,this);
