// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
//		jAlert( message, [title, callback] )
//		jConfirm( message, [title, callback] )
//		jPrompt( message, [value, title, callback] )
// 
// History:
//
//		1.00 - Released (29 December 2008)
//
//		1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC. 
//
(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		alert: function(message, title, callback) {
			if( title == null ) title = 'Alert';
			$.alerts._show(title, message, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		confirm: function(message, title, callback) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', function(result) {
				if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			if( title == null ) title = 'Prompt';
			$.alerts._show(title, message, value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		// Private methods
		
		_show: function(title, msg, value, type, callback) {
			
			$.alerts._hide();
			$.alerts._overlay('show');
			
			$("BODY").append(
			  '<div id="popup_container">' +
			    '<h1 id="popup_title"></h1>' +
			    '<div id="popup_content">' +
			      '<div id="popup_message"></div>' +
				'</div>' +
			  '</div>');
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0
			});
			
			$("#popup_title").text(title);
			$("#popup_content").addClass(type);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			switch( type ) {
				case 'alert':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});
					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
		
		_hide: function() {
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', $.alerts._reposition);
					break;
					case false:
						$(window).unbind('resize', $.alerts._reposition);
					break;
				}
			}
		}
		
	}
	
	// Shortuct functions
	jAlert = function(message, title, callback) {
		$.alerts.alert(message, title, callback);
	}
	
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);;
// ColorBox v1.3.18 - 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 Y(c,d,e){var g=b.createElement(c);return d&&(g.id=f+d),e&&(g.style.cssText=e),a(g)}function Z(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 _(a){return K.photo||/\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(a)}function ba(){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 bb(b,c){a.event.trigger(b),c&&c.call(P)}function bc(){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(Q<y.length-1||K.loop)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 bd(b){if(!U){P=b,ba(),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));if(!S){S=T=!0,r.show();if(K.returnFocus)try{P.blur(),a(P).one(l,function(){try{this.focus()}catch(a){}})}catch(c){}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),bb(h,K.onOpen),J.add(D).hide(),I.html(K.close).show()}W.load(!0)}}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,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.browser.msie&&!a.support.opacity,o=n&&a.browser.version<7,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";W=a.fn[e]=a[e]=function(b,c){var f=this;b=b||{},W.init();if(!f[0]){if(f.selector)return f;f=a("<a/>"),b.open=!0}return c&&(b.onComplete=c),f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b)),a(this).addClass(g)}),(a.isFunction(b.open)&&b.open.call(f)||b.open)&&bd(f[0]),f},W.init=function(){if(!r){if(!a("body")[0]){a(W.init);return}z=a(c),r=Y(X).attr({id:e,"class":n?f+(o?"IE6":"IE"):""}),q=Y(X,"Overlay",o?"position:absolute":"").hide(),s=Y(X,"Wrapper"),t=Y(X,"Content").append(A=Y(X,"LoadedContent","width:0; height:0; overflow:hidden"),C=Y(X,"LoadingOverlay").add(Y(X,"LoadingGraphic")),D=Y(X,"Title"),E=Y(X,"Current"),G=Y(X,"Next"),H=Y(X,"Previous"),F=Y(X,"Slideshow").bind(h,bc),I=Y(X,"Close")),s.append(Y(X).append(Y(X,"TopLeft"),u=Y(X,"TopCenter"),Y(X,"TopRight")),Y(X,!1,"clear:left").append(v=Y(X,"MiddleLeft"),t,w=Y(X,"MiddleRight")),Y(X,!1,"clear:left").append(Y(X,"BottomLeft"),x=Y(X,"BottomCenter"),Y(X,"BottomRight"))).find("div div").css({"float":"left"}),B=Y(X,!1,"position:absolute; width:9999px; visibility:hidden; display:none"),a("body").prepend(q,r.append(s,B)),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()}),J=G.add(H).add(E).add(F),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()))})}},W.remove=function(){r.add(q).remove(),r=null,a("."+g).removeData(e).removeClass(g)},W.position=function(a,b){function g(a){u[0].style.width=x[0].style.width=t[0].style.width=a.style.width,C[0].style.height=C[1].style.height=t[0].style.height=v[0].style.height=w[0].style.height=a.style.height}var c=0,d=0,e=r.offset();z.unbind("resize."+f),r.css({top:-99999,left:-99999}),K.fixed&&!o?r.css({position:"fixed"}):(c=z.scrollTop(),d=z.scrollLeft(),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(){g(this),T=!1,s[0].style.width=K.w+O+M+"px",s[0].style.height=K.h+N+L+"px",b&&b(),setTimeout(function(){z.bind("resize."+f,W.position)},1)},step:function(){g(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=Y(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(),bb(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=[Z(-1),Z(1)];while(c=y[b.pop()])o=a.data(c,e).href||c.href,a.isFunction(o)&&(o=o.call(c)),_(o)&&(p=new Image,p.src=o)}}else J.hide();K.iframe?(h=Y("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||ba(),bb(m),bb(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?(Y(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):_(c)?(a(R=new Image).addClass(f+"Photo").error(function(){K.title=!1,e(Y(X,"Error").text("This image 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]&&(Q<y.length-1||K.loop)&&(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"?Y(X,"Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},W.next=function(){!T&&y[1]&&(Q<y.length-1||K.loop)&&(Q=Z(1),W.load())},W.prev=function(){!T&&y[1]&&(Q||K.loop)&&(Q=Z(-1),W.load())},W.close=function(){S&&!U&&(U=!0,S=!1,bb(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(),bb(m),A.remove(),setTimeout(function(){U=!1,bb(l,K.onClosed)},1)}))},W.element=function(){return a(P)},W.settings=d,a("."+g,b).live("click",function(a){a.which>1||a.shiftKey||a.altKey||a.metaKey||(a.preventDefault(),bd(this))}),W.init()})(jQuery,document,this);;
/*
 * jQuery Templates Plugin 1.0.0pre
 * http://github.com/jquery/jquery-tmpl
 * Requires jQuery 1.4.2
 *
 * Copyright Software Freedom Conservancy, Inc.
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 */
(function(a){var r=a.fn.domManip,d="_tmplitem",q=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,b={},f={},e,p={key:0,data:{}},i=0,c=0,l=[];function g(g,d,h,e){var c={data:e||(e===0||e===false)?e:d?d.data:{},_wrap:d?d._wrap:null,tmpl:null,parent:d||null,nodes:[],calls:u,nest:w,wrap:x,html:v,update:t};g&&a.extend(c,g,{nodes:[],parent:d});if(h){c.tmpl=h;c._ctnt=c._ctnt||c.tmpl(a,c);c.key=++i;(l.length?f:b)[i]=c}return c}a.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(f,d){a.fn[f]=function(n){var g=[],i=a(n),k,h,m,l,j=this.length===1&&this[0].parentNode;e=b||{};if(j&&j.nodeType===11&&j.childNodes.length===1&&i.length===1){i[d](this[0]);g=this}else{for(h=0,m=i.length;h<m;h++){c=h;k=(h>0?this.clone(true):this).get();a(i[h])[d](k);g=g.concat(k)}c=0;g=this.pushStack(g,f,i.selector)}l=e;e=null;a.tmpl.complete(l);return g}});a.fn.extend({tmpl:function(d,c,b){return a.tmpl(this[0],d,c,b)},tmplItem:function(){return a.tmplItem(this[0])},template:function(b){return a.template(b,this[0])},domManip:function(d,m,k){if(d[0]&&a.isArray(d[0])){var g=a.makeArray(arguments),h=d[0],j=h.length,i=0,f;while(i<j&&!(f=a.data(h[i++],"tmplItem")));if(f&&c)g[2]=function(b){a.tmpl.afterManip(this,b,k)};r.apply(this,g)}else r.apply(this,arguments);c=0;!e&&a.tmpl.complete(b);return this}});a.extend({tmpl:function(d,h,e,c){var i,k=!c;if(k){c=p;d=a.template[d]||a.template(null,d);f={}}else if(!d){d=c.tmpl;b[c.key]=c;c.nodes=[];c.wrapped&&n(c,c.wrapped);return a(j(c,null,c.tmpl(a,c)))}if(!d)return[];if(typeof h==="function")h=h.call(c||{});e&&e.wrapped&&n(e,e.wrapped);i=a.isArray(h)?a.map(h,function(a){return a?g(e,c,d,a):null}):[g(e,c,d,h)];return k?a(j(c,null,i)):i},tmplItem:function(b){var c;if(b instanceof a)b=b[0];while(b&&b.nodeType===1&&!(c=a.data(b,"tmplItem"))&&(b=b.parentNode));return c||p},template:function(c,b){if(b){if(typeof b==="string")b=o(b);else if(b instanceof a)b=b[0]||{};if(b.nodeType)b=a.data(b,"tmpl")||a.data(b,"tmpl",o(b.innerHTML));return typeof c==="string"?(a.template[c]=b):b}return c?typeof c!=="string"?a.template(null,c):a.template[c]||a.template(null,q.test(c)?c:a(c)):null},encode:function(a){return(""+a).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});a.extend(a.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){b={}},afterManip:function(f,b,d){var e=b.nodeType===11?a.makeArray(b.childNodes):b.nodeType===1?[b]:[];d.call(f,b);m(e);c++}});function j(e,g,f){var b,c=f?a.map(f,function(a){return typeof a==="string"?e.key?a.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+d+'="'+e.key+'" $2'):a:j(a,e,a._ctnt)}):e;if(g)return c;c=c.join("");c.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(f,c,e,d){b=a(e).get();m(b);if(c)b=k(c).concat(b);if(d)b=b.concat(k(d))});return b?b:k(c)}function k(c){var b=document.createElement("div");b.innerHTML=c;return a.makeArray(b.childNodes)}function o(b){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+a.trim(b).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(m,l,k,g,b,c,d){var j=a.tmpl.tag[k],i,e,f;if(!j)throw"Unknown template tag: "+k;i=j._default||[];if(c&&!/\w$/.test(b)){b+=c;c=""}if(b){b=h(b);d=d?","+h(d)+")":c?")":"";e=c?b.indexOf(".")>-1?b+h(c):"("+b+").call($item"+d:b;f=c?e:"(typeof("+b+")==='function'?("+b+").call($item):("+b+"))"}else f=e=i.$1||"null";g=h(g);return"');"+j[l?"close":"open"].split("$notnull_1").join(b?"typeof("+b+")!=='undefined' && ("+b+")!=null":"true").split("$1a").join(f).split("$1").join(e).split("$2").join(g||i.$2||"")+"__.push('"})+"');}return __;")}function n(c,b){c._wrap=j(c,true,a.isArray(b)?b:[q.test(b)?b:a(b).html()]).join("")}function h(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function s(b){var a=document.createElement("div");a.appendChild(b.cloneNode(true));return a.innerHTML}function m(o){var n="_"+c,k,j,l={},e,p,h;for(e=0,p=o.length;e<p;e++){if((k=o[e]).nodeType!==1)continue;j=k.getElementsByTagName("*");for(h=j.length-1;h>=0;h--)m(j[h]);m(k)}function m(j){var p,h=j,k,e,m;if(m=j.getAttribute(d)){while(h.parentNode&&(h=h.parentNode).nodeType===1&&!(p=h.getAttribute(d)));if(p!==m){h=h.parentNode?h.nodeType===11?0:h.getAttribute(d)||0:0;if(!(e=b[m])){e=f[m];e=g(e,b[h]||f[h]);e.key=++i;b[i]=e}c&&o(m)}j.removeAttribute(d)}else if(c&&(e=a.data(j,"tmplItem"))){o(e.key);b[e.key]=e;h=a.data(j.parentNode,"tmplItem");h=h?h.key:0}if(e){k=e;while(k&&k.key!=h){k.nodes.push(j);k=k.parent}delete e._ctnt;delete e._wrap;a.data(j,"tmplItem",e)}function o(a){a=a+n;e=l[a]=l[a]||g(e,b[e.parent.key+n]||e.parent)}}}function u(a,d,c,b){if(!a)return l.pop();l.push({_:a,tmpl:d,item:this,data:c,options:b})}function w(d,c,b){return a.tmpl(a.template(d),c,b,this)}function x(b,d){var c=b.options||{};c.wrapped=d;return a.tmpl(a.template(b.tmpl),b.data,c,b.item)}function v(d,c){var b=this._wrap;return a.map(a(a.isArray(b)?b.join(""):b).filter(d||"*"),function(a){return c?a.innerText||a.textContent:a.outerHTML||s(a)})}function t(){var b=this.nodes;a.tmpl(null,null,null,this).insertBefore(b[0]);a(b).remove()}})(jQuery);
/*
 * jQuery autoResize (textarea auto-resizer)
 * @copyright James Padolsey http://james.padolsey.com
 * @version 1.04
 */

