/* 
 * Functions for the user-facing (public) portion of Armadillo
 * Copyright 2011 NimbleHost. All rights reserved.
 * Requires jQuery 1.4+
 *
 */

$armadillo = jQuery.noConflict();

function startColorbox() {
	$armadillo(".colorbox1").colorbox({rel:'gallery1'});
	$armadillo(".colorbox2").colorbox({rel:'gallery2'});
	$armadillo(".colorbox3").colorbox({rel:'gallery3'});
	$armadillo(".colorbox4").colorbox({rel:'gallery4'});
	$armadillo(".colorbox5").colorbox({rel:'gallery5'});
}

function attachMenuToSiteNav(siteMainNav, siteSecondNav, siteThirdNav, position) {
	//Remove the extraneous '.current' class from the Armadillo menu, so we don't create two IDs with the same value
	if ( $armadillo(siteMainNav).find('ul li.current').length == 0 ) { $armadillo('#armadilloContentMenu ul li.current').removeClass('current'); }
	else if ( $armadillo(siteMainNav).find('ul li a.current').length == 0 ) { $armadillo('#armadilloContentMenu ul li a.current').removeClass('current'); }
	//Add an id of 'current' to the armadillo menu, for themes that use look for that id when styling the menu
	$armadillo('#armadilloContentMenu ul .current').attr('id', 'current');
	//Get the list items from the armadillo menu
	var menuHTML;
	if ($armadillo(siteMainNav).find('ul').length == 0) { menuHTML = $armadillo('#armadilloContentMenu').html(); } else { menuHTML = $armadillo('#armadilloContentMenu ul').html(); }
	var subMenuHTML;
	if ( $armadillo('#armadilloContentMenu ul ul .current').not('ul ul ul .current').length == 1 ) { subMenuHTML = $armadillo('#armadilloContentMenu ul ul .current').parent().parent().html(); }
	else if ( $armadillo('#armadilloContentMenu ul ul ul .current').not('ul ul ul ul .current').length == 1 ) { subMenuHTML = $armadillo('#armadilloContentMenu ul ul .current').parent().parent().parent().parent().html(); }
	else if ( $armadillo('#armadilloContentMenu ul ul ul ul .current').not('ul ul ul ul ul .current').length == 1 ) { subMenuHTML = $armadillo('#armadilloContentMenu ul ul .current').parent().parent().parent().parent().parent().parent().html(); }
	else if ( $armadillo('#armadilloContentMenu ul ul ul ul ul .current').not('ul ul ul ul ul ul .current').length == 1 ) { subMenuHTML = $armadillo('#armadilloContentMenu ul ul .current').parent().parent().parent().parent().parent().parent().parent().parent().html(); }
	else { subMenuHTML = $armadillo('#armadilloContentMenu ul .current+ul').html(); }
	subMenuHTML = "<ul><li><a></a><ul>" + subMenuHTML + "</ul></li></ul>";
	var thirdMenuHTML;
	if ( $armadillo('#armadilloContentMenu ul ul ul .current').not('ul ul ul ul .current').length == 1 ) { thirdMenuHTML = $armadillo('#armadilloContentMenu ul ul ul .current').parent().parent().html(); }
	else if ( $armadillo('#armadilloContentMenu ul ul ul ul .current').not('ul ul ul ul ul .current').length == 1 ) { thirdMenuHTML = $armadillo('#armadilloContentMenu ul ul ul .current').parent().parent().parent().parent().html(); }
	else if ( $armadillo('#armadilloContentMenu ul ul ul ul ul .current').not('ul ul ul ul ul ul .current').length == 1 ) { thirdMenuHTML = $armadillo('#armadilloContentMenu ul ul ul .current').parent().parent().parent().parent().parent().parent().html(); }
	else { thirdMenuHTML = $armadillo('#armadilloContentMenu ul ul .current+ul').html(); }
	thirdMenuHTML = "<ul><li><a></a><ul><li><a></a><ul>" + thirdMenuHTML + "</ul></li></ul></li></ul>";
	//Remove the ID and Class for the current menu item in the 'main' website's navigation
	$armadillo(siteMainNav).find('ul #current').removeAttr('id');
	$armadillo(siteMainNav).find('ul .current').removeClass('current');
	$armadillo(siteMainNav).find('ul .currentAncestor').removeClass('currentAncestor');
	$armadillo(siteSecondNav).find('ul #current').removeAttr('id');
	$armadillo(siteSecondNav).find('ul .current').removeClass('current');
	$armadillo(siteSecondNav).find('ul .currentAncestor').removeClass('currentAncestor');
	$armadillo(siteThirdNav).find('ul #current').removeAttr('id');
	$armadillo(siteThirdNav).find('ul .current').removeClass('current');
	$armadillo(siteThirdNav).find('ul .currentAncestor').removeClass('currentAncestor');
	//Get the placement where we want to insert Armadillo's menu items
	//Site's main navigation
	var endOfMainNav = $armadillo(siteMainNav + ' ul > li a').not('ul li ul a').last().parent();
	var startOfMainNav = siteMainNav + ' ul li:first';
	//Site's secondary navigation
	var endOfSecondNav = $armadillo(siteSecondNav + ' ul > li a').not('ul li ul a').last().parent();
	var startOfSecondNav = siteSecondNav + ' ul li:first';
	//Site's other navigation
	var endOfThirdNav = $armadillo(siteThirdNav + ' ul > li a').not('ul li ul a').last().parent();
	var startOfThirdNav = siteThirdNav + ' ul li:first';
	//Add menu items to the Site's menu
	if ( position === 'moveToBefore' ) {
		if ( siteMainNav !== '' && $armadillo(siteMainNav).find('ul').length == 0 ) { $armadillo(siteMainNav).append(menuHTML); }
		else if ( siteMainNav !== '' ) { $armadillo(menuHTML).insertBefore(startOfMainNav); }
		if ( $armadillo('#armadilloContentMenu ul .current+ul').length != 0 || $armadillo('#armadilloContentMenu ul ul .current').length != 0 ) {
			if ( siteSecondNav !== '' && $armadillo(siteSecondNav).find('ul ul').length == 0 ) { $armadillo(siteSecondNav).append(subMenuHTML); }
			else if ( siteSecondNav !== '' ) { $armadillo(subMenuHTML).insertBefore(startOfSecondNav); }
		}
		if ( $armadillo('#armadilloContentMenu ul ul .current+ul').length != 0 || $armadillo('#armadilloContentMenu ul ul ul .current').length != 0 ) {
			if ( siteThirdNav !== '' && $armadillo(siteThirdNav).find('ul ul ul').length == 0 ) { $armadillo(siteThirdNav).append(thirdMenuHTML); }
			else if ( siteThirdNav !== '' ) { $armadillo(thirdMenuHTML).insertBefore(startOfThirdNav); }
		}
	} else if ( position === 'moveToAfter' ) {
		if ( siteMainNav !== '' && $armadillo(siteMainNav).find('ul').length == 0 ) { $armadillo(siteMainNav).append(menuHTML); }
		else if ( siteMainNav !== '' ) { $armadillo(menuHTML).insertAfter(endOfMainNav); }
		if ( $armadillo('#armadilloContentMenu ul .current+ul').length != 0 || $armadillo('#armadilloContentMenu ul ul .current').length != 0 ) {
			if ( siteSecondNav !== '' && $armadillo(siteSecondNav).find('ul ul').length == 0 ) { $armadillo(siteSecondNav).append(subMenuHTML); }
			else if ( siteSecondNav !== '' ) { $armadillo(subMenuHTML).insertAfter(endOfSecondNav); }
		}
		if ( $armadillo('#armadilloContentMenu ul ul .current+ul').length != 0 || $armadillo('#armadilloContentMenu ul ul ul .current').length != 0 ) {
			if ( siteThirdNav !== '' && $armadillo(siteThirdNav).find('ul ul ul').length == 0 ) { $armadillo(siteThirdNav).append(thirdMenuHTML); }
			else if ( siteThirdNav !== '' ) { $armadillo(thirdMenuHTML).insertAfter(endOfThirdNav); }	
		}
	}
}

