$(document).ready(function(){
	if($("#pullQuotes").length){ // only run if we have pullquotes on the page
		$("#pullQuotes").appendTo("#side");

		contentHeight = $("#article-content")[0].offsetHeight;
		sideTopHeight = $("#sideTop")[0].offsetHeight;
		numQuotes = $("#side blockquote.pullquote").length;

		/* This version chunks each quote into equal sections.  Makes for uneven gaps */
		// chunk = (contentHeight-sideTopHeight)/numQuotes;
	// 			console.debug("chunk = "+chunk);
	// 			$("#side blockquote.pullquote:not(:last)").each(function(){
	// 				curHeight = this.offsetHeight;
	// 				console.debug("curHeight = "+curHeight);
	// 				newMargin = chunk - curHeight;
	// 				console.debug("newMargin = "+newMargin);
	// 				$(this).css("marginBottom",newMargin)
	// 				console.debug(this);
	// 			});


		/* This version goes for equal white space */
		totalQuoteHeight = 0;
		$("#side blockquote.pullquote").each(function(){
			totalQuoteHeight += this.offsetHeight;
		});

		availableHeight = contentHeight-sideTopHeight; // total available height to fill up
		totalWhitespaceHeight = availableHeight - totalQuoteHeight; // total amount of white space we need to have
		perQuoteMargin = totalWhitespaceHeight/numQuotes; // how much margin to put on each quote
		$("#side blockquote.pullquote:not(:last)").css("marginBottom",perQuoteMargin);
	}


	/* Open links with rel="external" in a new window
	------------------------------------------------------------------ */
	$("a[@rel=\"external\"]").click(function(){
		this.target = "_blank";
	});

	/* add "odd" class to odd rows
	------------------------------------------------------------------ */
	$("table.tabular tbody tr:nth-child(odd)").addClass("odd");


	// get window height/width for popup sizes
	wHeight = self.outerHeight;
	wWidth = self.outerWidth;
	if($.browser.msie) {
		wHeight = document.documentElement.offsetHeight;
		wWidth = document.documentElement.offsetWidth;
	}

	popH = wHeight * .6;
	popW = wWidth * .6;

	/* Open audio in a new popup window
	----------------------------------------------------------------*/
	$(".audioPlay").popupwindow({height:150,width:350,center:2});

	/* Open scriptures in a new popup window
	----------------------------------------------------------------*/
	$(".scripture").popupwindow({height:popH,width:popW,center:2,scrollbars:1,toolbar:1,location:1});

	/* Open scriptures in a new popup window
	----------------------------------------------------------------*/
	$(".glossary_item").popupwindow({height:popH,width:popW,center:2,scrollbars:1,toolbar:1,location:1});

	// make glossary layers
	$("#helpText").insertAfter("#content");
	$("#helpText .glossary").append('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');
	$(".glossary_term").csHelp({targetCorner:"br",helpCorner: "tr", useSelf: true, offsetY:15, hideLinks:false});


});



/*
Popupwindow plugin for jQuery.
by: Tony Petruzzi
homepage: http://rip747.wordpress.com
plugin download: http://rip747.wordpress.com/2007/03/02/the-return-of-popupwindow-jquery-plugin/
Full file in same folder @ jquery.popupwindow.js
*/

jQuery.fn.popupwindow=function(p){var profiles=p||{};return this.each(function(index){jQuery(this).bind("click",function(){var setting,parameters,mysettings,b,a;mysettings=(jQuery(this).attr("rel")||"").split(",");settings={height:300,width:500,toolbar:0,location:0,scrollbars:1,status:0,resizable:1,left:0,top:0,center:1};if(mysettings.length==1&&mysettings[0].split(":").length==1){a=mysettings[0];if(typeof profiles[a]!="undefined"){settings=jQuery.extend(settings,profiles[a])}else{settings=jQuery.extend(settings,p)}}else{for(var i=0;i<mysettings.length;i++){b=mysettings[i].split(":");if(typeof settings[b[0]]!="undefined"&&b.length==2){settings[b[0]]=b[1]}}}if(settings.center==1){settings.top=(screen.height-(settings.height+110))/2;settings.left=(screen.width-settings.width)/2}if(settings.center==2){wHeight=self.outerHeight;wWidth=self.outerWidth;wX=self.screenX;wY=self.screenY;if($.browser.msie){wHeight=document.documentElement.offsetHeight;wWidth=document.documentElement.offsetWidth;wX=self.screenLeft;wY=self.screenTop}settings.top=(wHeight/2+self.wY)-settings.height/2;settings.left=(wWidth/2+self.wX)-settings.width/2}parameters="height="+settings.height+",width="+settings.width+",toolbar="+settings.toolbar+",location="+settings.location+",scrollbars="+settings.scrollbars+",status="+settings.status+",resizable="+settings.resizable+",left="+settings.left+",screenX="+settings.left+",top="+settings.top+",screenY="+settings.top;var name="PopUpWindow"+index;window.open(this.href,name,parameters).focus();return false})})};