(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).attr('tabIndex','-1').insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);;
/*
 * Superfish v1.4.1 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

(function($){
	$.superfish = {};
	$.superfish.o = [];
	$.superfish.op = {};
	$.superfish.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		delay		: 0,
		animation	: {opacity:'show'},
		speed		: 'normal',
		oldJquery	: false, /* set to true if using jQuery version below 1.2 */
		disableHI	: false, /* set to true to disable hoverIntent usage */
		// callback functions:
		onInit		: function(){},
		onBeforeShow: function(){},
		onShow		: function(){}, /* note this name changed ('onshow' to 'onShow') from version 1.4 onward */
		onHide		: function(){}
	};
	$.fn.superfish = function(op){
		var bcClass = 'sfbreadcrumb',
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$);
				var o = getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				if ( !$$.is('.'+bcClass) ) {
					menu.sfTimer=setTimeout(function(){
						$$.hideSuperfishUl();
						if (o.$path.length){over.call(o.$path);}
					},o.delay);
				}		
			},
			getMenu = function($el){ return $el.parents('ul.superfish:first')[0]; },
			getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return $.superfish.op = $.superfish.o[el.serial]; },
			hasUl = function(){ return $.superfish.op.oldJquery ? 'li[ul]' : 'li:has(ul)'; };

		return this.each(function() {
			var s = this.serial = $.superfish.o.length;
			var o = $.extend({},$.superfish.defaults,op);
			o.$path = $('li.'+o.pathClass,this).each(function(){
				$(this).addClass(o.hoverClass+' '+bcClass)
					.filter(hasUl()).removeClass(o.pathClass);
			});
			$.superfish.o[s] = $.superfish.op = o;
			
			$(hasUl(),this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out)
			.not('.'+bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			
			o.onInit.call(this);
			
		}).addClass('superfish');
	};
	
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = $.superfish.op,
				$ul = $('li.'+o.hoverClass,this).add(this).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = $.superfish.op,
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ o.onShow.call(this); });
			return this;
		}
	});
	
	$(window).unload(function(){
		$('ul.superfish').each(function(){
			$('li',this).unbind('mouseover','mouseout','mouseenter','mouseleave');
		});
	});
})(jQuery);
;
(function ($) {

  Drupal.behaviors.barracudaSuperfish = {

    attach: function(context, settings) {
      $('#block-system-main-menu ul', context).superfish({
		delay: 500,											    
        animation: { opacity:'show' },
        speed: 500,
        autoArrows: false,
        dropShadows: false /* Needed for IE */
      });
    }
  };

})(jQuery);  
;
var ThishoodStream = (function($) {

	var Constructor = function(params) {

		var updateRelativeTimePeriodMs = 60000,
			getThreadCountPeriodMs = 120000;

		var pageTitle = document.title;

		var lastThreadDate = params.lastThreadDate || 0;
		var currentGroupId = params.currentGroupId || 0;
		var currentUserId = params.currentUserId || 0;
		var currentThreadId = params.currentThreadId || 0;
		var baseUrl = this.baseUrl = params.baseUrl || "";

		var fromDate = 0;
		var toDate = 0;

		var that = this;

		function updateRelativeTimes() {
			var relTime = Constructor.relativeTime;
			var els = document.querySelectorAll(".isoDate");
			var len = els.length;
			var ie, el, el1;
			for (ie = 0; ie < len; ie++) {
				el = els[ie];
				el1 = document.getElementById(el.id.substring(3));
				el1.innerHTML = relTime(el.innerText);
			}
			setTimeout(updateRelativeTimes, updateRelativeTimePeriodMs);
		}

		function onAjaxError(xhr) {
			if (xhr.status == 401) {
				document.location = baseUrl + "user/logout";
			}
		}

		function markLastNewThread(threadId) {
			$(".thStream .thread").removeClass("endNewThreads");
			$("#thread" + threadId).addClass("endNewThreads");
		}

		this.getThreads = function() {
			var stillWorking = true;
			setTimeout(function() {
				if (stillWorking) {
					var spinner = document.getElementById("streamSpinner");
					if (spinner) {
						spinner.style.display = "";
					}
				}
			}, 1000);
			var url = currentThreadId ? "threads/thread/view/" + currentThreadId : "threads/group/" + currentGroupId + "/user/" + currentUserId;
			$.ajax({
				url: baseUrl + url + "/fromdate/0/todate/" + toDate + "/" + Math.random(),
				success: onThreadsReceived,
				error: onAjaxError,
				complete: function() {
					stillWorking = null;
					var el = document.getElementById("streamSpinner");
					if (el) {
						el.style.display = "none";
					}
				},
				dataType: "json"
			});
		};

		function onThreadsReceived(threads) {
			var spinner = document.getElementById("streamSpinner");
			if (spinner) {
				spinner.style.display = "none";
			}
			var threadsLength = threads.length;
			if (threadsLength > 0) {
				var container = document.getElementById("threads");
				if (container) {
					$.tmpl("streamThread", threads).appendTo(container);
					var lastNewThread;
					if (!fromDate) {
						if (lastThreadDate) {
							var thread;
							for (var it in threads) {
								thread = threads[it];
								if (thread.dateUpdated <= lastThreadDate) {
									break;
								}
								$("#thread" + thread.threadId).addClass("new");
								lastNewThread = thread;
							}
							lastThreadDate = null;
						}
						fromDate = threads[0].dateUpdated;
					}
					toDate = threads[threadsLength - 1].dateUpdated;
					if (lastNewThread) {
						markLastNewThread(lastNewThread.threadId);
					}
				}
			}
			if (threadsLength < 20) {
				$("#moreButton").hide();
			}
		}

		this.getNewThreads = function() {
			suspendThreadCount();
			$(".thread.new").removeClass("new");
			var url = currentThreadId ? "threads/thread/view/" + currentThreadId : "threads/group/" + currentGroupId + "/user/" + currentUserId;
			$.ajax({
				url: baseUrl + url + "/fromdate/" + fromDate + "/todate/0/" + Math.random(),
				success: onNewThreadsReceived,
				error: onAjaxError,
				dataType: "json"
			});
			scheduleThreadCount();
		};

		function onNewThreadsReceived(threads) {
			if (threads.length) {
				fromDate = threads[0].dateUpdated;
				var it, thread, replies, repliesLength;
				for (it = threads.length - 1; it >= 0; it--) {
					thread = threads[it];
					replies = thread.replies;
					repliesLength = replies.length;
					if (repliesLength) {
						// Check replies
						if ($("#reply" + replies[repliesLength - 1].replyId).length) {
							// Last reply already displayed => not new
							threads.splice(it, 1);
						} else {
							// Move whole thread to top
							$("#thread" + thread.threadId).remove();
						}
					} else if ($("#thread" + thread.threadId).length) {
						// Thread already displayed => not new
						threads.splice(it, 1);
					}
				}
				if (threads.length) {
					var container = document.getElementById("threads");
					if (container) {
						$.tmpl("streamThread", threads).prependTo(container);
						for (it in threads) {
							$("#thread" + threads[it].threadId).addClass("new");
						}
						markLastNewThread(threads[threads.length - 1].threadId);
					}
				}
			}
			updatedThreadCount = 0;
			$("#newMessagesButton").hide();
			document.title = pageTitle;
		}

		var getThreadCountTimeout, gettingThreadCount, updatedThreadCount;

		function scheduleThreadCount() {
			if (!getThreadCountTimeout) {
				getThreadCountTimeout = setTimeout(getThreadCount, getThreadCountPeriodMs);
			}
		}

		function suspendThreadCount() {
			if (getThreadCountTimeout) {
				clearTimeout(getThreadCountTimeout);
				getThreadCountTimeout = null;
			}
		}

		function getThreadCount() {
			suspendThreadCount();
			if (!gettingThreadCount) {
				gettingThreadCount = true;
				var url = currentThreadId ? "threads/count/thread/" + currentThreadId : "threads/count/group/" + currentGroupId + "/user/" + currentUserId;
				$.ajax({
					url: baseUrl + url + "/fromdate/" + fromDate + "/" + Math.random(),
					success: onThreadCountReceived,
					error: onAjaxError,
					complete: function() {
						gettingThreadCount = null;
					},
					dataType: "json"
				});
			}
			scheduleThreadCount();
		}

		function onThreadCountReceived(count) {
			updatedThreadCount = count;
			if (count > 0) {
				var title = "(" + count + ") " + pageTitle;
				if (document.title != title) {
					document.title = title;
					var newMessagesButton = $("#newMessagesButton");
					newMessagesButton.html("<span>Click to see " + count + " new message" + (count > 1 ? "s" : "") + "</span>");
					newMessagesButton.show();
				}
			}
		}

		this.getReplies = function(threadId) {
			$.ajax({
				url: baseUrl + "threads/replies/thread/" + threadId + "/" + Math.random(),
				success: onRepliesReceived,
				error: onAjaxError,
				dataType: "json"
			});
		};

		function onRepliesReceived(replies) {
			// replyTemplate should be compiled already
			if (replies.length) {
				var containerId = "#replies" + replies[0].threadId;
				$(containerId).html("");
				$.tmpl("streamReply", replies).appendTo(containerId);
			}
		}

		this.createThread = function(form) {
			var message = $(form.message);
			if (message.val().length) {
				document.getElementById("threadPostButton").disabled = true;
				var stillWorking = true;
				setTimeout(function() {
					if (stillWorking) {
						var spinner = document.getElementById("threadPostSpinner");
						if (spinner) {
							spinner.style.display = "";
						}
					}
				}, 1000);
				var the = this;
				$.ajax({
					url: baseUrl + "threads/thread/create",
					global: false,
					type: "POST",
					data: $(form).serialize(),
					dataType: "json",
					success: function(threads) {
						if (threads && !threads.errors) {
							var container = document.getElementById("threads");
							if (container) {
								$(form.message).val("");
								Constructor.hideForm(form.id);
								form = null;
								$.tmpl("streamThread", threads).prependTo(container);
								var it, el;
								for (it in threads) {
									el = $("#thread" + threads[it].threadId);
									el.hide();
									el.addClass("highlighted");
								}
								el = null;
								for (it in threads) {
									$("#thread" + threads[it].threadId + ":hidden").fadeIn("slow", function() {
										$(this).removeClass("highlighted");
									});
								}
								the.getNewThreads();
								the = null;
							}
						} else {
							jAlert(threads.errors, 'Error on creating thread');
						}
					},
					error: onAjaxError,
					complete: function() {
						stillWorking = null;
						var el = document.getElementById("threadPostSpinner");
						if (el) {
							el.style.display = "none";
						}
						el = document.getElementById("threadPostButton");
						if (el) {
							el.disabled = false;
						}
						el = null;
					}
				});
				message.val("");
			}
			message = null;
		};

		this.deleteThread = function(threadId) {
			jConfirm("The thread will be deleted permanently. Are you sure?", "Please confirm", function (answer) {
				if (answer) {
					deleteThread(threadId);
				}
			});
		};

		function deleteThread(threadId) {
			$.ajax({
				url: baseUrl + "threads/thread/delete",
				global: false,
				type: "POST",
				data: "threadId=" + threadId,
				dataType: "json",
				success: function(response) {
					if (response && response.ok) {
						var el = $("#thread" + threadId);
						if (el.length) {
							el.addClass("deleted");
							el.hide("slow", function() {
								el.remove();
								el = null;
							});
						}
					} else {
						jAlert(response.errors, 'Error on deleting thread');
					}
				},
				error: onAjaxError
			});
		}

		this.disableComments = function(threadId) {
			$.ajax({
				url: baseUrl + "threads/thread/comments/disable",
				global: false,
				type: "POST",
				data: "threadId=" + threadId,
				dataType: "json",
				success: function(response) {
					if (response && response.ok) {
						//todo re-render?
						jAlert("Need to reload page (F5) because re-rendering is not implemented", "Comments are disabled", function(){})
					}
				},
				error: onAjaxError
			});
		};

		this.enableComments = function(threadId) {
			$.ajax({
				url: baseUrl + "threads/thread/comments/enable",
				global: false,
				type: "POST",
				data: "threadId=" + threadId,
				dataType: "json",
				success: function(response) {
					if (response && response.ok) {
						//todo re-render?
						jAlert("Need to reload page (F5) because re-rendering is not implemented", "Comments are enabled",function(){})
					}
				},
				error: onAjaxError
			});
		};

		this.createReply = function(form) {
			var reply = $(form.reply);
			if (reply.val().length) {
				var threadId = form.threadId.value;
				var postButtonId = "replyForm" + threadId + "Button";
				var postSpinnerId = "replyForm" + threadId + "Spinner";
				document.getElementById(postButtonId).disabled = true;
				var stillWorking = true;
				setTimeout(function() {
					if (stillWorking) {
						var spinner = document.getElementById(postSpinnerId);
						if (spinner) {
							spinner.style.display = "";
						}
					}
				}, 1000);
				var the = this;
				$.ajax({
					url: baseUrl + "threads/reply/create",
					global: false,
					type: "POST",
					data: "fromDate=" + fromDate + "&" + $(form).serialize(),
					dataType: "json",
					success: function(replies) {
						if (replies && !replies.errors) {
							$(form.reply).val("");
							Constructor.hideForm(form.id);
							form = null;
							var containerId = "#replies" + replies[0].threadId;
							var ir, reply, el;
							for (ir in replies) {
								reply = replies[ir];
								if (!$("#reply" + reply.replyId).length) {
									$.tmpl("streamReply", reply).appendTo(containerId);
									el = $("#reply" + reply.replyId);
									el.hide();
									el.addClass("highlighted");
								}
							}
							el = null;
							for (ir in replies) {
								$("#reply" + replies[ir].replyId + ":hidden").fadeIn("slow", function() {
									$(this).removeClass("highlighted");
								});
							}
							the.getNewThreads();
							the = null;
						} else {
							jAlert(replies.errors,"Error on create reply")
						}
					},
					error: onAjaxError,
					complete: function() {
						stillWorking = null;
						var el = document.getElementById(postSpinnerId);
						if (el) {
							el.style.display = "none";
						}
						el = document.getElementById(postButtonId);
						if (el) {
							el.disabled = false;
						}
						el = null;
					}
				});
			}
			reply = null;
		};

		this.deleteReply = function(replyId) {
			jConfirm("The reply will be deleted permanently. Are you sure?", "Please confirm", function (answer) {
				if (answer) {
					deleteReply(replyId);
				}
			});
		};

		function deleteReply(replyId) {
			$.ajax({
				url: baseUrl + "threads/reply/delete",
				global: false,
				type: "POST",
				data: "replyId=" + replyId,
				dataType: "json",
				success: function(response) {
					if (response && response.ok) {
						var el = $("#reply" + replyId);
						if (el.length) {
							el.addClass("deleted");
							el.hide("slow", function() {
								el.remove();
								el = null;
							});
						}
					} else {
						jAlert(response.errors, "Error on removing reply")
					}
				},
				error: onAjaxError
			});
		}

/*
		function updateUsersOnline() {
			$.ajax({
				url: baseUrl + "threads/usersonline/group/" + currentGroupId + "/" + Math.random(),
				success: onUsersOnlineReceived,
				error: onAjaxError,
				dataType: "json"
			});
			setTimeout(updateUsersOnline, 60000);
		}

		function onUsersOnlineReceived(users) {
			$("#usersOnlineCount").html(users.length);
			$("#usersOnlineList").html("");
			$.tmpl("streamUserOnline", users).appendTo("#usersOnlineList");
		}
*/

		// Init
		(function() {
			$(document.getElementById("threadTemplate")).template("streamThread");
			$(document.getElementById("replyTemplate")).template("streamReply");
			$(document.getElementById("userOnlineTemplate")).template("streamUserOnline");
			that.getThreads();
			setTimeout(updateRelativeTimes, updateRelativeTimePeriodMs);
			scheduleThreadCount();
//			updateUsersOnline();
		})();

	};

	Constructor.ampRegexp = /&/g;
	Constructor.gtRegexp = />/g;
	Constructor.ltRegexp = /</g;

	Constructor.escapeHtml = function(text) {
		if (typeof text == "string") {
			var the = Constructor;
			return text.replace(the.ampRegexp, "&amp;").replace(the.gtRegexp, "&gt;").replace(the.ltRegexp, "&lt;");
		}
		return "";
	};

	Constructor.nlRegexp = /\r\n|\r|\n/g;

	Constructor.nl2br = function(text) {
		if (typeof text == "string") {
			return text.replace(Constructor.nlRegexp, "<br/>");	
		}
		return "";
	};

	Constructor.urlPatternRegexp = /((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(?:(?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))*\))+(?:\(?:(?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))*\)|[^&=\s`!()\[\]{};:'".,<>?������]))/gi;
	Constructor.emailPatternRegexp = /(([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+)/gi;

	Constructor.parseMessage = function(msg) {
		var the = Constructor;
		msg = the.nl2br(the.escapeHtml(msg));
		msg = msg.replace(the.urlPatternRegexp, the.urlReplacer);
		msg = msg.replace(the.emailPatternRegexp, the.emailReplacer);
		return msg;
	};

	Constructor.urlSchemeRegexp = /^([\w]+:)?\/\//;

	Constructor.urlReplacer = function(str) {
		var url = Constructor.urlSchemeRegexp.test(str) ? str : "http://" + str;
		if (str.length > 60) {
			str = str.substring(0, 57) + "...";
		}
		return '<a href="' + url + '" title="' + url + '" target="_blank" ref="nofollow">' + str + '</a>';
	};

	Constructor.emailReplacer = function(str) {
		return '<a href="mailto:' + str + '">' + str + '</a>';
	};

	Constructor.isoDateRegexp = /([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?/;

	Constructor.isoDateToDate = function(isoDate) {
		isoDate = new String(isoDate);
		var d = isoDate.match(Constructor.isoDateRegexp);
		var offset = 0;
		var date = new Date(d[1], 0, 1);
		if (d[3]) {date.setMonth(d[3] - 1);}
		if (d[5]) {date.setDate(d[5]);}
		if (d[7]) {date.setHours(d[7]);}
		if (d[8]) {date.setMinutes(d[8]);}
		if (d[10]) {date.setSeconds(d[10]);}
		if (d[12]) {date.setMilliseconds(Number("0." + d[12]) * 1000);}
		if (d[14]) {
			offset = Number(d[16]) * 60 + Number(d[17]);
			offset *= ((d[15] == '-') ? 1 : -1);
		}
		offset -= date.getTimezoneOffset();
		return new Date().setTime(Number(date) + offset * 60 * 1000);
	};

	Constructor.niceValue = function(val, unit) {
		val = new String(val);
		var niceVal = val;
		niceVal += " ";
		niceVal += unit;
		if (val.substring(val.length - 1) == "1") {
			if (val.substring(val.length - 2) == "11") {
				niceVal += "s";
			}
		} else {
			niceVal += "s";
		}
		return niceVal;
	};

	Constructor.relativeTime = function(isoDate) {
		var date;
		if (typeof isoDate == 'number') {
			date = isoDate;
		} else {
			date = Constructor.isoDateToDate(isoDate);
		}
		var delta = parseInt((new Date().getTime() - date) / 1000);
		if (delta < 60) {
			return "less than a minute ago";
		} else if (delta < 120) {
			return "about a minute ago";
		} else if (delta < 2700) {
			return Constructor.niceValue(Math.round(delta / 60), "minute") + " ago";
		} else if (delta < 5400) {
			return "about an hour ago";
		} else if (delta < 86400) {
			return "about " + Constructor.niceValue(Math.round(delta / 3600), "hour") + " ago";
		} else {
			return Constructor.niceValue(Math.round(delta / 86400), "day") + " ago";
		}
	};

	Constructor.showForm = function(formId) {
		var container = $("#" + formId + "Container");
		if (container.length) {
			container.show();
			container = null;
		}
		$("#" + formId + "Placeholder").hide();
		$("#" + formId).show();
		var textarea = $("#" + formId + "Textarea");
		if (!textarea.attr("autoResizable")) {
			textarea.autoResize();
			textarea.attr("autoResizable", "1");
		}
		textarea.trigger("change.dynSiz");
		textarea.focus();
		textarea = null;
	};

	Constructor.hideForm = function(formId) {
		$("#" + formId).hide();
		$("#" + formId + "Placeholder").show();
	};

	return Constructor;

})(jQuery);;
function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if(results == null)
		return "";
	else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// Cookie routines from w3schools
function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) {
			return unescape(y);
		}
	}
	return (false); //no cookie found
}

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function deleteCookie(c_name) {
	setCookie(c_name, "", -1);
}

	// Handling of slow connection
function checkSlowConnection() {
	var param = getParameterByName('slowConnection');//is it passed in the URL
	var cookieName = "yufit" + "SlowConnection";//name of the cookie includes the name of the video we're showing

	if (param == 'true') { //passed in the URL
		setCookie(cookieName, 'true', 365); //set the cookie for a year
	} else if (param == 'false') { //turn it off
		deleteCookie(cookieName); 
	}

	var cookieSlowConnection = getCookie(cookieName);//check if the cookie is set
	if (cookieSlowConnection == 'true') { 
		return (true);
	} else {
		return (false);
	}
}
;