function showMorePosts(assetPath) {
	$armadillo('.armadilloContentContainer').on("click", ".showMorePostsButton a", function() {
		var postsPageNumber = 'postsPageNumber=' + $armadillo(this).attr('rel');
		var contentArea = $armadillo(this).parent();
		$armadillo(this).parent().fadeTo( 500, 0, function() { $armadillo(this).slideUp( 500, function() { $armadillo(this).remove(); }); });
		
		$armadillo.ajax({
			type: 'get',
			cache: false,
			url: assetPath + '/armadillo/core/displayContent.php?action=showMorePosts',
			data: postsPageNumber,
			dataType: 'html',
			success: function(postsToDisplay) { 
						$armadillo(postsToDisplay).insertAfter(contentArea);
						$armadillo('.fetchedPostsContainer').slideDown( 500, function() { $armadillo(this).fadeTo( 500, 1 ); }); },
			error:  function() { $armadillo(contentArea).append('A problem occurred when trying to retrieve more posts.'); }
		});
	});
}

function armadilloDDmenu() {
	var config = { sensitivity: 3, interval: 30, over: revealChildren, timeout: 400, out: hideChildren};
	function revealChildren(){ $armadillo(this).find("ul:first").stop().slideDown(500); }
	function hideChildren(){ $armadillo(this).find("ul:first").stop().fadeOut(300); }
 	
 	$armadillo("#armadilloContentMenu ul .menuSection").each(function(){
 		var sectionLabel = $armadillo(this).text();
 		$armadillo("<li class='menuSectionLabel' style='display: block;'>" + sectionLabel + "</li>").insertBefore($armadillo(this).parent().parent());
 	});
 	
 	$armadillo("<div class='menuPointer'></div>").prependTo($armadillo("#armadilloContentMenu ul ul"));
 	$armadillo("#armadilloContentMenu ul ul ul").parent().append("<span class='childIndicator'>&middot;</span>");
 	$armadillo("#armadilloContentMenu ul ul").css({display: "none"}); //Opera fix
	$armadillo("#armadilloContentMenu ul li").hoverIntent(config);
}

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