/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-06-19 20:25:28 -0500 (Tue, 19 Jun 2007) $
 * $Rev: 2111 $
 *
 * Version 2.1
 */
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&parseInt($.browser.version)<=6){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};if(!$.browser.version)$.browser.version=navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];})(jQuery);

/*
 * Context Sensitive Help - jQuery plugin - Version 0.5
 *
 * Author - Aaron Barker
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 */

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5($){2 m=7;2 n=7;$.6.8=5(f){2 g=$.16({},$.6.8.10,f);3(g.W){3(!$(".9 R").1j("s")){$(".9 R").q("s").L(5(i){$(4).1x("<x K=\\"X\\">"+(i+1)+"</x> ")})}}$("#9 > V").E().q("9");$("#9 > U").E();3(g.s){$("#9 > V").q("s");$("#9 > U").q("s")}G 4.L(5(i){2 o=$.1L?$.16({},g,$4.1I()):g;3(!$(4).1j("1i")){3(g.1g)$(4).q("1f");3(!$(4).t("v"))$(4).t("v","1C"+i+1b.1B(1b.1A()*1y));2 c=$(4).t("15");2 d=$(c+" R x").1v();$(4).1t(" <x K=\\"X 1s\\">"+d+"</x>");2 e=g;$(4).p(5(){2 a=$(4).t("v");$(n).L(5(){3(c==n&&a!=m){}O{$.6.8.D("#"+$(4).t("v"))}});3(a!=m){$.6.8.F(4,c,e);n=c;m=$(4).t("v");2 b=4;e.H=e.u;$(T).Y("S.z",5(){e.u=7;$.6.8.F(b,c,e)})}O{n=7;m=7}G 7});3(!$(c).Q(".P").1K){$(c).1J("<a 15=\\"#d\\" K=\\"P 1f\\">"+g.1k+"</a>");$(c+" .P").p(5(){$.6.8.D(c);m=7;G 7})}$(4).q("1i")}})};$.6.8.10={1k:"1H",B:"1G",1h:"1F",1e:7,N:"1E",M:"1D",1d:0,1c:0,W:w,s:w,1a:w,u:w,1g:w};$.6.8.D=5(a){$(18).12("p.z");$(T).12("S.z");$(a).1z("17",5(){$(4).J({I:"",C:"",y:""})})};$.6.8.F=5(b,c,d){$(c).J({I:"14",C:"-11",y:"-11"}).1w();3(d.1e){2 e=b}O{2 e=$(b).13(d.B).Q(d.1h)[0]}2 f=$(e).1u();2 g=0;3(d.N.A("b")!="-1"){g=$(e)[0].Z}2 h=0;3(d.N.A("r")!="-1"){h=$(e)[0].19}2 i=0;3(d.M.A("b")!="-1"){i=$(c)[0].Z}2 j=0;3(d.M.A("r")!="-1"){j=$(c)[0].19}2 k=f.C+g+d.1c-i;2 l=f.y+h+d.1d-j;$(c).1r();$(c).J({I:"14",C:k,y:l});3(d.u)$(c).E().1q("17");3(d.H)d.u=d.H;3(d.1a){$(18).Y("p.z",5(){$.6.8.D(n);m=7})}3(d.B){$(b).13(d.B).Q("1p, 1o, 1n, 1m").p(5(a){a.1l()})}$(c).p(5(a){a.1l()})}})(1M);',62,111,'||var|if|this|function|fn|false|csHelp|helpText||||||||||||||||click|addClass||showForPrint|attr|animateIt|id|true|sup|left|foo|indexOf|parentElement|top|putBack|hide|positionHelp|return|animateItOrig|position|css|class|each|helpCorner|targetCorner|else|closer|find|h3|resize|window|h2|div|showFootnote|helpFootnote|bind|offsetHeight|defaults|1000px|unbind|parents|absolute|href|extend|fast|document|offsetWidth|closeAnywhere|Math|offsetY|offsetX|useSelf|hideForPrint|hideLinks|targetElement|csHelped|hasClass|closeText|stopPropagation|label|textarea|select|input|fadeIn|bgiframe|showForPrintInline|after|offset|text|show|prepend|100|fadeOut|random|floor|csHelperLink|tl|bl|dd|dl|Close|data|append|length|meta|jQuery'.split('|'),0,{}))

/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/*
Updated by Aaron Barker to use classes as paramaters instead of HREF query strings.  I also changed the inline handling back to the way it was, as it degrades better.
*/
var tb_pathToImage = "../images/loadingAnimation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){
	tb_init('a.thickbox, area.thickbox, input.thickbox, button.thickbox');//pass where to apply thickbox // AB - added button.thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).not(".thickboxed").click(function(){ // AB - Added check for "thickboxed" so we don't double up
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	var c = this.className || false; // AB - Added
	tb_show(t,a,g,c); // AB - Added the C parameter
	this.blur();
	return false;
	}).addClass("thickboxed"); // AB - Added the "thickboxed" class so we can run tb_init multiple times (for dynamic content) and not run on elements that already have the needed code
}

function tb_show(caption, url, imageGroup, classes) {//function called when the user clicks on a thickbox link  // AB - Aded classes parameter

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}

		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}

		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader

		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{
	   		baseURL = url;
	   }

	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images

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

			imgPreloader = new Image();
			imgPreloader.onload = function(){
			imgPreloader.onload = null;

			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth);
				imageWidth = x;
				if (imageHeight > y) {
					imageWidth = imageWidth * (y / imageHeight);
					imageHeight = y;
				}
			} else if (imageHeight > y) {
				imageWidth = imageWidth * (y / imageHeight);
				imageHeight = y;
				if (imageWidth > x) {
					imageHeight = imageHeight * (x / imageWidth);
					imageWidth = x;
				}
			}
			// End Resizing

			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");

			$("#TB_closeWindowButton").click(tb_remove);

			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;
				}
				$("#TB_prev").click(goPrev);
			}

			if (!(TB_NextHTML === "")) {
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);
					return false;
				}
				$("#TB_next").click(goNext);

			}

			document.onkeydown = function(e){
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}
			};

			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};

			imgPreloader.src = url;
		}else{//code to show html

//			var queryString = url.replace(/^[^\?]+\??/,''); // AB - Commented out
// 			var params = tb_parseQuery( queryString ); // AB - Commented out
			var params = tb_parseClasses( classes ); // AB - Added to use classes instead of query string
			if(url.match(/#([\w-]+)/))params["inlineId"] = url.match(/#([\w-]+)/)[1]; // AB - pulls the actual ID linked in the href, as this degrades better

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;

			if(params['type'] == "iframe"){	// either iframe or ajax window	 // AB - Changed to use passed parameter
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}

			$("#TB_closeWindowButton").click(tb_remove);

				if(params['type'] == "inline"){ // AB - Changed to use passed parameter
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"});
				}else if(params['type'] == "iframe"){ // AB - Changed to use passed parameter
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					seperator = "&"; // AB - Default scripts always assumes there is an existing query string, need to test for it
					if(url.indexOf("?")==-1)seperator = "?"; // AB - Added, see above
					$("#TB_ajaxContent").load(url += seperator+"random=" + (new Date().getTime()),function(){//to do a post change this load method // AB - Used seperator from above
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}

		}

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

	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

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

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

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

 // AB - This whole function is new
function tb_parseClasses ( classes ) {
	var Params = {};
	if ( ! classes ) {return Params;}// return empty object
	var Pairs = classes.split(" ");
	for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('_');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

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

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


