	$(document).ready(function(){
		if(!tmb.readCookie('visited') || tmb.testing){
			tmb.build();
			tmb.start();
		}
	});
	tmb = {
		/**
		* Hi, Jonathan/Naomi! You can set these however you like
		**/
		heading : 'If you enjoyed this post', 
		copy : ''
		+'Then you may be interested in signing up for my newsletter. You\'ll never miss a blog'
		+' update, plus you\'ll get:<ul><li>The first three chapters of my book, Career Renegade'
		+'</li><li>A chance to win a 1-hour Renegade Biz Brainstorming Session valued at '
		+'$500 (monthly drawing)</li><li>Special "eTribe-only" dispatches and discounts, and...'
		+'</li><li>The secret to eternal life (hint: it involves chocolate)</li></ul>',
		finePrint : 'This form appears only once, and your email will never be shared.',
		nameH : 'your name', 
		emailH : 'your email', 
		submit : 'submit',
		delay : 30, // time in seconds before popup shows
		width : 540,
		height : 360,
		commentTrigger : true, // if set to true, popup will show when user scrolls to comments 
		siteUrl : 'www.jonathanfields.com/blog', // the url where we can find the tmb directory
		testing : false, // set to false while in production
		
		/**
		* No need to change anything below here
		**/
		build : function(){
			hiddenElements = [
			{ i : 'popup_meta_web_form_id', n : 'meta_web_form_id', v : '1483036279' }, 
			{ i : 'popup_meta_split_id', n : 'meta_split_id', v : '' }, 
			{ i : 'popup_unit', n : 'unit', v : 'awakeatthewheel' }, 
			{ i : 'redirect_6398a0ec81201de34a815d6ba407b48b', n : 'redirect', v : 'http://www.aweber.com/form/thankyou_vo.html' }, 
			{ i : 'popup_meta_redirect_onlist', n : 'meta_redirect_onlist', v : 'http://www.jonathanfields.com/blog' }, 
			{ i : 'popup_meta_adtracking', n : 'meta_adtracking', v : '' }, 
			{ i : 'popup_meta_message', n : 'meta_message', v : '1' }, 
			{ i : 'popup_meta_required', n : 'meta_required', v : 'name,from' },
			{ i : 'popup_meta_forward_vars', n : 'meta_forward_vars', v : '0' }
			];
			$('head')
				.append($('<link/>')
					.attr('rel', 'stylesheet')
					.attr('href', 'http://'+tmb.siteUrl+'/tmb/popup.css')
					.attr('type', 'text/css')
				);
					
			var popup = $('<div/>')
				.attr('id', 'tmb_popup')
				.hide()
				.prependTo('body');
			popup
				.append(
					$('<div/>')
						.attr('id', 'tmb_overlay')
				);
			var dialog = $('<div/>')
							.attr('id', 'tmb_dialog');
			popup.append(dialog);
			dialog
				.append(
					$('<div/>')
						.attr('id', 'tmb_popup-toprc')
					)
				.append(
					$('<div/>')
						.attr('id', 'tmb_popup-botrc')
					)
				.append(
					$('<div/>')
						.attr('id', 'tmb_popup-content')
						.append($('<a/>')
							.attr('href', '#')
							.attr('id', 'tmb_popup-close')
							.click(
								function(){
										tmb.close();
								return false;
								}
							)
						)
						.append(
							$('<div/>')
							.attr('id', 'tmb_popup-heading')
						)
						.append(
							$('<p/>')
							.attr('id', 'tmb_popup-copy')
						)
						.append(
							$('<form/>')
								.attr('id', 'tmb_popup-form')
								.attr('action', 'http://www.aweber.com/scripts/addlead.pl')
								.attr('method', 'post')
								.append(
									$('<table/>')
										.append(
											$('<tr/>')
												.append(
													$('<th/>')
														.attr('id', 'tmb_popup-nameH')
												)
												.append(
													$('<td/>')
														.append(
															$('<input/>')
																.attr('type', 'text')
																.attr('name', 'name')
															)
												)
										)
										.append(
											$('<tr/>')
												.append(
													$('<th/>')
														.attr('id', 'tmb_popup-emailH')
												)
												.append(
													$('<td/>')
														.append(
															$('<input/>')
																.attr('type', 'text')
																.attr('name', 'from')
															)
												)
										)								
								)
								.append(
									$('<a/>')
										.attr('id', 'tmb_popup-submit')
										.attr('href', '#')
								)
						)
						.append(
							$('<div/>')
								.attr('id', 'tmb_popup-finePrint')
							)
				);
				for(i in hiddenElements){
					var elm = hiddenElements[i];
					$('#tmb_popup-form')
						.append($('<input/>')
							.attr('type', 'hidden')
							.attr('id', elm.i)
							.attr('name', elm.n)
							.val(elm.v)
						);
				}		
		},
		setup : function(){
			$('#tmb_popup-heading').html(tmb.heading);
			$('#tmb_popup-copy').html(tmb.copy);
			$('#tmb_popup-nameH').html(tmb.nameH);
			$('#tmb_popup-emailH').html(tmb.emailH);
			$('#tmb_popup-finePrint').html(tmb.finePrint);
			$('#tmb_popup-submit')
				.html(tmb.submit)
				.click(function(){
					$('#tmb_popup-form').submit();
					return false;
				});
			var win = tmb.windowDimensions();
			var pageHeight = win[1] + tmb.scrollHeight();
			var pageWidth = win[0];
			var pageCenter = pageWidth/2;
			var dialogWidth = tmb.width;
			var dialogHeight = tmb.height;
			var dialogLeft = pageCenter - (dialogWidth/2);
			var dialogTop = (win[1]/2) - (dialogHeight/2);
			if(tmb.isIE6){
				dialogTop = tmb.scrollY() + (win[1]/2) - (dialogHeight/2);
				$('#tmb_dialog').css('position', 'absolute');
			}
			
			$('#tmb_overlay')
				.css('height', pageHeight + 'px');
			$('#tmb_dialog')
				.css({
					'width' : dialogWidth + 'px',
					'height' : dialogHeight + 'px', 
					'top' : dialogTop + 'px', 
					'left' : dialogLeft + 'px'
				});
		},
		open : function()
		{
			tmb.setup();
			$('#tmb_popup').show();
			tmb.createCookie('visited', '1', 186);
		},
		close : function()
		{
			$('#tmb_popup').hide();
		},
		start : function(){			
			tmb.endY = $('#commentlist').offset().top;
			var win = tmb.windowDimensions();
			if(tmb.endY < win[1] || !tmb.commentTrigger){
				tmb.timedOpen(tmb.delay * 1000);
			}
			else{
				setTimeout('tmb.trigger()', 1000);
			}
		},
		trigger : function(){
			var scroll = tmb.scrollY();
			var win = tmb.windowDimensions();
			if(scroll > (tmb.endY - win[1])){ 
				tmb.open();
			}
			else{
				setTimeout('tmb.trigger()', 1000);
			}
		},
		timedOpen : function(s){
			setTimeout('tmb.open()', s);
		},
		createCookie : function(name, value, days){
			if(days){
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else{
				var expires = "";
			}
			value = escape(value);
			document.cookie = name+"="+value+expires+"; path=/";
		},
		readCookie : function(name){
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return(unescape(c.substring(nameEQ.length,c.length)));
			}
			return null;
		},
		scrollY : function(){
			var scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
			}
			return scrOfY;
		},
		scrollHeight : function(){
			var scrOfY = 0;
			if( typeof( window.scrollMaxY ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.scrollMaxY;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollHeight;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollHeight;
			}
			return scrOfY;
		},
		windowDimensions : function(){
			var width = 0, height = 0;
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				width = window.innerWidth;
				height = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				width = document.documentElement.clientWidth;
				height = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				width = document.body.clientWidth;
				height = document.body.clientHeight;
			}
			return [ width , height ];
		},
		endY : 0,
		isIE6 : navigator.userAgent.toLowerCase().indexOf('msie 6') != -1
	}