// ColorBox v1.3.19 - jQuery lightbox plugin
// (c) 2011 Jack Moore - jacklmoore.com
// License: http://www.opensource.org/licenses/mit-license.php
(function(a,b,c){function Z(c,d,e){var g=b.createElement(c);return d&&(g.id=f+d),e&&(g.style.cssText=e),a(g)}function $(a){var b=y.length,c=(Q+a)%b;return c<0?b+c:c}function _(a,b){return Math.round((/%/.test(a)?(b==="x"?z.width():z.height())/100:1)*parseInt(a,10))}function ba(a){return K.photo||/\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(a)}function bb(){var b;K=a.extend({},a.data(P,e));for(b in K)a.isFunction(K[b])&&b.slice(0,2)!=="on"&&(K[b]=K[b].call(P));K.rel=K.rel||P.rel||"nofollow",K.href=K.href||a(P).attr("href"),K.title=K.title||P.title,typeof K.href=="string"&&(K.href=a.trim(K.href))}function bc(b,c){a.event.trigger(b),c&&c.call(P)}function bd(){var a,b=f+"Slideshow_",c="click."+f,d,e,g;K.slideshow&&y[1]?(d=function(){F.text(K.slideshowStop).unbind(c).bind(j,function(){if(K.loop||y[Q+1])a=setTimeout(W.next,K.slideshowSpeed)}).bind(i,function(){clearTimeout(a)}).one(c+" "+k,e),r.removeClass(b+"off").addClass(b+"on"),a=setTimeout(W.next,K.slideshowSpeed)},e=function(){clearTimeout(a),F.text(K.slideshowStart).unbind([j,i,k,c].join(" ")).one(c,function(){W.next(),d()}),r.removeClass(b+"on").addClass(b+"off")},K.slideshowAuto?d():e()):r.removeClass(b+"off "+b+"on")}function be(b){U||(P=b,bb(),y=a(P),Q=0,K.rel!=="nofollow"&&(y=a("."+g).filter(function(){var b=a.data(this,e).rel||this.rel;return b===K.rel}),Q=y.index(P),Q===-1&&(y=y.add(P),Q=y.length-1)),S||(S=T=!0,r.show(),K.returnFocus&&a(P).blur().one(l,function(){a(this).focus()}),q.css({opacity:+K.opacity,cursor:K.overlayClose?"pointer":"auto"}).show(),K.w=_(K.initialWidth,"x"),K.h=_(K.initialHeight,"y"),W.position(),o&&z.bind("resize."+p+" scroll."+p,function(){q.css({width:z.width(),height:z.height(),top:z.scrollTop(),left:z.scrollLeft()})}).trigger("resize."+p),bc(h,K.onOpen),J.add(D).hide(),I.html(K.close).show()),W.load(!0))}function bf(){!r&&b.body&&(Y=!1,z=a(c),r=Z(X).attr({id:e,"class":n?f+(o?"IE6":"IE"):""}),q=Z(X,"Overlay",o?"position:absolute":"").hide(),s=Z(X,"Wrapper"),t=Z(X,"Content").append(A=Z(X,"LoadedContent","width:0; height:0; overflow:hidden"),C=Z(X,"LoadingOverlay").add(Z(X,"LoadingGraphic")),D=Z(X,"Title"),E=Z(X,"Current"),G=Z(X,"Next"),H=Z(X,"Previous"),F=Z(X,"Slideshow").bind(h,bd),I=Z(X,"Close")),s.append(Z(X).append(Z(X,"TopLeft"),u=Z(X,"TopCenter"),Z(X,"TopRight")),Z(X,!1,"clear:left").append(v=Z(X,"MiddleLeft"),t,w=Z(X,"MiddleRight")),Z(X,!1,"clear:left").append(Z(X,"BottomLeft"),x=Z(X,"BottomCenter"),Z(X,"BottomRight"))).find("div div").css({"float":"left"}),B=Z(X,!1,"position:absolute; width:9999px; visibility:hidden; display:none"),J=G.add(H).add(E).add(F),a(b.body).append(q,r.append(s,B)))}function bg(){return r?(Y||(Y=!0,L=u.height()+x.height()+t.outerHeight(!0)-t.height(),M=v.width()+w.width()+t.outerWidth(!0)-t.width(),N=A.outerHeight(!0),O=A.outerWidth(!0),r.css({"padding-bottom":L,"padding-right":M}).hide(),G.click(function(){W.next()}),H.click(function(){W.prev()}),I.click(function(){W.close()}),q.click(function(){K.overlayClose&&W.close()}),a(b).bind("keydown."+f,function(a){var b=a.keyCode;S&&K.escKey&&b===27&&(a.preventDefault(),W.close()),S&&K.arrowKey&&y[1]&&(b===37?(a.preventDefault(),H.click()):b===39&&(a.preventDefault(),G.click()))}),a("."+g,b).live("click",function(a){a.which>1||a.shiftKey||a.altKey||a.metaKey||(a.preventDefault(),be(this))})),!0):!1}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:"File {current} of {total}",previous:"previous",next:"next",close:"close",open:!1,returnFocus:!0,reposition:!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,top:!1,bottom:!1,left:!1,right:!1,fixed:!1,data:undefined},e="colorbox",f="cbox",g=f+"Element",h=f+"_open",i=f+"_load",j=f+"_complete",k=f+"_cleanup",l=f+"_closed",m=f+"_purge",n=!a.support.opacity&&!a.support.style,o=n&&!c.XMLHttpRequest,p=f+"_IE6",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,U,V,W,X="div",Y;if(a.colorbox)return;a(bf),W=a.fn[e]=a[e]=function(b,c){var f=this;b=b||{},bf();if(bg()){if(!f[0]){if(f.selector)return f;f=a("<a/>"),b.open=!0}c&&(b.onComplete=c),f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b))}).addClass(g),(a.isFunction(b.open)&&b.open.call(f)||b.open)&&be(f[0])}return f},W.position=function(a,b){function i(a){u[0].style.width=x[0].style.width=t[0].style.width=a.style.width,t[0].style.height=v[0].style.height=w[0].style.height=a.style.height}var c=0,d=0,e=r.offset(),g=z.scrollTop(),h=z.scrollLeft();z.unbind("resize."+f),r.css({top:-9e4,left:-9e4}),K.fixed&&!o?(e.top-=g,e.left-=h,r.css({position:"fixed"})):(c=g,d=h,r.css({position:"absolute"})),K.right!==!1?d+=Math.max(z.width()-K.w-O-M-_(K.right,"x"),0):K.left!==!1?d+=_(K.left,"x"):d+=Math.round(Math.max(z.width()-K.w-O-M,0)/2),K.bottom!==!1?c+=Math.max(z.height()-K.h-N-L-_(K.bottom,"y"),0):K.top!==!1?c+=_(K.top,"y"):c+=Math.round(Math.max(z.height()-K.h-N-L,0)/2),r.css({top:e.top,left:e.left}),a=r.width()===K.w+O&&r.height()===K.h+N?0:a||0,s[0].style.width=s[0].style.height="9999px",r.dequeue().animate({width:K.w+O,height:K.h+N,top:c,left:d},{duration:a,complete:function(){i(this),T=!1,s[0].style.width=K.w+O+M+"px",s[0].style.height=K.h+N+L+"px",K.reposition&&setTimeout(function(){z.bind("resize."+f,W.position)},1),b&&b()},step:function(){i(this)}})},W.resize=function(a){S&&(a=a||{},a.width&&(K.w=_(a.width,"x")-O-M),a.innerWidth&&(K.w=_(a.innerWidth,"x")),A.css({width:K.w}),a.height&&(K.h=_(a.height,"y")-N-L),a.innerHeight&&(K.h=_(a.innerHeight,"y")),!a.innerHeight&&!a.height&&(A.css({height:"auto"}),K.h=A.height()),A.css({height:K.h}),W.position(K.transition==="none"?0:K.speed))},W.prep=function(b){function g(){return K.w=K.w||A.width(),K.w=K.mw&&K.mw<K.w?K.mw:K.w,K.w}function h(){return K.h=K.h||A.height(),K.h=K.mh&&K.mh<K.h?K.mh:K.h,K.h}if(!S)return;var c,d=K.transition==="none"?0:K.speed;A.remove(),A=Z(X,"LoadedContent").append(b),A.hide().appendTo(B.show()).css({width:g(),overflow:K.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(t),B.hide(),a(R).css({"float":"none"}),o&&a("select").not(r.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(k,function(){this.style.visibility="inherit"}),c=function(){function q(){n&&r[0].style.removeAttribute("filter")}var b,c,g=y.length,h,i="frameBorder",k="allowTransparency",l,o,p;if(!S)return;l=function(){clearTimeout(V),C.hide(),bc(j,K.onComplete)},n&&R&&A.fadeIn(100),D.html(K.title).add(A).show();if(g>1){typeof K.current=="string"&&E.html(K.current.replace("{current}",Q+1).replace("{total}",g)).show(),G[K.loop||Q<g-1?"show":"hide"]().html(K.next),H[K.loop||Q?"show":"hide"]().html(K.previous),K.slideshow&&F.show();if(K.preloading){b=[$(-1),$(1)];while(c=y[b.pop()])o=a.data(c,e).href||c.href,a.isFunction(o)&&(o=o.call(c)),ba(o)&&(p=new Image,p.src=o)}}else J.hide();K.iframe?(h=Z("iframe")[0],i in h&&(h[i]=0),k in h&&(h[k]="true"),h.name=f+ +(new Date),K.fastIframe?l():a(h).one("load",l),h.src=K.href,K.scrolling||(h.scrolling="no"),a(h).addClass(f+"Iframe").appendTo(A).one(m,function(){h.src="//about:blank"})):l(),K.transition==="fade"?r.fadeTo(d,1,q):q()},K.transition==="fade"?r.fadeTo(d,0,function(){W.position(0,c)}):W.position(d,c)},W.load=function(b){var c,d,e=W.prep;T=!0,R=!1,P=y[Q],b||bb(),bc(m),bc(i,K.onLoad),K.h=K.height?_(K.height,"y")-N-L:K.innerHeight&&_(K.innerHeight,"y"),K.w=K.width?_(K.width,"x")-O-M:K.innerWidth&&_(K.innerWidth,"x"),K.mw=K.w,K.mh=K.h,K.maxWidth&&(K.mw=_(K.maxWidth,"x")-O-M,K.mw=K.w&&K.w<K.mw?K.w:K.mw),K.maxHeight&&(K.mh=_(K.maxHeight,"y")-N-L,K.mh=K.h&&K.h<K.mh?K.h:K.mh),c=K.href,V=setTimeout(function(){C.show()},100),K.inline?(Z(X).hide().insertBefore(a(c)[0]).one(m,function(){a(this).replaceWith(A.children())}),e(a(c))):K.iframe?e(" "):K.html?e(K.html):ba(c)?(a(R=new Image).addClass(f+"Photo").error(function(){K.title=!1,e(Z(X,"Error").text("This file could not be loaded"))}).load(function(){var a;R.onload=null,K.scalePhotos&&(d=function(){R.height-=R.height*a,R.width-=R.width*a},K.mw&&R.width>K.mw&&(a=(R.width-K.mw)/R.width,d()),K.mh&&R.height>K.mh&&(a=(R.height-K.mh)/R.height,d())),K.h&&(R.style.marginTop=Math.max(K.h-R.height,0)/2+"px"),y[1]&&(K.loop||y[Q+1])&&(R.style.cursor="pointer",R.onclick=function(){W.next()}),n&&(R.style.msInterpolationMode="bicubic"),setTimeout(function(){e(R)},1)}),setTimeout(function(){R.src=c},1)):c&&B.load(c,K.data,function(b,c,d){e(c==="error"?Z(X,"Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},W.next=function(){!T&&y[1]&&(K.loop||y[Q+1])&&(Q=$(1),W.load())},W.prev=function(){!T&&y[1]&&(K.loop||Q)&&(Q=$(-1),W.load())},W.close=function(){S&&!U&&(U=!0,S=!1,bc(k,K.onCleanup),z.unbind("."+f+" ."+p),q.fadeTo(200,0),r.stop().fadeTo(300,0,function(){r.add(q).css({opacity:1,cursor:"auto"}).hide(),bc(m),A.remove(),setTimeout(function(){U=!1,bc(l,K.onClosed)},1)}))},W.remove=function(){a([]).add(r).add(q).remove(),r=null,a("."+g).removeData(e).removeClass(g).die()},W.element=function(){return a(P)},W.settings=d})(jQuery,document,this);
