﻿// ==UserScript==
// @name           Better Facebook
// @namespace      http://userscripts.org/users/86416
// @include        http://*.facebook.com/*
// @include        http://facebook.com/*
// @include        https://*.facebook.com/*
// @include        https://facebook.com/*
// @include        http://*.facebook.tld/*
// @include        http://facebook.tld/*
// @include        https://*.facebook.tld/*
// @include        https://facebook.tld/*

// @exclude        http://*.channel.facebook.tld/*
// @exclude        http://static.*.facebook.tld/*
// @exclude        http://*.facebook.tld/ai.php*
// @exclude        http://*.facebook.tld/pagelet/generic.php/pagelet/home/morestories.php*

// @exclude        https://*.channel.facebook.tld/*
// @exclude        https://static.*.facebook.tld/*
// @exclude        https://*.facebook.tld/ai.php*
// @exclude        https://*.facebook.tld/pagelet/generic.php/pagelet/home/morestories.php*

// ==/UserScript==
/* 
Better Facebook
(c) 2009-2011 Matt Kruse
http://BetterFacebook.net
*/
var version = 5.951;
var DEBUG = false;
var PERFORMANCE = false;
var SCRIPT_TYPE = "greasemonkey";
var undef;

// Main Script
// -----------

(function() { 

// Specifically for Opera
if (window.opera && !/https?:\/\/[^\/]*\.?facebook\.[^\/]+\//.test(window.location.href)) { return; }






var ajax = function(props) {
//	unsafeWindow.console.log(JSON.stringify(props),props);
	GM_xmlhttpRequest(props);
}

// If showing the "Likebox" for BFB in FB, add some styles to control it before exiting
if (location.href.indexOf('likebox.php')>0 && location.href.indexOf('betterfb')>0) {
	GM_addStyle( ((<><![CDATA[
		#LikeboxPluginPagelet .app_content_174424289341 .actorPhoto { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341	.uiStreamStory { padding-right:0px; }
		#LikeboxPluginPagelet .app_content_174424289341	.connect_top { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .uiStreamStory ~ .uiStreamStory { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .fbConnectWidgetFooter { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 #load_more_stories { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .mainWrapper > .fcg { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .actorName { display:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .page_stream { border-top:none; }
		#LikeboxPluginPagelet .app_content_174424289341 .pvm { padding:0; }
	]]></>).toString()) );
	var insertViewPostLink = true;
	document.addEventListener('DOMNodeInserted',function(e) {
		if (!insertViewPostLink) { return; }
		var o=e.target; 
		if (o.nodeType == 3){o=o.parentNode;}
		if (o.nodeType==3) { return; }
		var tn = o.tagName;
		if (tn=="SCRIPT" || tn=="LINK" || tn=="INPUT" || tn=="BR" || tn=="STYLE") { return; }
		var footer = o.querySelector('.uiStreamFooter');
		if (footer) {
			insertViewPostLink = false;
			try {
				var li = document.querySelector('.uiStreamStory');
				var fbid = li.getAttribute('data-ft').match(/"fbid":"(\d+)/)[1];
				footer.innerHTML += '<a href="/betterfb/posts/'+fbid+'" target="_blank" style="padding-left:15px;text-decoration:underline;">&gt;&gt; view post</a>';
			} catch(e) { }
		}
	},false);
}

// Don't run on link redirects and some other cases
var excludes = ['/l.php?u','/ai.php','/plugins/','morestories.php'];
try {
	for (var i=0; i<excludes.length; i++) {
		if (location.href.indexOf(excludes[i])>0 ) { return; }
	}
} catch(e) { }

/*GM_PREFS*/
// ==================================================================
// Extension Option Persistence
// ==================================================================
function setValue(key,val,func) { 
	if (PERFORMANCE) { trace_start('setValue',null,true); }
	var do_set=function() { 
		if (PERFORMANCE) { trace_start('setValue',null,true); }
		try { 
			GM_setValue(key,val); 
		} catch(e) { 
			alert(e); 
		} 
		if(func) { 
			func(key,val); 
		} 
		if (PERFORMANCE) { trace_end('setValue',null,true); }
	};
	do_set.name="setValue.do_set";
	window.setTimeout(do_set,0);
	if (PERFORMANCE) { trace_end('setValue',null,true); }
}
function getValue(key, def, func) {
	if (PERFORMANCE) { trace_start('getValue',null,true); }
	// Key can be either a single key or an array of keys
	if (typeof key=="string") {
		return func(GM_getValue(key,def));
	}
	else if (typeof key=="object" && key.length) {
		var values = {};
		for (var i=0; i<key.length; i++) {
			var default_value = undef;
			if (typeof def=="object" && def.length && i<def.length) {
				default_value = def[i];
			}
			values[key[i]] = GM_getValue(key[i],default_value);
		}
		if (func) {
			return func(values);
		}
		else { return values; }
	}
    if (PERFORMANCE) { trace_end('getValue',null,true); }
    return undef;
}
/*/GM_PREFS*/


// ==================================================================
// Turn off auto-loading of Older Posts when footer is scrolled into 
// view. FB's code sucks and breaks when there are no posts and the
// footer is visible immediately!
// ==================================================================
function setScrollLoad(enabled) {
	try { 
		unsafeWindow.disableScrollLoad=!enabled;
	} catch(e) { }
}
setScrollLoad(false);

// Setup a fake UIIntentionalStream object if it doesn't exist, so FB's sloppy code won't break
if (!unsafeWindow.UIIntentionalStream || !unsafeWindow.UIIntentionalStream.instance) {
	unsafeWindow.UIIntentionalStream={instance:{loadOlderPosts:function(){}}};
}

// ==================================================================
// ERROR REPORTING
// Setup error-reporting really early so we can trap early errors
// ==================================================================
var showerror_container;
var show_errors = true;
function showexception(e) { var str = e.toString(); if(e.lineNumber){ str+=" line #"+e.lineNumber; } showerror(str); }
function showerror(msg,data) { if (show_errors) { if (data){msg+='<div class="bfb_data">'+(htmlescape(data).replace(/\n/g,"<br>"))+'</div>';} showusermessage(msg); } }
function showusermessage(msg) {
	if (!showerror_container) {
		addGlobalStyle('.bfb_error_container { position:fixed; z-index:999; top:5px; right:5px; width:300px; background-color:#cc5555; border:1px solid black; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; padding:5px; font-size:18px; color:white; text-align:center; max-height:800px; overflow:auto; } '+
			'.bfb_error_container .bfb_note { font-size:12px; } '+
			'#bfb_error_close { float:right; cursor:pointer; } '+
			'.bfb_error { border:1px solid #ccc; padding:2px; margin:5px; background-color:white; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; font-size:12px; color:black; text-align:left; } '+
			'.bfb_error .bfb_data { max-height:150px; overflow:auto; font-size:10px; border:1px solid #ccc; } '+
			'#bfb_error_link { text-decoration:underline; color:#ccccff; }');
		showerror_container = el('div','bfb_error_container',{id:'bfb_error_container'},null,"<img src=\""+delete_img+"\" id=\"bfb_error_close\">Better Facebook Error!<br><div class=\"bfb_note\">(These errors may be disabled in Options-&gt;Debug)</div><div class=\"bfb_note\">See the <a href=\"http://BetterFacebook.net/faq.php\">FAQ</a> for help!</div>");
		append(document.body,showerror_container);
		bind('bfb_error_close','click',function() { showerror_container.style.display="none"; });
	}
	var m = el('div','bfb_error',null,null,msg);
	append(showerror_container, m);
	showerror_container.style.display="block";
	m.scrollIntoView();
}

// ==================================================================
// TRACE functions
// ==================================================================
var performance_monitor_enabled = false;
var tracelog = "";
var trace_stack = "";
var trace_stats = {};
var trace_window = null;
var tracing_paused = false;
var trace_level = 0;
var trace_pad = function() {var pad = "";for (var i=0; i<trace_level; i++) {pad += "&nbsp;&nbsp;&nbsp;";}return pad;};
var trace = function(str) {tracelog += str+"<br>";};
var trace_func_name = function(f,args) {
	var n = "";
	if (typeof f=="function" ) {
		n = f.name;
		if (f && f.arguments && args) {
			n += "(";
			for (var i=0; i<f.arguments.length; i++) {
				if (i>0) { n += ","; }
				var arg = f.arguments[i];
				var a = "";
				if (typeof arg=="function") { a= "[func]"; }
				else if (typeof arg=="object") { a= "[object]"; }
				else if (typeof arg=="string") { a= "\""+arg+"\""; }
				else if (arg) { a= arg.toString(); }
				if (a.length>20) { a = a.substr(0,20) + "..."; }
				n += a;
			}
			n += ")";
		}
	}
	else if (f) { n = f; }
	if (!n) { n = "<anonymous function>"; }
	return n;
};
var trace_start = function(f,details,tracestack) {
	if (!performance_monitor_enabled || tracing_paused) { return; }
	if (typeof tracestack=="undefined") { tracestack=false; }
	var n = trace_func_name(f,false);
	var o = trace_stats[n];
	if (typeof o=="undefined") {
		trace_stats[n] = {name:n,count:0,start:0,elapsed:0};
		o = trace_stats[n]
	}
	o.count++;
	o.start = +(new Date);
	if (tracestack) {
		trace_log(trace_pad() + trace_func_name(f,true) +" "+(details||""));
		trace_level++;
	}
};
var trace_end = function(f) {
	if (!performance_monitor_enabled || tracing_paused) { return; }
	var n = trace_func_name(f,false);
	if (n) {
		var o = trace_stats[n];
		if (o && o.start) {
			o.elapsed += ( +(new Date) - o.start );
			trace_level--;
		}
	}
};
var trace_log = function(s,classname) {
	if (classname){s="<span class=\""+classname+"\">"+s+"</span>";}
	trace_stack += s+"<br>";
};
var trace_update = function() {
	if (!performance_monitor_enabled) { if (trace_update_interval!=null) { clearInterval(trace_update_interval); } return; }
	tracing_paused = true;
	if (trace_window==null) {
		var d = document.createElement('div');
		var content = '<div id="bfb_trace_window_header">BFB Debug Window <img src="https://s3.amazonaws.com/BFB/close_red_x.gif" style="cursor:pointer;float:right;" onclick="w=document.getElementById(\'bfb_trace_window\');if(w){w.style.display=\'none\';}"><br>';
		content += '<input type="checkbox" id="bfb_trace_cb_scroll_trace"> Auto-scroll ';
		content += '<input type="checkbox" id="bfb_trace_cb_insert"> Show DOM Inserts ';
		content += '<input type="checkbox" id="bfb_trace_cb_messages"> Show Messages ';
		content += '</div><div style="clear:both;"></div><div id="bfb_trace_window_body"></div><div id="bfb_trace_window_call_stack"></div>';
		d.innerHTML = content;
		d.id="bfb_trace_window";
		document.body.appendChild(d);
		var maxw = ( (window.innerWidth - 980)/2 - 40);
		if (maxw<300) { maxw=500; }
		d.style.maxWidth = maxw+"px";
		$('bfb_trace_window_call_stack').style.maxHeight = (window.innerHeight - 50 - 300)+"px";
		trace_window = d;
	}
	var f,trace_funcs=[];
	var h = '<table><thead><tr><th>Function</th><th>Calls</th><th>Elapsed</th><th>Avg</th></tr></thead><tbody>';
	for (f in trace_stats) {
		if (trace_stats[f].elapsed>20 || trace_stats[f].count>50) {
			trace_funcs.push(f);
		}
	}
	trace_funcs = trace_funcs.sort( function(a,b) { return trace_stats[a].elapsed<trace_stats[b].elapsed } );
	for (var i=0; i<trace_funcs.length; i++) {
		var o = trace_stats[trace_funcs[i]];
		h += "<tr><td>"+o.name+"</td><td>"+o.count+"</td><td>"+o.elapsed+"</td><td>"+(o.elapsed/o.count).toFixed(2)+"</td></tr>";
	}
	h += "</tbody></table>";
	html($('bfb_trace_window_body'),h);
	tracing_paused = false;
};
var trace_stack_update = function() {
	if (!performance_monitor_enabled) { if (trace_stack_update_interval!=null) { clearInterval(trace_stack_update_interval); } return; }
	tracing_paused = true;
	if (trace_stack!="") {
		var stack = document.getElementById('bfb_trace_window_call_stack');
		if (stack && stack.innerHTML && stack.innerHTML.length>2500000) {
			html(stack,"");
		}
		if (stack) {
			appendhtml(stack,trace_stack);
			if ($('bfb_trace_cb_scroll_trace','checked')) {
				stack.scrollTop=99999;
			}
			trace_stack = "";
		}
	}
	tracing_paused = false;
};
window.addEventListener('load',trace_update,false);
var trace_update_interval = setInterval(trace_update,5000);
var trace_stack_update_interval = setInterval(trace_stack_update,1000);

// ==================================================================
// UTILITY functions
// ==================================================================
function htmlescape(str) { if(typeof str=="string") { return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,"&quot;"); } return ""; }
function parse(str) { try { return JSON.parse(str); } catch (e) { return {}; } }
function _template(s) {if (PERFORMANCE) { trace_start('_template'); }for (var i=1; i<arguments.length; i++) {var arg = arguments[i];if ("object"==typeof arg) { for (var key in arg) { var val = arg[key]; if (typeof val=='undefined') {val = '';} s = s.replace( new RegExp("%"+key+"%","g"),val); } }		else { s = s.replace( new RegExp("%"+i+"%","g"),arg); }	}if (PERFORMANCE) { trace_end('_template'); }	return s;}
var convert_string_to_regex_matches = {};
function convert_string_to_regex(str) {if (typeof convert_string_to_regex_matches[str]!="undefined") { return convert_string_to_regex_matches[str]; }try {var matches = str.match(/^\/(.*?)\/(\w*)$/);var re = new RegExp(matches[1],matches[2]);convert_string_to_regex_matches[str] = re;return re;}	catch(e) { alert("Invalid regular expression:"+str); convert_string_to_regex_matches[str] = null; return null; }}
function trim(str) { if(!str){return str;} if (str.trim) { return str.trim(); } return str.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,""); }
function $(id,prop) { var el=document.getElementById(id); if(!el){return el;} if(typeof prop!="undefined"){return el[prop];} return el;}
function $first(o,cn,func) {if(!o){return null;} if (o && o.getElementsByClassName) { var cns = o.getElementsByClassName(cn); if (cns && cns.length) { if(func) { func(cns[0],o); }; return cns[0]; } } return null; }
function $$(cn,func,context) { $each((context||document).getElementsByClassName(cn),func); }
function $each(els,func){ if (els && els.length) { if (typeof func=="string") { func = new Function(func); } for (var i=els.length-1; i>=0; i--) { func.call(els[i],els[i]); } } }
function $tagname(o,tagname,func) { if(!o){return;}$each(o.getElementsByTagName(tagname),func); }
function bind(el,ev,func,capture) { if (typeof el=="string") { el = $(el); } if (typeof func=="string") { func = new Function(func); } if(typeof capture!="boolean"){capture=false;} if (el && el.addEventListener) { el.addEventListener(ev,func,capture); } }
function hasClass(o,re) {if(!o){return false;}if (typeof re=="string") {re = new RegExp("(^|\\s)"+re+"(\\s|$)");}return (o.className && re.test(o.className));}
function addClass(o,cn) {if(!o){return;}if (o.className==null || o.className=='') { o.className = cn; return;}if (hasClass(o,cn)) { return; }o.className = o.className + " " + cn; }
function removeClass(o,re) {if(!o){return;} if (!hasClass(o,re)) { return; } if (typeof re=="string") { re = new RegExp("(^|\\s)"+re+"(\\s|$)"); } o.className = o.className.replace(re,' '); }
function toggleClass(o,cn) {if(!o){return;} if(hasClass(o,cn)) { removeClass(o,cn); } else { addClass(o,cn); } }
function getParentByClass(el,cn){ if (hasClass(el,cn)){return el;} while(el=el.parentNode) { if(hasClass(el,cn)) { return el; } } return null; }
function parent(el,selector){ if (!el||!el.parentNode){return null;} if(!selector){return el.parentNode;} if (matchesSelector(el,selector)){return el;} while(el=el.parentNode) { if(matchesSelector(el,selector)) { return el; } } return null; }
function getParentByTag(el,tn){ tn=tn.toLowerCase();while(el=el.parentNode) { if(el && el.tagName && tn==el.tagName.toLowerCase()) { return el; } } return null; }
function parentChain(o){var s="";while(o){s+=outerHTML(o);o=o.parentNode;}return s;}
function outerHTML(o,esc){if(!o || !o.tagName){return (esc?"&lt;&gt;":"<>");}return (esc?"&lt;":"<")+o.tagName+(o.id?" id="+o.id:"")+(o.className?" class="+o.className:"")+(esc?"&gt;":">");}
function innerText(o){if(!o){return"";}if(typeof o.textContent!="undefined"){return o.textContent;} if(typeof o.innerText!="undefined"){return o.innerText;} return o.innerHTML;}
function prev(o,tag){if(!o){return null;}while(o=o.previousSibling){if(o.tagName==tag){return o;}}return null;}
function next(o,tag){if(!o){return null;}while(o=o.nextSibling){if(o.tagName==tag){return o;}}return null;}
function css(el,rules){rules.split(/\s*;\s*/).foreach(function(){ var keyval=this.split(':'); el.style[keyval[0]]=keyval[1]; });}
function removeChild(o){if(o&&o.parentNode&&o.parentNode.removeChild){o.parentNode.removeChild(o);}}
function QS(o,query,propfunc){if(!o||!o.querySelector){return null;}var m=o.querySelector(query);if(!m){return null;}if(typeof propfunc=="undefined"){return m;}if(typeof propfunc=="function"){return propfunc(m);}return m[propfunc];}
function QSA(o,query,func){if(!o||!o.querySelectorAll){return null;}var m=o.querySelectorAll(query);if(!m||m.length==0){return null;}if (typeof func=="string") { func = new Function(func); }if(typeof func!="function"){return m;}for(var i=0;i<m.length;i++){func.call(m[i],m[i]);}return m;}
function match(str,regex,func){if(typeof str!="string"){return null;}var m=str.match(regex);if(m&&m.length){if(typeof func=="function"){for (var i=regex.global?0:1;i<m.length;i++){func(m[i]);}return m;}else{return m.length>1?m[regex.global?0:1]:null;}}return null;}
function url_param(url,param){return unescape(match(url,new RegExp(param+'=([^&]+)','i'))); }
function encode_url_params(o){var u="";for(var i in o){if(u!=""){u+="&";}u+=encodeURIComponent(i)+"="+encodeURIComponent(o[i]);}return u;}
function clickLink(el,bubble) {if(!el){return;}if(typeof bubble!="boolean"){bubble=true;}var e = document.createEvent('MouseEvents');e.initEvent('click',bubble,true,window,0);el.dispatchEvent(e);}
function mouseEvent(el,event,bubble) {if(!el){return;}if(typeof bubble!="boolean"){bubble=true;}var e = document.createEvent('MouseEvents');e.initEvent(event,bubble,true,window,0);el.dispatchEvent(e);}
function press_key(o,code,type) { if(!o){return;}type=type||"keypress";var e=document.createEvent('KeyboardEvent'); if(typeof code=="string"){code=code.charCodeAt(0);} e[e.initKeyboardEvent?'initKeyboardEvent':'initKeyEvent'](type,true,true,window,false,false,false,false,false,code);  o.dispatchEvent(e); }
function time() { return (new Date()).getTime(); }
function delay(func,t){setTimeout(func,t||10);}
function split(str,del){if(typeof str!="string"){return [];}if(!str||!str.split){return [str];}return str.split(del);}
function hide(o){if(o&&o.style){o.style.display="none";}}
function show(o){if(o&&o.style){o.style.display="block";}}
function target(e){ var t=e.target; if (t.nodeType == 3){t=t.parentNode;} return t; }
function to_array(o){ var a=[]; if(o&&o.length) { for (var i=0;i<o.length;i++) { a.push(o[i]); } } return a; }
function object_to_array(o,key,desc){ var i,a=[]; for(i in o){ a.push(o[i]); } if(key){ return sort_array(a,key,desc); } return a; }
function array_to_object(a){var o={};if(a && a.length){for(var i=0;i<a.length;i++){o[a[i]]=a[i];} }return o; }
function sort_array(arr,key,desc){ var before=desc?-1:1; var after=desc?1:-1; return arr.sort( function(a,b){ var ta=typeof a[key]; var tb=typeof b[key]; if (ta=="undefined" && tb=="undefined"){return 0;} if (tb=="undefined"){return before;} if(ta=="undefined"){return after;} return (a[key]>b[key])?before:a[key]==b[key]?0:after; } ); }
function foreach(o,sorttype,func) {var a=[];for (var i in o) { a.push(i); }if (sorttype=='key') { a=a.sort(); }else if (sorttype=='value') { a=a.sort(function(a,b){ return (o[a]>o[b])?-1:o[a]==o[b]?0:1; }); }$each(a,function(){func(this,o[this])});}
function poll(func,interval,max){interval=interval||500;max=max||50;var count=0;var f=function(){ if(count++>max){return;}if (func()===false){ setTimeout(f,interval); } };f();}
// Add CSS to the page
function addGlobalStyle(css) {if (PERFORMANCE) { trace_start('addGlobalStyle'); }GM_addStyle(css);if (PERFORMANCE) { trace_end('addGlobalStyle'); }}
function insertStylesheet(url,id) { var link = el("link",null,{rel:"stylesheet",type:"text/css",href:url}); if(id){link.id=id;} document.getElementsByTagName("head")[0].appendChild(link); trace("Inserted stylesheet:"+url);}
// Mutation functions
// These set an internal flag to denote that we are doing the mutating, so the DOMNodeInserted handlers don't fire
function append(to,el){if(PERFORMANCE){trace_start('append');}if(to&&to.appendChild){ internalUpdate=true; for(var i=1; i<arguments.length; i++) { to.appendChild(arguments[i]); } internalUpdate=false; }; if(PERFORMANCE){trace_end('append');} return to;}
function insertBefore(el,ref){if(PERFORMANCE){trace_start('insertBefore');}internalUpdate=true; if(ref&&ref.parentNode){ref.parentNode.insertBefore(el,ref); internalUpdate=false;}if(PERFORMANCE){trace_end('insertBefore');}};
function html(el,h){if(PERFORMANCE){trace_start('html');}internalUpdate=true; if(typeof el=='string'){el=$(el);}if(el){el.innerHTML=h;} internalUpdate=false;if(PERFORMANCE){trace_end('html');}}
function appendhtml(el,h){if(PERFORMANCE){trace_start('appendhtml');}internalUpdate=true; if(el&&h){el.innerHTML+=h;} internalUpdate=false;if(PERFORMANCE){trace_end('appendhtml');}}
function insertFirst(container,el) {if(PERFORMANCE){trace_start('insertFirst');} insertAtPosition(container,el,1); if(PERFORMANCE){trace_end('insertFirst');}}
function insertAtPosition(container,el,pos) {if(PERFORMANCE){trace_start('insertAtPosition');} if (container && container.childNodes && container.childNodes.length) {var l = container.childNodes.length;if (pos<1) { pos=l+pos+1;}if (pos<1) { pos=1; } if (l>pos-1) { insertBefore(el, container.childNodes[pos-1]); } else { append(container,el); } }if(PERFORMANCE){trace_end('insertAtPosition');}}
function insertAfter(el,ref) { if(PERFORMANCE){trace_start('insertAfter');}var container, ns; if ( (container=ref.parentNode) && (ns=ref.nextSibling) ) { insertBefore(el, ns); } else if (container) { append(container,el); } if(PERFORMANCE){trace_end('insertAfter');}}
function scroll_to_top() {if (document.documentElement) {document.documentElement.scrollTop = 0;} if (document.body) {document.body.scrollTop = 0;}}
function delimited_string_add(str,add,del){str = str||"";del=del||",";var re = RegExp("(^|"+del+")"+add+"("+del+"|$)");if(!re.test(str)){str+=((str!="")?del:"")+add;}return str;}
function ago(when,now) {var diff = Math.floor((now-when)/1000/60);if (diff<60) { return diff+" minutes ago"; }diff = Math.floor(diff/60);if (diff<24) { return diff+" hours ago"; }diff = Math.floor(diff/24);return diff+" days ago";}
function setSelectionRange(input, selectionStart, selectionEnd) {if (input.setSelectionRange) {input.focus();input.setSelectionRange(selectionStart, selectionEnd);}else if (input.createTextRange) {var range = input.createTextRange();range.collapse(true);range.moveEnd('character', selectionEnd);range.moveStart('character', selectionStart);range.select();}}
function setCaretToPos (input, pos) {setSelectionRange(input, pos, pos);}
function current_style(o,s){ var a=window.getComputedStyle(o,null); if (a) { return a.getPropertyValue(s); } return null; }
function offset(obj) {
	var x= +obj.offsetLeft, y=+obj.offsetTop;
	while(obj=obj.offsetParent) {
		if (obj.offsetLeft) { x+= +obj.offsetLeft; }
		if (obj.offsetTop) { y+= +obj.offsetTop; }
	}
	return position = {left:x,top:y};
}
function matchesSelector(o,sel){
	if (o.matchesSelector){return o.matchesSelector(sel);}
	if (o.mozMatchesSelector){return o.mozMatchesSelector(sel);}
	if (o.webkitMatchesSelector){return o.webkitMatchesSelector(sel);}
	if (o.querySelectorAll && o.parentNode) {
		var matches = o.parentNode.querySelectorAll(sel);
		if (matches && matches.length) {
			for (var i=0; i<matches.length; i++) {
				if (matches[i]===o) { return true; }
			}
		}
	}
	return;
}
// ELEMENT CREATION
function el(type,cn,props,events,innerHTML,style) {
	if (PERFORMANCE) { trace_start('el'); }
	var o = document.createElement(type);
	if (cn) { o.className=cn; }
	if (props) {for (var i in props) {o[i] = props[i];}}
	if (events) {for (i in events) {o.addEventListener(i,events[i],false);}}
	if (innerHTML) {html(o,innerHTML);}
	if (style) {for (i in style) {o.style[i]=style[i];}}
	if (PERFORMANCE) { trace_end('el'); }
	return o;
}
function button(value,onclick,id) {
	if (PERFORMANCE) { trace_start('button'); }
	var button = el( 'input','',{type:'button','value':value},{click:onclick} );
	var span = el('label','uiButton UIButton UIButton_Blue UIFormButton UIButton_better_fb',{'id':id});
	append(span,button);
	if (PERFORMANCE) { trace_end('button'); }
	return span;
}
function message(str,okFunc,obj) {
	if (PERFORMANCE) { trace_start('message'); }
	var msg = el('div','better_fb_message');
	html( msg, '<div class="better_fb_bulb_spacer"></div>'+str );
	if (obj) { append(msg,obj); }
	okFunc = okFunc || (function(){});
	var ok = el('span','better_fb_close',{innerHTML:'OK'},{click:function() { okFunc(); this.parentNode.parentNode.style.display='none'; } } );
	var ok_wrap = el('div','bfb_close_wrap');
	append(ok_wrap,ok);
	append(msg,ok_wrap);
	append(msg,el('div','bfb_clear'));
	if (PERFORMANCE) { trace_end('message'); }
	return msg;
}
function minimessage(str,okFunc) {
	okFunc = okFunc || (function(){});
	return el('div','better_fb_mini_message',{innerHTML:str,title:'Click to close message'},{click:function() { okFunc(); this.style.display='none'; }} );
}
function quickmessage(str,duration,style) {
	duration = duration||5;
	var container = $('bfb_quickmessages');
	if (!container) {
		container = el('div',null,{id:'bfb_quickmessages'});
		append(document.body,container);
		container = $('bfb_quickmessages');
	}
	var msg = el('div','bfb_quickmessage',null,null,str);
	if (style) { for(var o in style){msg.style[o]=style[o];} }
	append(container,msg);
	setTimeout( function() { removeChild(msg); }, duration*1000 );
}
// Subscribing to Facebook's Arbiter-controlled events
function subscribe(event,func) {
	if (unsafeWindow && unsafeWindow.Arbiter && typeof unsafeWindow.Arbiter.subscribe=="function") {
		unsafeWindow.Arbiter.subscribe(event,function(a,b) {
			setTimeout(function(){ func(a,b); },10);
		});
	}
}

// ==================================================================
// DOM INSERTION
// ==================================================================
// Trigger a function when an element with a certain ID is added to the document
function onIdLoad(id,func,watch_stream) {
	if (PERFORMANCE) { trace_start('onIdLoad'); }
	var o = document.getElementById(id);
	if (o) { func(o,id,o); } // Call it right away if it already exists
	watchDOMNodeInserted('#'+id,func,watch_stream);
	if (PERFORMANCE) { trace_end('onIdLoad'); }
}
// Trigger a function when elements matching a selector is added to the document
function onSelectorLoad(selector,func,watch_stream) {
	if (PERFORMANCE) { trace_start('onSelectorLoad'); }
	var els = document.querySelectorAll(selector);
	if (els && els.length) { // Call it right away if it already exists
		for (var i=0; i<els.length; i++) {
			func(els[i],selector);
		}
	} 
	watchDOMNodeInserted(selector,func,watch_stream);
	if (PERFORMANCE) { trace_end('onSelectorLoad'); }
}
var internalUpdate = false; // FLAG to keep track of internal moves which should NOT trigger the DOMNodeInserted hooks!
var domNodeInsertedHandlers = {};
var domNodeInsertedStreamHandlers = {};
function watchDOMNodeInserted(selector,func,watch_stream) {
	var f = {"selector":selector,"handler":func};
	if (watch_stream==="both" || watch_stream) {
		if (typeof domNodeInsertedStreamHandlers[selector]=="undefined") {
			domNodeInsertedStreamHandlers[selector]=[];
		}
		domNodeInsertedStreamHandlers[selector].push(f);
	}
	if (watch_stream==="both" || !watch_stream) {
		if (typeof domNodeInsertedHandlers[selector]=="undefined") {
			domNodeInsertedHandlers[selector]=[];
		}
		domNodeInsertedHandlers[selector].push(f);
	}
}
// Fire a list of handlers on an element when it is inserted
function elementLoad(o,handler_list) {
	delay(function() {
		for (selector in handler_list) {
			var els= to_array(o.querySelectorAll(selector));
			if (matchesSelector(o,selector)) {
				els.push(o);
			}
			if (els) {
				var funcs = handler_list[selector];
				for (var i=0; i<funcs.length; i++) {
					for (var j=0; j<els.length; j++) {
						funcs[i].handler(els[j],selector,o); 
					}
				}
			}
		}
	},10);
}

// ===================================================
// UNLOAD HANDLER
// ===================================================
// Trigger a function when an element with a given ID is removed from the document
var onUnload = (function() {
	var unloadselectors = "";
	var unloadhandlers = {};
	window.addEventListener('DOMNodeRemoved',function(e) {
		if (PERFORMANCE) { trace_start('DOMNodeRemoved',null,true); }
		if (unloadselectors=="") { return; }
		var o = e.target;
		if (o.nodeType==3 || internalUpdate) { return; }
		var tn = o.tagName;
		if (tn=="SCRIPT" || tn=="LINK" || tn=="BR" || tn=="STYLE") { return; }
		var els = to_array(o.querySelectorAll(unloadselectors));
		if (unloadhandlers[o.id]) {
			els.push(o);
		}
		for (var i=0; i<els.length; i++) {
			var id = els[i].id;
			var funcs = unloadhandlers[id];
			if (funcs) {
				var newfuncs = [];
				for (var j=0; j<funcs.length; j++) {
					funcs[j].f.call(els[i],[els[i]]);
					if (funcs[j].persist) {
						newfuncs.push(funcs[j]);
					}
				}
				unloadhandlers[i] = newfuncs;
			}
		}
		if (PERFORMANCE) { trace_end('DOMNodeRemoved',null,true); }
	},false);
	return function(ids,func,persist) {
		if (typeof ids=="string") {
			ids=[ids];
		}
		for (var i=0; i<ids.length; i++) {
			var id = ids[i];
			unloadselectors = delimited_string_add(unloadselectors,'#'+id);
			unloadhandlers[id] = unloadhandlers[id] || [];
			unloadhandlers[id].push({'f':func,'persist':persist});
		}
	}
})();

/* Trigger a function when an element exists and has content */
function onElementContent(id,func,doc,delay,count) {
	delay = delay || 500;
	doc = doc || document;
	count= count||0;
	var o = doc.getElementById(id);
	if (o==null || !o.childNodes || o.childNodes.length==0) {if (count++>30) {func(null);}else {setTimeout( function() { onElementContent(id,func,doc,delay,count) } ,delay);}}
	else {func(o);}
}

// ===================================================
// "Select All" friends in events popup
// ===================================================
onSelectorLoad('.fbProfileBrowserListContainer',function(o) {
	if (QS(o,'.checkableListItem')) {
		if ($('bfb_select_all_friends')==null) {
			var dialog_content = getParentByClass(o,'dialog_content');
			var tbody = QS(dialog_content,'.filterBox tbody');
			var select_all = button('Select All',function() { QSA(dialog_content,'.checkableListItem a.anchor',function(a) { clickLink(a); }); },'bfb_select_all_friends');
			var tr = append( el('tr'), append( el('td',null,{colSpan:2},null,null,{textAlign:'right'}), el('span',null,null,null,'(Scroll user list to bottom to load all friends before clicking Select All!)'), select_all) );
			append(tbody, tr);
		}
	}
});

// ===================================================
// Don't run in frames
// ===================================================
try {
	if (window.frameElement || unsafeWindow.frameElement) { return; }
	var tryagain = true;
	try {
		if (window && window.self && window.top) {
			if (window.self!=window.top) {
				return;
			}
			tryagain = false;
		}
	} catch(e) { }
	if (tryagain) {
		if (typeof unsafeWindow!="undefined" && (unsafeWindow!=unsafeWindow.top || unsafeWindow!=unsafeWindow.parent)) { 
			return;
		}
	}
} catch(e) { return; }

// ===================================================
// Activate a theme url
// ===================================================
function apply_theme(url,default_url) {
	var theme_style = $('bfb_theme');
	if (typeof url=="undefined") { url = default_url; }
	if (!theme_style) {
		if (url) { insertStylesheet(add_theme_url_parameters(url),'bfb_theme'); }
	}
	else {
		if (url) { theme_style.href=add_theme_url_parameters(url); }
		else { removeChild(theme_style); }
	}
}
function add_theme_url_parameters(url) {
	var now = new Date();
	url = url.replace(/bfb_theme_year/g,now.getFullYear());
	url = url.replace(/bfb_theme_month/g,now.getMonth());
	url = url.replace(/bfb_theme_date/g,now.getDate());
	url = url.replace(/bfb_theme_hour/g,now.getHours());
	url = url.replace(/bfb_theme_minutes/g,now.getMinutes());
	url = url.replace(/bfb_theme_seconds/g,now.getSeconds());
	return url;
}

// ==================================================================
// REMOTE CONTENT
// ==================================================================
var window_href = "";
var protocol = "http:";
var host = "facebook.com";
try { window_href = location.href; } catch(e) { } 
try { protocol = location.protocol; } catch(e) { } 
try { host = location.host; } catch(e) { }
var url_prefix = protocol+'//'+host;
var remote_content = {
	typeahead: { type:'xhr', url:url_prefix+'/ajax/typeahead_search.php?__a=1', headers:{'Content-type':'application/x-www-form-urlencoded'}, ttl:3600 }
	,friend_lists: { type:'xhr', url:url_prefix+'/friends/ajax/superfriends.php?__a=1&all_lists=true', headers:{'Content-type':'application/x-www-form-urlencoded'}, ttl:3600 }
	,group_activity: { type:'iframe', url:url_prefix+'/groups.php', ttl:3600 }
	,friend_activity: { type:'iframe', url:url_prefix+'/home.php?sk=ru', ttl: 3600 }
};
function get_remote_content(type,func,ref,force_refresh) {
	if (PERFORMANCE) { trace_start('get_remote_content'); }
	var rc = remote_content[type], response;
	if (rc) {
		// First check the cache!
		var type_key = userid+"/"+type;
		var last_check_prop = type_key+'/last_check';
		getValue([last_check_prop,type_key],[0,null],function(values) {
			var last_check = +values[last_check_prop];
			var cache = values[type_key];
			var t = time();
			if (!force_refresh && cache && ( (t-last_check) <= (rc.ttl*1000)) ) {
				// Use cached content!
				trace("Using cached content for type:"+type);
				func(cache);
			} else {
				if (typeof rc.queue=="undefined") { rc.queue=[]; }
				// Add the func to the queue
				rc.queue.push(func);
				trace("Refreshing cached content for type:"+type);
				// Only start loading if it's not already been started
				if (typeof rc.loading=="undefined" || !rc.loading) {
					rc.loading = true;

					// Get new content
					if (rc.type=='xhr') {
						var headers = rc.headers || {}; headers['Cache-Control']='no-cache';
						var method = rc.method || 'GET';
						var url = rc.url;
						url += (url.indexOf('?')>0?'&':'?')+'time='+t;
						try {
							ajax({'method':method,'headers':headers,'url':url,'onload':function(res) { 
								rc.loading = false;
								if (res.responseText==null || res.responseText=="") {
	//								showerror("No response received for remote content: "+type);
									return;
								}
								// Call each queued function
								var save_value = true;
								while (rc.queue.length) {
									var func = rc.queue.shift();
									var dosave = func(res.responseText); 
									if (dosave===false) {
										save_value=false;
									}
								}
								if (save_value) {
									setValue(last_check_prop,""+t);
									setValue(type_key,res.responseText);
								}
							}});
						} catch(e) {
							showerror('An error occurred while trying to retrieve remote data from url: <a href="'+url+'">'+url+'</a>. The error is:<br>'+e.toString());
						}
					}
					else if (rc.type=='iframe') {
						var iframe = el("iframe",null,{src:rc.url});
						iframe.style.display="none";
						iframe.addEventListener('load',function(e) {
							try {
								rc.loading = false;
								var doc = e.target.contentDocument;
								setValue(last_check_prop,""+t);
								var val = null;
								while (rc.queue.length) {
									var func = rc.queue.shift();
									val = func(doc);
								}
								if (val!=null) {
									setValue(type_key,""+val);
								}
								if (iframe && iframe.parentNode) { iframe.parentNode.removeChild(iframe); }
							}
							catch (e) { showexception(e); }
						},false);
						append(ref,iframe);
					}
				}
			}		
		});
	}
	if (PERFORMANCE) { trace_end('get_remote_content'); }
}
function load_remote_content(type,ref,func,loading_msg,empty_msg,force_refresh) {
	if (PERFORMANCE) { trace_start('load_remote_content'); }
	if (loading_msg) { html(ref,loading_msg); }
	get_remote_content(type,function(res) {
		var content = func(res) || empty_msg;
		html(ref,content);
		if (PERFORMANCE) { trace_end('load_remote_content'); }
		return content;
	},ref,force_refresh);
	if (PERFORMANCE) { trace_end('load_remote_content'); }
}
function fetch_content_in_iframe(url,id,func) {
	var iframe = el("iframe",null,{src:url});
	iframe.style.visibility="hidden";
	iframe.style.position="absolute";
	iframe.addEventListener('load',function(e) {
		try {
			var doc = e.target.contentDocument || e.target.contentWindow.document;
			var check = function() {
				var e = doc.getElementById(id);
				if (e) { 
					func(e); 
					e=null; doc=null; iframe.src = null;
					if (iframe && iframe.parentNode) { iframe.parentNode.removeChild(iframe); }
					iframe=null;
				}
				else { setTimeout(check,200); }
			};
			check();
		}
		catch (e) { showexception(e); }
	},false);
	append(document.body,iframe);
}
function get_friend_lists(func) {
	get_remote_content('friend_lists', function(result) {
		var friend_lists = parse(result.substring(9),"Friend Lists");
		if (!friend_lists.payload || !friend_lists.payload.collections) { 
			func(null); 
			return false; 
		}
		return func(friend_lists.payload.collections);
	});
}

// ==================================================================
// CONSTANTS
// FACEBOOK CLASS NAMES, ETC
// ==================================================================
var feedCommentClass = "commentList";
var timestampClass = " uiStreamSource timestamp ";
var streamContainerSelector = ".UIIntentionalStream_Content,.group_mall";
var streamCollapsedClass = "uiStreamCollapsed";
var storySelector = ".uiUnifiedStory,.mall_post";

var delete_img = "data:image/gif,GIF89a%15%00%15%00%F7%FF%00%FF%F4%FF%FF%F8%F9%EC%89_%DC%5B2%D85%19%DF%5DL%F3aH%E2M%2C%DDR-%D5K%1D%A32%0F%E6Y%3E%E6V%2B%E2qa%FE%FE%FE%E9%3E%09%CBI%23%E6%83j%EAR2%DBb%3B%E2c4%DES3%E9iN%FC%FD%FF%D8%2C%05%CCR)%E2%5DA%E8pK%DBkD%F8%FF%FF%F6%FE%FF%ECK%14%CF%3C%0B%FB%FD%FA%FC%FF%FF%ED%7Bi%B5%2C%03%E7kI%FF%FF%FB%E2tS%DDcE%D6B%0C%DF%5D%3C%D1N%24%F3%8Bs%DBW%3C%EC%5D%3C%D9D%15%B43%13%E2V%26%E5P%1B%E4%7Db%DDZ*%AC*%04%A8.%13%EDlT%E6nV%FF%FF%FD%FF%FF%F8%E2sZ%E6L%16%EBN%23%E6bB%E5b%3C%D9F%1A%E2Z6%AB%3C%22%EAa3%FC%FC%FB%B12%19%E6Q2%E2N'%FD%FF%F9%AD9%1E%E4M%18%E9%7Fb%E3J%0D%E7xe%BA%25%06%E3cA%FF%FD%FD%FF%FB%FD%FD%FF%F3%E6rZ%E9jG%E4L%1C%E3N%23%FF%FD%FF%FF%FC%FF%FF%FB%FF%FF%F9%FF%FB%FF%FF%FF%FF%F4%FB%FF%FD%FF%FD%FE%FF%FF%DE%EE%5CC%EAQ%25%EB%88k%E1S%3D%E5%5DM%D7B%17%ED%A2%83%DAD%2B%E9N0%B0.%0C%EA%B2%99%E1%3F%18%DE%60-%E6cG%CEF%1E%E2%8Cq%D80%01%DD8%00%E0V%17%ED%A4%91%EB%AB%90%A5%3F%17%AE7%19%F9%89u%E6jR%E4%80q%F0WO%F7%FF%FE%B2D%2B%A9%26%00%ED%96x%E2t%5D%E4I%18%E9M%1C%EEYC%E0K%23%E3W6%CF%40%16%E5%60M%E0dL%DDt%5E%E1iD%E4%5D%25%EBZ-%E3G)%E8%60F%D2A%22%FCh%5E%D8D%1F%E9bN%DFO*%EByU%F6td%C8%3D%20%E7%90t%ED%90q%FF%FA%F1%F0g%40%FF%FB%F5%DBK3%FF%FC%F9%FF%FD%FA%E0C%18%E6%88l%EB%82b%EA%82i%EEgT%E4v%5B%EDy%60%EE%80a%EF%7Cg%EB%EF%FB%E2fB%E2fG%DCnU%F3%C0%95%E7fF%F9%FF%FD%E8v%5C%DF%EE%F4%EA%E6%FD%D70%03%E1%7FR%D38%0C%EDpP%D96%0B%ED%8F%83%DD8%0B%EE%C5%C1%EAQ%17%F4%CE%C1%EF%A6%9D%F6%FC%FA%A36%15%DF%8Fx%AE4%11%F2%D2%DD%F8%B8%B8%E1G%0B%B20%11%ECA%0D%EEI%0F%E0iS%E8j%5E%E0nS%C5)%03%E6nS%F7%FF%F2%EA%89v%E8nI%EBpN%EClM%A8%40%25%DFrS%B10%08%FF%DA%DF%A2%20%00%EEwa%EBa%22%AE-%0E%E8%90x%B2Q1%ED%92%7F%EC%94%7C%DFW%1D%DCK%1E%E0uY%D5Z1%F6%CA%E1%FC%D3%E3%DDjK%E0N%1F%E7fQ%F1%9B%84%F2%9F%8F%FC%FC%F2%FF%FD%F0%E7%5D%40%F5q%5C%EF_D%E6E%11%E4M%20%E7P)%E6T%23%E1R2%E9sY%E8v%5B%E2%5C%13%EEwY%E1F0%E3M4%F5%FE%FF%E0i%3F%D9A%02%F3%5BD%EDh%3B%CEJ%1A%FF%FE%FF%FF%FF%FF%FF%FF%FF!%F9%04%01%00%00%FF%00%2C%00%00%00%00%15%00%15%00%00%08%FF%00%FF%FD%3B%D5o%0B%00%1D%FD%FA%5D%F0%D7%C1%1F%2F%11%0E%FC%E5%B8%22%F0%DF4lMN%882D%26%92%86t%DF%5CH%40%20%C1%5D%99%0C%E1%FEu%B94g%97%1FK%BE%22%CCX%B2d%94%ABx%D1%C4%15%18%E0%26%1B%2C%2C%23%E8%A81%C3%E2%0E%A8R%A5f%8C%F83%E5Y3%1F%84%CE%FC%0A%20B%5E9s%DBX%E415%C9%19%AD%12%CF%D6qH%A7%A1%C2%A6%5E%FDZm%D0f%8B%99.%24%7F%10%91%D3%C7%A1E%81%2F%C1%DC%D1X!%24%CB%15%3Co%04%7C%F2%D7%AF%83%85T((%8C%D9%B3%C7%81%91%0A%2B%92%F4%F3%D2(%94%98%3CM%88D%C9%91N%8F%91~%9A%02%208%80%80o%3F%1D%16%9A%D0%AB%F6%C8%5B%0E%0F%5C%D888w%A5%5B%A0%23%92%22%7B!%A2b%07%25Y%3Bv%18%CB%A1%C5%C1%96%0B%0Cz0%B2r%24%81%1D%7F%7B%82%1C%3BA%0A%C7%8D%7D%A8%3ALf%10%03%8D%8CvV%12%14%FD%F1%D7%C9%DE%8D)%AA%9C%E1%40%86%C5%DF%15%24%FD%B8%C5%F8%D0%AE%0A%90_WL%C0C%E1C%5D%83%0D%26%5C%10%02%05%22h%81%8E%0C%3D(%01%C8%0B%C3%F8s%C18%13P%C1%8A2R%60!E%26%A9%1C%A2%C52%FD%E4%C2%03%20)%5C%E3%40%17%9E%2C%F0%84%01%26%B4%E2%05%15%99%FC0%845%98%F8U%0C%3B%B3%90%10%00%14%8C%240%01%18%B8D%81%CF%13m%24%A2%88%0B%0Cp%B2%0A%13%0F%D4R%03%14%FD%DCR%85%0A%03h%A0%82%20.%0E%B0%C8%3C%EF%84%C1%840%0F%60P%03a%04%40R%0F%02%DF%D0%D0B%051H%40%88%1C%83%14CL%3Eq%C0A%8D%0E%AF%40%40%40%25%908%02A%02%10%00%C1O!k%A4%00%02%08%B1%60%90%0C4%F7%FC%03%0C%1F%0A%D80%0C%0C6%14%A1%00%0Ci%90%20%8D%13N%90%D0G%1D%E0Tt%05%17X%88%80%85%0E%178%B0%87%7BHt%B0%07%16X%BC%22P%40%00%3B";
var pause_img = "data:image/jpeg,%FF%D8%FF%E0%00%10JFIF%00%01%01%00%00%01%00%01%00%00%FF%DB%00%84%00%09%06%06%0C%06%05%09%08%07%08%0A%0E%09%0A%0D%16%0E%0D%0C%0C%0D%1A%13%14%10%16%1F%1C!%20%1F%1C%1E%1E%23'2*%23%25*%25%1E%1E%1F%3B%2C%2F3*8%2C8%15*15B*5%26%2B%3A)%01%09%0A%0A%0D%0B%0D%19%0E%0D%19)%1C%16%244*))))))%2C)))))))))))))))%2C))))))))))%2C))))))))))))))%FF%C0%00%11%08%00%14%00%14%03%01%22%00%02%11%01%03%11%01%FF%C4%00%1A%00%00%02%02%03%00%00%00%00%00%00%00%00%00%00%00%00%00%06%01%04%02%05%07%FF%C4%000%10%00%00%05%02%02%05%0C%03%00%00%00%00%00%00%00%00%00%01%02%03%05%04%06%11%12%07%13AQR%2312Sadq%92%A3%B2%B3%D1%16!%22%FF%C4%00%17%01%01%01%01%01%00%00%00%00%00%00%00%00%00%00%00%00%02%03%01%00%FF%C4%00%16%11%01%01%01%00%00%00%00%00%00%00%00%00%00%00%00%00%00%01%11%FF%DA%00%0C%03%01%00%02%11%03%11%00%3F%00q%9E%98%8B%B2%AC%E8%E9Yx%EDj*5l%F2%0C6%B5%9A%D4%83V'%98%CB%84%C5%5B%8E%F6%83%B6!%A1%A4kb%1DS3%2Ck%E9%C9%9Af%8DINT%2B%FA%C5E%81%F2%85%CD%8E%D0%B9%A6%A7%B3%E8%A6%19%3B%AA%98%F8%5C%0A%FAWs%3D%87%60%17%0Ci%97%A6%C0wFH%E9W%AD%1BTS-6%CB-!%26%C1%2B%04%A4%88%BAJ%00%9B%D9%DDd%CBG%DD%D3%EEP%03%CA%9E%AA%D3%5C%B5%0DS6%DAP%CE%08A%11b%93%D8%5E%23%3F%CA%EAz%B6%3C%A7%F6%00%0A%03%5B%2B(%E5mR%5Cu-%E6%24%11~%88%F7%9Fh%80%00s_%FF%D9";
var play_img = "data:image/gif,GIF89a%14%00%14%00%F7%00%00%00%00%00%FF%FF%FF%F8%F8%FA%F5%F6%FB%F3%F4%F9%F0%F1%F6%EE%EF%F4%ED%EE%F3%EB%EC%F1%E3%E4%E9%FA%FB%FF%F9%FA%FE%F0%F1%F5%EF%F0%F4%7F%83%8E%81%85%90%84%87%90%DF%E3%EE%DE%E2%ED%DD%E1%EC%DA%DE%E9%E3%E7%F2%DC%DF%E8%DA%DD%E6%E9%EC%F5%86%89%90%E0%E4%ED%DE%E2%EB%E2%E6%EF%EE%F1%F8%E8%EB%F2%E6%E9%F0%E4%E7%EE%DF%E2%E9%7C%82%8E%D9%DF%EB%D8%DE%EA%D7%DD%E9%EB%EC%EEz%82%8F%D4%DD%EC%D6%DE%EB%88%8B%90%87%8A%8F%86%89%8E%8C%8F%94%F4%F7%FC%F2%F5%FA%EF%F2%F7%EC%EF%F4%EB%EE%F3%EA%ED%F2%E9%EC%F1%DB%E2%EC%D5%DC%E6u%82%93dlw%83%8B%96%D8%E5%F6%D7%E4%F5%D5%E2%F3%D2%DF%F0%88%90%9B%D0%DC%EC%9F%A7%B2%D0%D8%E3%D9%E1%EC%D8%E0%EBv%83%93%82%8F%9F%CA%D7%E7%C7%D4%E4%D0%DD%ED%CF%DC%EC%CE%DB%EB%DA%E7%F7%D6%E3%F3%D1%DB%E7%D7%E1%ED%D5%DF%EB%8B%90%96%F4%F9%FF~%85%8D%8E%95%9D%EA%F1%F9%60p%80%7F%8F%9F%83%93%A3%81%91%A1%8A%9A%AA%89%99%A9%BD%CD%DD%C2%D2%E2%BF%CF%DF%BE%CE%DE%C8%D8%E8%C6%D6%E6%CE%DE%EE%87%90%99%85%8E%97%84%8D%96%83%8C%95%DC%E5%EE%E7%F0%F9%E4%ED%F6%E2%EB%F4%5Eo%7Fx%89%99%7B%8C%9Cz%8B%9B%7D%8E%9E%7C%8D%9D%7F%90%A0%83%94%A4%82%93%A3%89%9A%AAw%85%92%BD%CE%DE%BC%CD%DD%BB%CC%DC%B8%C9%D9%C3%D4%E4%C1%D2%E2%BF%D0%E0%BE%CF%DF%C8%D9%E9%C7%D8%E8%C6%D7%E7%CC%DD%ED%CA%DB%EB%C7%D7%E6%C4%D4%E3z%84%8D~%88%91%CA%D8%E5%D9%E7%F4%DD%EB%F8%D8%E2%EB%EB%F5%FE%E9%F3%FC%E1%EB%F4%82%89%8F%DE%E5%EB%D1%D8%DE%F2%F9%FF%F1%F8%FE%EF%F6%FC%EC%F3%F9%E9%F0%F6%E5%EC%F2x%86%91t%7D%84%DD%EB%F6%E0%EE%F9%8F%98%9F%DF%E8%EF%D9%E2%E9%EA%F3%FA%E7%F0%F7%E2%EB%F2%E1%EA%F1%DB%E0%E4%D3%D8%DC%F3%F8%FC%F1%F6%FA%F0%F5%F9%EF%F4%F8%EE%F3%F7%EC%F1%F5%EA%EF%F3%E4%E9%ED%F4%F8%FB%E3%E7%EAy%86%8F%7D%8A%93%88%95%9E%DB%E8%F1%E4%F1%FA%DF%EC%F5%F3%FA%FF%FA%FD%FF%7B%89%92z%88%91%7F%8D%96%81%8F%98%C3%D1%DA%E3%F1%FA%E2%F0%F9%DE%EB%F3%E8%F5%FD%E6%F3%FBp%7B%81%7F%8A%90%82%8D%93%87%92%98r%7B%80%87%90%95%DE%E9%EF%EE%F9%FF%EB%F6%FC%E9%F4%FA%E7%F2%F8%E6%F1%F7%DF%E8%ED%DE%E7%EC%EE%F7%FC%EB%F4%F9%EA%F3%F8%E9%F2%F7%E0%E5%E8%DC%E1%E4%7C%8B%92%7F%8C%92~%8B%91%E6%F5%FC%EB%F8%FE%EA%F7%FD%E7%F4%FA%82%8D%91%81%8C%90%DC%E4%E7%F2%FA%FD%EE%F6%F9%E1%E9%EC%F3%FC%FF%F4%F8%F9%EC%F6%F8%F2%FD%FF%F3%FE%FF%F4%FE%FF%F6%FF%FF%F8%FF%FF%F9%FF%FF%FC%FF%FF%FD%FD%FD%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%2C%00%00%00%00%14%00%14%00%00%08%FF%00q%DD%B2U%AB%95%2BB%85%82%FD%D2t%89%D8%B0FS%C8%E4%00%82%E3U.Y%B1%60%F5Z%A4%AC%D8%A7O%CC%96Ar%F4%C8L%90!%3E%08%F1*%A7(Q2O%9C6I%A2%E4%ED%5B%A9T%95%CC%9DA%23%A6%CC%B13%A0%3E937)%12)U%A8LI%7B1%AAS%1A4c%A4%40%A3%82%0E%1D7J%A7B%A5c%95nU%B8%05%D1%9A!%3B%26%0C%CA%AC(%A7D%01%00%D0%C0%04%83%B6%E0%8C%1D3%11%F7%180%16%A3%D2%A5%A3%B5vm%00%01%01%CE%99%1B%17x%B0%B6%162%5C%C0P%D0%B7%AF%BAn%E4%C6%3D%8E%BCME%8C%01%05%1A4n%2C%EEZ%B6%CE%D9%A8%AD%98A%C0%C0%81%CD%9B%9F%3D%C3%E6%ABZ%06%0F%1Dh%20%40%BD%D9%935%5D%D3%20%80%C0%00%E2%03%ED%BE%8Cve%CAd%EB%81%86%0A%1B8%FC%0E%BE%04%13%22D%96%1CL%90%40!%02%EA%04N%0Ee_%C2%9D%8E%08%12%23l%D4th%7C%C1B%08%14L%D0%EB%60%A2%83%C8%89')%9A%08Y%5B%A2%C6%8F%FA%3Fx%E4%DF%C1c%C7%8D%22%83%24!%08%12G%1C%A1%84%11%86%20h%C8%82F%F4%10%06%17X%C4%A1G%1Fy%00%F2%87%1F%80%04%A2%E1%86%1A~%01%86%17X%CCq%87%1Dx%E8Q%C7%1E%7C%EC%A1%E2%8A*n%D1%C5%16Y%A8!%87%1Bm%C0%F1%06%1Ck%B0%A1%E3%8E%3AZq%85%16U%04%04%00%3B";
var up_img = "data:image/gif,GIF89a%15%00%14%00%E6%00%00%F8%F8%F8%F3%F3%F3%E6%E6%E6%EA%EA%EA%E8%E8%E8%F9%F9%F9%E9%E9%E9%F5%F5%F5qqq%DC%DC%DC%9B%9B%9Bvvv%DB%DB%DB%7B%7B%7BZZZlllmmm~~~%B3%B3%B3%B4%B4%B4%C3%C3%C3%9A%9A%9Ahhh%9D%9D%9Ddddrrr%98%98%98%A2%A2%A2%A8%A8%A8%EF%EF%EFaaa%AA%AA%AA%97%97%97%D2%D2%D2%A0%A0%A0%94%94%94%D0%D0%D0%FE%FF%FE%F6%F6%F6%FC%FC%FC%F4%F4%F4%CC%CC%CC%FD%FE%FD%5C%5C%5C%92%92%92%8F%8F%8F%A6%A6%A6%91%91%91%A7%A7%A7%A3%A3%A3%8E%8E%8E%F1%F1%F1%D9%D9%D9%A9%A9%A9MMM%DA%DA%DAEEESSSbbb%D8%D8%D8%5E%5E%5EzzzpppUUUtttgggsss___fffIIIxxx%DD%DD%DDcccPPP%E7%E7%E7%EB%EB%EB%CA%CA%CA%EC%EC%EC%AC%AC%AC%8C%8C%8C%E4%E4%E4%E5%E5%E5%ED%ED%ED%E3%E3%E3%EE%EE%EE%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%00%00%00%00%00%2C%00%00%00%00%15%00%14%00%00%07%FF%80!%13N%84%85%86%87%84%13!%12%24%07U%8F%90%91%92%07%24%12%1F%073T%9A%9B%9C%9A%1D%1DT3%07%1F5U%9D%A7%A7U50URTR%B0%B1%B2%B0%AFRU0.UM%B1M%BD%0C%0B%0C%BD%B0%BBMU.1%25K%BDM%CA%0C%0E8D%09%CC%CA%BD%251%1B*KK%03%DA4%2BE%3F%2B%3EG%DA%E5*%1B%22'%03%06%03%037C6%0E%18A%18%40%09%ED%ED'%22%17%05%06%FE4%1E%92%F0%B0%F0%A0%A0%05%23%09%FC%11(pA%01%00%02%04v%20%C9%A1%03%02%82%8B%17!%F4%60%00%11%80%02%0D%07%94%88%24%60%A2%00%04!%0BR%16Xi%82%80%92%03%1A%40%A0%10%20R%80M%0F%19%1A%E8%2C%40S%09M%14%20F%04%88B4%8A%80(%0E2DX%0A%C0h%D1%00%23X%0C-J%14%0A%80%ABW%A9F%09%C0%E2E%00(S%A0%88%1DK6%EC%D8%00%2FZ%04%98%C2%B6%AD%5B%B6%60(%C5N%09%D0B%86%92%04o%F3%BAM%A0D%86%02%0E%14%98%08%1EL%B80%05%0E%0ARTx%C2%B8%B1%E3%C7%8C%2B%A4%08%04%00%3B";
var down_img = "data:image/gif,GIF89a%15%00%14%00%E6%00%00%F5%F5%F5%F3%F3%F3%E6%E6%E6%E9%E9%E9%E8%E8%E8qqqBBB%DA%DA%DA%9B%9B%9B%EA%EA%EA%F6%F6%F6%8F%8F%8F%DB%DB%DBvvv%EF%EF%EFlllhhhVVVcccRRR%AA%AA%AA%F1%F1%F1%98%98%98%B4%B4%B4%A2%A2%A2%FD%FE%FD%97%97%97%F9%F9%F9%94%94%94%9D%9D%9D%C3%C3%C3%F4%F4%F4%A0%A0%A0%D2%D2%D2%CC%CC%CC%D0%D0%D0%FE%FF%FE%B3%B3%B3%FC%FC%FC%DC%DC%DC%A9%A9%A9GGG%A3%A3%A3%8E%8E%8E%A7%A7%A7aaaiii%A8%A8%A8%92%92%92%A6%A6%A6ddd%91%91%91%9A%9A%9A%F8%F8%F8%FA%FA%FAmmm___%87%87%87%5E%5E%5E%F2%F2%F2OOO%8B%8B%8B%7C%7C%7C%82%82%82%3C%3C%3CJJJooo%40%40%40ZZZzzz~~~%99%99%99%EC%EC%EC%CA%CA%CA%EB%EB%EB%AC%AC%AC%8C%8C%8C%E7%E7%E7%E4%E4%E4%ED%ED%ED%E5%E5%E5%EE%EE%EE%E3%E3%E3%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%00%00%00%00%00%2C%00%00%00%00%15%00%14%00%00%07%FF%80!%17K%84%85%86%87%84%17!%25%23%00S%8F%90%91%92%00%23%25%14%00%15Q%9A%0EQ%9C%9A%9F%9E%15%00%14(S%9F%A7%A8%A8S(%2CSOQO%B1%AF%B2%B4%B2S%2C1SH%B1H%BB%40C%06%C1%BC%BCS1*%24J%BDHJJ%06%3C%11%D06%BD%C9H%24*%18%19%CC%DAJ)D%12%DF6%DBJ%19%18%20%26%09%03%078)A%13-%10%F0-%132%07%09%09%26%20%1D%1B%03%FC%0CB%3A2%5C%3C%18%E8%C2G%02%05%03%08l%E8%80%A0%06%81%87%03%18%14%B9Q%A0b%81%1CJ%10%26%AC%81%C0%02%80%26%20A20R%A0A%83%1EH%14%10%08%09%C0%82%86%0F%02%9A%C4%8Cy%E0G%83%05H%00%AC%0C%F9A%03%87%00P%A0%08%08%1A%F4%C0%91%9CC%85%06%0D%C0%01%06P(N%88%06%15%B0%23%A9%D4%000f%04p%22E%8A%93%AF%60%C3%86%0D0cA%80%AE%5D%B9%A2%F5%CA%16m%80%05%2B%22%9A%9CXK%B7%EE%89%26%2B%10%BC%F0%90%A4%AF%DF%BF%80%3D%BC%40%20%82%06%93%C3%88%13%2B%3ELCD%20%00%3B";
var x_img = "data:image/gif,GIF89a%09%00%09%00%A2%00%00%00%00%00%FF%FF%FF%AD%BD%D6%EA%EE%F4%FF%FF%FF%00%00%00%00%00%00%00%00%00!%F9%04%01%00%00%04%00%2C%00%00%00%00%09%00%09%00%00%03%168B%CC%A2b%B9H%E2%B2%CD%D2Vw%D6%DFEa%D3%23eC%02%00%3B";
var guided_setup_action = null;
var clean_prefs = function() { }

var storyTypes = {
 '12,38,94,178': 'Event stories',
 '366,289': 'Facebook Deals',
 '316': 'Friends being added to Groups',
 '116,278,285': 'Friends checking in (location)',
 '7': 'Friends commenting on photos',
 '21': 'Friends joining groups',
 '313,360':'Friends "playing games"',
 '68': 'Friends tagged in notes',
 '65': 'Friends tagged in pictures',
 '130': 'Friends tagged in videos',
 '245': 'Friends "Liking" posts',
 '257': 'Friends commenting on non-friend content',
 '161': 'Page "Likes"',
 '283': 'External (site/link) "Likes"',
 '5,80,263': 'Links',
 '8': 'New friend notifications',
 '66': 'Notes',
 '247,6': 'Photos',
 '237': 'Posts by any application',
 '55': 'Posts to event walls',
 '308': 'Posts to groups',
 '164': 'Posts to Pages',
 '282,305': 'Profile Information change', // 305 = job change
 '15,60,259': 'Profile Picture changes',
 '280': 'Questions Asked',
 '338,281':'Questions Answered',
 '286':'Questions Followed',
 '10,62,9,3': 'Relationship changes', // 9=A married to B, 3=friend A married to non-friend B?
 '46,11': 'Status updates',
 '128': 'Status updates by Pages',
 '400,447':'Subscription notications',
 '77': 'Tagged posts',
 '17': 'Videos',
 '56,273': 'Wall-to-Wall posts',
 '100':'Wall posts to your wall'
};
var story_types = {};
for (var st in storyTypes) {
	var types = st.split(",");
	for (var i=0; i<types.length; i++) {
		story_types[types[i]] = storyTypes[st];
	}
}
var apps = {
    "106548749379931":"21 questions",
    "14465560457":"6 waves Gaming Network",
    "145712665484714":"60photos",
    "56078883483":"6waves Poker",
    "2998790650":"Addicting Games",
    "114440918573776":"Age of Champions",
    "223102214157":"Ameba Pico",
    "99953444729":"Animal Paradise",
    "136850942021":"Anita predictions",
    "50342477628":"Anket",
    "20851133681":"Appbank",
    "17091798008":"Are YOU Interested",
    "174582889219848":"Army Attack",
    "113556445341048":"Astrology",
    "3008250443":"Astrology",
    "191342050909554":"BACARDI Together",
    "342684208824":"Backyard Monsters",
    "107433747809":"Badoo",
    "215779025017":"Baking Life",
    "338051018849":"Baking Life",
    "2405167945":"My Band",
    "181798818501421":"BandooChat",
    "178091127385":"BandPage by RootMusic",
    "182222305144028":"BandRx",
    "123966167614127":"Bandsintown",
    "60884004973":"Barn Buddy",
    "148669555176974":"Battle Pirates",
    "181238248175":"Battle Punks",
    "133306231504":"Be Naughty",
    "113698985309095":"Become the Avatar",
    "40343401983":"Bejeweled Blitz",
    "131401703561418":"Between You and Me",
    "249071419053":"Big City Life",
    "107047069978":"Bing Bar",
    "111239619098":"Bing",
    "108854979142742":"BINGO Blitz",
    "27178406486":"Biotronic",
    "425755285303":"Birdland",
    "5437153164":"Birthday Calendar",
    "14852940614":"Birthday Cards",
    "100044563957":"Bite Me",
    "3447538274":"Blingee Book",
    "133860221774":"Bola",
    "139701732734451":"Bold Text",
    "8519508606":"Bowling Buddies",
    "144030170500":"Brain Buddies",
    "131479520210618":"BranchOut",
    "124194560873":"Bubble Island",
    "114224881951277":"Bubble Paradise",
    "115086491859102":"Bubble Popp 2",
    "167633464091":"Bubble Popp",
    "148430031885488":"Bubble Saga",
    "6705455684":"BuddyPoke",
    "22257989976":"Bumper Sticker",
    "2427603417":"Bumper Sticker",
    "347486061825":"Cafe Life",
    "101539264719":"Cafe World",
    "256799621935":"Car Town",
    "116823891666136":"Casino City",
    "46755028429":"Castle Age",
    "100160675317":"Castle And Co",
    "2318966938":"Causes",
    "162065369655":"Chase Community Giving",
    "8278986302":"Circle of Moms",
    "291549705119":"CityVille",
    "100626246643948":"Clobby Group Chat",
    "75510507417":"COLLAPSE",
    "10291197539":"Collect Hearts",
    "62691070599":"Collect Roses",
    "2433486906":"Compare People",
    "338535090337":"Concerts",
    "5179614317":"Concerts",
    "209845035304":"Conduit",
    "95936962634":"Contests",
    "26947445683":"Country Life",
    "165747315075":"Country Story",
    "82716374139":"Country Story",
    "168640034863":"Crazy Cow Music Quiz",
    "48596151436":"Crazy Planets",
    "165375796970":"Create your Quiz",
    "129547877091100":"Crime City",
    "141437422542260":"CSI Crime City",
    "277669328975":"Cupid",
    "20290140409":"Daily Horoscope",
    "2432011670":"Daily Horoscope",
    "250617178518":"Daily Horoscope",
    "9322309221":"Daily Tarot Cards",
    "125717634120849":"Death Time Calculator",
    "78222424325":"Decorative Writing",
    "271369798991":"Demande  tes Amis",
    "127995567256931":"Diamond Dash",
    "53714299244":"Do you really know me",
    "2388926799":"Dogbook",
    "9729051194":"Doorbell",
    "119468838217":"DoubleDown Casino",
    "111896392174831":"Dragons of Atlantis",
    "149777331718970":"Draw My Thing",
    "75127329583":"Drink it up",
    "298341310193":"Drinks for All",
    "247431880944":"DROID",
    "113719625324737":"EA SPORTS FIFA Superstars",
    "122580857763901":"eBuddy",
    "102965689949":"Element Analyst Creator",
    "164285363593426":"Empires And Allies",
    "217680310882":"Entrevista tus Amigos",
    "372268249833":"Evony",
    "127760087237610":"Facebook Platform Opt In",
    "117955111903":"Family Feud",
    "2359239297":"Family Tree",
    "5388815661":"Were Related",
    "108468622525037":"FanBridge Fan Page Creator",
    "64571521476":"FARKLE",
    "56748925791":"Farm Town",
    "156383461049284":"FarmVille",
    "102452128776":"FarmVille",
    "131704200228509":"Fashion Designer",
    "315888392043":"Fashion World",
    "181988617439":"Ferme Pays",
    "257873289864":"Fish Friends",
    "154109904146":"Fish Isle",
    "100354007223":"Fish World",
    "151044809337":"FishVille",
    "133911659959418":"Flag Balls World Cup 2010",
    "2372251387":"Flock Browser",
    "11908058186":"Forever Friends",
    "216274310341":"Formspring",
    "174998653270":"Fortune Cookie",
    "136970699676856":"Foto Memria",
    "86734274142":"Foursquare",
    "413123837941":"Frases de la vieja de Mierd",
    "102153277223":"Frases Diarias",
    "155624737799898":"freequizzes",
    "2610371153":"Friend Block",
    "5655417519":"Friend Hug",
    "326914550570":"Friend Interview",
    "148818305184742":"Friend Matrix",
    "146563558702544":"Friendly for iPad",
    "389195615844":"Friends Emotions",
    "7019261521":"Friends For Sale",
    "231667526876431":"Friends Photos",
    "83275034265":"Friends Quizzes",
    "201278444497":"FrontierVille",
    "153292069231":"Frosmo",
    "314590221259":"Funfari",
    "212391322553":"Funflow",
    "94168997876":"Galletas de la fortuna",
    "62181482841":"Games",
    "79389216309":"Gangster City",
    "38278202455":"Garden Life",
    "175251882520655":"Gardens of Time",
    "23438505508":"Geo Challenge",
    "124318160942877":"Get Revealed",
    "8089123087":"Gift Creator",
    "225760977045":"GirlsDateForFree",
    "65496494327":"Give Hearts",
    "96815041925":"Glamble Poker",
    "127422718290":"Glcksnu",
    "157643297597296":"Global Warfare",
    "191593014043":"Gnlk Falnz The Fortune Teller",
    "175038902544578":"GnomeTown",
    "54375760911":"God wants You to Know",
    "201978810060":"GooBox Jeux Gratuits",
    "279343665079":"Goobox Juegos gratis",
    "72396514444":"Good and Evil",
    "360375426140":"Gourmet Ranch",
    "2439131959":"Graffiti",
    "207717314188":"Granja Pas",
    "8331309681":"Hallmark Social Calendar",
    "134920244184":"Happy Aquarium",
    "106265797465":"Happy Farm",
    "57132175859":"Happy Farm",
    "140357045994487":"Happy Hospital",
    "31231052697":"Happy Island",
    "127148832824":"Happy Pets",
    "7176719309":"Hatchlings",
    "2462728553":"Hearts",
    "105484376153111":"Hello City",
    "175984199091917":"Hero City",
    "58259641862":"Hero World",
    "123725371037047":"HOGELDNZ",
    "2552096927":"Honesty Box",
    "125043264175761":"HootSuite",
    "183319479511":"HootSuite",
    "2339854854":"Horoscopes",
    "333713683461":"Horoscopes",
    "129653133741884":"Horscopo Dirio",
    "315878856166":"Horse Saga renamed",
    "190435500990432":"Hosted iFrame",
    "299672925361":"Hotel City",
    "7242238915":"HotShot",
    "81708710756":"How Well Do You Know Me",
    "41158896424":"HTC Sense",
    "2345673396":"Hug Me",
    "4673352481":"Hugged",
    "80541436066":"Hugs",
    "6917629807":"iCast",
    "56456021122":"Icy Tower",
    "3105775330":"iHearts",
    "6627984866":"iLike this Artist",
    "124024574287414":"Instagram",
    "10754253724":"iPhoto Uploader",
    "17604663455":"IQ test",
    "25148877350":"Is Cool",
    "94483022361":"Island Paradise",
    "6307004335":"iSmile",
    "119866041395334":"It Girl",
    "400560945032":"Jeux Flash Gratuits",
    "368596809331":"Jewell Stars",
    "8725050364":"JibJab",
    "329338272587":"Jumping Dog",
    "119607768061558":"Jungle Jewels",
    "87409181318":"Jungle Jewels",
    "307957522611":"Jungle Life",
    "385041300032":"Kingcom",
    "130402594779":"Kingdoms of Camelot",
    "10585847530":"Kisses",
    "127979500596129":"Komu iftlik",
    "92922535871":"La Meteo del Humor",
    "48268916695":"La meteo du moral",
    "92264180565":"LArc en Ciel du Moral",
    "53702860994":"LG Phone",
    "2405948328":"Likeness",
    "99663102846":"Lil Farm Life",
    "48187595837":"LivingSocial",
    "233260194406":"Lounge Bar",
    "207737238125":"Love Percentage Daily",
    "353489950377":"Lovely Farm",
    "35512920026":"Ma Fiche",
    "10979261223":"Mafia Wars",
    "20030663368":"Magic Land",
    "112549508829442":"Mahjong Saga",
    "108589655859196":"Mahjong Trails",
    "106451196053938":"Mahjong",
    "48912475783":"Mahjong",
    "232279070608":"Mahjongg Dimensions",
    "217638774392":"Mall World",
    "191616050877248":"MapleStory Adventures",
    "128581025231":"Marketplace",
    "114750555226259":"Maya Pyramid",
    "199931046702512":"Megacity",
    "37185134036":"MeinKalender",
    "38075929120":"Metropolis",
    "202577393268":"MiCalendario",
    "315455798286":"Millionaire City",
    "5706713477":"MindJolt Games",
    "115705755156917":"Miner Speed",
    "179372416900":"Mis buenos amigos",
    "162857367075":"Mis Fotos",
    "148768088503846":"Miscrits World of Adventure",
    "2384884864":"MixPod Music Playlist",
    "184736811530":"MMA Pro Fighter",
    "8743457343":"Mob Wars",
    "112462268161":"Mobsters 2 Vendetta",
    "62963747512":"MonCalendrier",
    "157470434271574":"Monopoly Millionaires",
    "129748227041755":"Monster Galaxy",
    "175763303727":"Monster World",
    "318024301141":"MonstrosCity",
    "14405921260":"MOTOBLUR",
    "2558160538":"Movies",
    "132970837947":"MSN",
    "57220127280":"Music Challenge",
    "2413267546":"Music",
    "2436915755":"Music",
    "58267769762":"My Arabic Name",
    "17236267818":"My Best Girls",
    "296408696694":"My Casino",
    "226424314329":"My City Life",
    "111884338842047":"My Empire",
    "6224046065":"My Family",
    "125363437505916":"My Friend Secrets",
    "152645868106521":"My Kingdom",
    "104326862942942":"My Mood",
    "2490151219":"My Personality",
    "123837014322698":"My Shops",
    "2352149512":"My Stuff",
    "14167664298":"My Tab",
    "151646922090":"My Top Fans",
    "213797292305":"My Town",
    "102680597135":"My Tribe",
    "301568376907":"My Vineyard",
    "33699672217":"MyCalendar",
    "106932686001126":"Mynet anak Okey",
    "162843607082809":"MyPad for iPad",
    "173803199324041":"Mystery Manor",
    "166974299986250":"Mystic Meg",
    "109674171476":"myYearbook",
    "155663022639":"Name Analyzer",
    "213568186669":"NanoStar Siege",
    "9953271133":"NetworkedBlogs",
    "105150252854220":"Nightclub City",
    "102796083108857":"Nimbuzz Mobile",
    "137827210650":"Ninja Saga",
    "147198662055":"Ninja Warz",
    "49340319393":"Nokia social app",
    "27694818115":"Nokia",
    "56137638329":"Nokia",
    "181699118532591":"NS_EN Play Now Tab",
    "177484378970788":"Oferece uma rosa",
    "9313288246":"Okey",
    "46194160792":"OndaPix",
    "152629207127":"Onedate",
    "7326494972":"Online People",
    "152125811490446":"Pages ",
    "139475280761":"Pandora",
    "120495504667538":"People Roulette",
    "349982333921":"Pet Forest Online",
    "11609831134":"Pet Society",
    "43339618829":"Petites questions entre amis",
    "163576248142":"PetVille",
    "38997159460":"Photobucket",
    "164366686937186":"PhotoMania",
    "96991919724":"phrases 4 fun",
    "34469440080":"Phrases Box daily",
    "139706616078480":"Phrases new",
    "346127299384":"Phrases _ F r a z i",
    "350031875244":"Phrases",
    "134506053246185":"PicBadges",
    "15079221211":"Pick who",
    "2258014869":"Picnik",
    "3396043540":"Pieces of Flair",
    "7068221435":"Pillow Fight",
    "266989143414":"Pioneer Trail",
    "176047503611":"piZap Photo Editor",
    "158391354186658":"piZapcom",
    "124652482372":"Platinum Life Web Edition BETA",
    "100577877361":"PlayStationNetwork",
    "89515727790":"Plock",
    "47804741521":"Plurk",
    "188875041752":"Poker Blitz",
    "9727320655":"Poker Palace",
    "101045923317506":"Poker Play Now",
    "125307794210678":"Poker Play Now",
    "150335135013694":"Poker Texas Boyaa",
    "20678178440":"Poll",
    "55182998957":"Pool Live Tour",
    "222965351112":"Pool Master 2",
    "494509405050":"Pool Master",
    "142518545776470":"Preguntas y Respuestas",
    "356104976566":"Premier Football",
    "5644329558":"Premier Football",
    "117320678334654":"Profile Banner",
    "188551474501934":"Profile Labeler",
    "18489293024":"Profile Song",
    "367415665181":"Puzzle Saga",
    "115301331874715":"PyramidVille",
    "102925723121370":"Qui regarde le plus votre profil ",
    "6016992457":"Quiz Creator",
    "7635383700":"Quiz Monster",
    "8525382561":"Quiz Planet",
    "20403127296":"Quizazz",
    "6071052793":"QuizBone",
    "2341007765":"Quizzes",
    "112682186530":"Quotes Creator",
    "120563477996213":"Ravenwood Fair",
    "397668330151":"Resort World",
    "43016202276":"Restaurant City",
    "176611639027113":"RewardVille",
    "46185617224":"RockFREE",
    "2601240224":"RockYou Live",
    "89771452035":"Roller Coaster Kingdom",
    "326803741017":"Rotten Tomatoes",
    "45439413586":"RSS Graffiti",
    "72687635881":"Samsung Mobile",
    "208891395787993":"Sayfa nerme",
    "20737309912":"Scavenger Hunt",
    "4014809927":"School of Wizardry",
    "14916117452":"SCRABBLE",
    "7730584433":"SCRABBLE",
    "6494671374":"Scramble",
    "136494494209":"Scribd",
    "126065837432395":"Seni Kimler Takip Ediyor",
    "179234248795565":"Shadow Fight",
    "6459818531":"Show Some Love",
    "4260387428":"Sketch Me",
    "260273468396":"Skype",
    "171306882348":"SkypeWorks",
    "2378983609":"Slide FunSpace",
    "169545139744270":"Slotomania Slot Machines",
    "186995688782":"Smiles",
    "20407635301":"Snaptu",
    "163965423072":"Social City",
    "100495476683973":"Social Empires",
    "163098990943":"Social Interview",
    "185050880967":"Social Pang",
    "23798139265":"Social RSS",
    "130972710269090":"Social Statistics",
    "221476177866279":"Socialbox",
    "19935916616":"Songs",
    "8630423715":"Sorority Life",
    "19507961798":"SoundCloud",
    "174829003346":"Spotify",
    "169868688162":"SPP Ranch",
    "241219935874":"sProphet  Sports Predictions",
    "338375791266":"Starbucks Card",
    "8109791468":"Status Shuffle",
    "123338877715314":"Stick Run",
    "267470608481":"StumbleUpon",
    "57001576911":"Sunshine Ranch",
    "369817626957":"Super Crayon",
    "130782229473":"Super Dance",
    "145535448838453":"Super Mario Classic",
    "260692711926":"SuperFun Town",
    "29591742977":"SuperPoke Pets",
    "2357179312":"SuperPoke",
    "160221913381":"Superstar City",
    "28134323652":"Sweepstakes",
    "113430382004230":"Sweet World",
    "176217385757369":"TabPress Custom iFrame Tabs",
    "38656534621":"Tarjetitas",
    "18120686907":"Tattoodle",
    "2227470867":"Test Console",
    "130409810307796":"Tetris Battle",
    "2376198867":"Tetris Friends",
    "2389801228":"Texas HoldEm Poker",
    "113315295379073":"The Hardest Game of the World",
    "44898431470":"The Mood Weather Report",
    "121943604485916":"The Pokerist club  Texas Poker",
    "144959615576466":"The Sims Social",
    "130095157064351":"The Smurfs amp Co",
    "334201605612":"Tiki Farm",
    "255168890258":"Tiki Resort",
    "140802830263":"Tinychat  Video Chat",
    "162683987103384":"Toolbar Widget",
    "109306535771":"Top Eleven  Be a Football Manager",
    "153678824653183":"Top Fifty Photos of Friends",
    "2425101550":"Top Friends",
    "161347997227885":"TopFace",
    "161695830562593":"Total Domination Nuclear Strategy",
    "187984023512":"Towner",
    "119226218098665":"TrainCity",
    "234860566661":"Treasure Isle",
    "158243717529":"Treasure Madness",
    "29518083188":"Treasure Madness",
    "104656394022":"Trebol de la Suerte",
    "370852557681":"Treetopia",
    "113561858666012":"Trial Madness",
    "2219089314":"TripAdvisor  Cities Ive Visited",
    "162729813767876":"TripAdvisor",
    "56849177140":"Trivias Locas  Trivias encuestas y tests",
    "133451120007663":"Truth Game",
    "137767829572142":"Truths About You",
    "48119224995":"Tumblr",
    "53267368995":"Tweets To Pages",
    "2231777543":"Twitter",
    "33181781021":"UNO",
    "25287267406":"Vampire Wars",
    "122787657740607":"vChatter",
    "10150138245120151":"Verdonia",
    "157391050947062":"VEVO for Artists",
    "122274804478146":"Video Alemi",
    "153698564676380":"Video Yeri",
    "2481647302":"Visual Bookshelf",
    "7616635055":"Wedding Buzz formerly Weddingbook",
    "2603626322":"Where Ive Been",
    "8827826004":"Who Has The Biggest Brain",
    "134867833190649":"WhoIsNear",
    "101628414658":"Wild Ones",
    "201143516562748":"Wildfires iFrames for Pages",
    "30713015083":"Windows Live Messenger",
    "129982580378550":"WixYourPage",
    "10726707410":"Word Challenge",
    "163789865790":"Word Challenge",
    "168378113211268":"Words With Friends",
    "230265160294":"World at War",
    "130832813611477":"World Cup 2010 Jersey",
    "5747726667":"Xbox LIVE",
    "90376669494":"Yahoo",
    "5243732877":"Yearbook",
    "97534753161":"Yelp",
    "82038911142":"Your Japanese Name",
    "160292238168":"Your Luck daily",
    "290797550542":"Yourapps",
    "2513891999":"YouTube Box",
    "57675755167":"YouTube for Pages",
    "3801015922":"YouTube Video Box",
    "87741124305":"YouTube",
    "21526880407":"YoVille",
    "169557846404284":"Zombie Lane",
    "292329111180":"Zoo Kingdom",
    "339444600959":"Zoo Paradise",
    "167746316127":"Zoo World",
    "6953377468":"Zoosk",
    "113155018698187":"Zuma Blitz",
    "177554951839":"Zynga Game Bar"
};

// ==================================================================
// "GLOBAL" VARIABLES
// ==================================================================
var nofbidcount = 0;
var storyCount = 0;
var count_processed = 0;
var count_hidden = 0;
var count_filtered = 0;
var count_tabbed = 0;
var count_reordered = 0;
var count_expanded = 0;
var count_duplicate = 0;
var olderPostsClickCount=0;
var current_time=new Date();
var current_year = current_time.getFullYear();
var access_token = null;
var post_array = {};
var post_hash = {};
var post_counter = 0;
var findAndClickOlderPosts = function(){};
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var weeks = days * 7;

// ==================================================================
// First order of business - find out who we are!
// ==================================================================
var userid = "anonymous";
var m,a = QS(document,'#navAccountPic,.headerTinymanName');
if (a && a.href && /profile/i.test(a.href)) {
	var href = a.href;
	if (m = href.match(/id=(\d+)\b/)) { userid = m[1]; }
	else if (m = href.match(/\/([a-z0-9\.]+)\?ref=profile/)) { userid = m[1]; }
}
else if (a && a.href) {
	if (m=a.href.match(/facebook\.[^\/]+\/(.*)/)) {
		userid = m[1];
	}
}
if (userid=="anonymous") { return; }

// ==================================================================
// GRAPH API
// ==================================================================
var graph_token_refreshed = false;
var graph_token_pref = userid+'/access_token';
function set_graph_token(token) {
	access_token = token;
	setValue(graph_token_pref,token);
}
function get_graph_token(func) {
	if (access_token==null) {
		getValue(graph_token_pref,null,function(token) {
			if (token!=null) {
				set_graph_token(token);
				func(token);
			}
			else {
				refresh_graph_token(func);
			}
		});
	}
	else {
		func(access_token);
	}
}
function refresh_graph_token(func) {
	ajax({'method':'GET',headers:{'Cache-Control':'no-cache'},'url':'https://developers.facebook.com/docs/reference/api','onload':function(res) {
		var token = null;
		var src = res.responseText;
		var m = src.match(/https:\/\/graph\.facebook\.com\/me\/friends\?access_token=([^"]+)/);
		if (m && m.length>1) { token = m[1]; }
		if (token) {
			set_graph_token(token);
			graph_token_refreshed = true;
			return func(token);
		}
		showerror("Error retrieving Token");
		return func(null);
	}});
}
function graph(url,func) {
	var make_request= function(token){
		if (!token) { return; }
		ajax({'method':'GET',headers:{'Cache-Control':'no-cache'},'url':'https://graph.facebook.com/'+url+'?access_token='+token,'onload':function(res) {
			try {
				var response = JSON.parse(res.responseText);
				if (response && !response.error) {
					return func(response);
				}
				else if (response && response.error) {
					if (!graph_token_refreshed) {
						refresh_graph_token(make_request);
					}
					else {
						showerror("Graph API Error for ["+url+"]:\n"+response.error.message);
					}
				}
			} catch(e) { showexception(e); }
		}});
	};
	get_graph_token(make_request);

}

// ==================================================================
// "Reusable" Options interface
// ==================================================================
function GM_options(key,userid) {
	try {
		this.optionsDiv = null;
		this.options = [];
		this.optionsObj = {};
		this.tabs = [];
		this.currentTab = null;
		this.key = key;
		this.userid = userid || "anonymous";
		this.loaded = false;
		this.prefs = {};
		var self = this;
		
		this.load = function(callback) {
			if (PERFORMANCE) { trace_start('options.load',null,true); }
			var self = this;
			getValue(this.userid+'/prefs',null,function(storedPrefs) {
				trace_start('options.load.getValue callback',null,true);
				if (storedPrefs && storedPrefs!=null && storedPrefs!='' && storedPrefs!="null") {
					try {
						self.prefs = JSON.parse(storedPrefs);
						self.loaded = true;
					}
					catch (e) {
						self.prefs = {};
						showerror("Your stored preferences could not be read because they have become corrupt. Sorry, but your options been reset! This shouldn't happen again! The error was:",e.toString());
						setValue(self.userid+"/prefs","");
					}
				}
				if (typeof callback=="function") { 
					callback(self); 
				}
				trace_end('options.load.getValue callback',null,true);
			});
			if (PERFORMANCE) { trace_end('options.load',null,true); }
		}
		
		this.get = function(name) {
			var parts = name.split(".");
			var prop = parts[parts.length-1];
			var o = this.prefs;
			var option = this.optionsObj[name];
			var def = option?option['default']:undef;
			for (var i=0; i<parts.length-1; i++) {
				var part = parts[i];
				if (typeof o[part]=="undefined") {
					return def; 
				}
				o = o[part];
			}
			if (typeof o[prop]!="undefined") {
				return o[prop];
			}
			return def;
		}
		
		this.set = function(name,val,savenow,func) {
			if (PERFORMANCE) { trace_start('options.set',null,true); }
			var self = this;
			var do_save = function() {
				if (PERFORMANCE) { trace_start('this.set.do_save',null,true); }
				var parts = name.split(".");
				var prop = parts[parts.length-1];
				var o = self.prefs;
				for (var i=0; i<parts.length-1; i++) {
					var part = parts[i];
					if (typeof o[part]=="undefined") {
						o[part] = {};
					}
					o = o[part];
				}
				if (typeof savenow=="undefined" || savenow) {
					o[prop]=val;
					self.save(func);
				}
				else {
					o[prop] = val;
				}
				if (PERFORMANCE) { trace_end('this.set.do_save',null,true); }
				return val;
			}
			if (typeof savenow=="undefined" || savenow) {
				self.load(function() {
					do_save();
				});
			}
			else {
				do_save();
			}
			if (PERFORMANCE) { trace_end('options.set',null,true); }
		}
		
		this.multiset = function(values,savenow,func) {
			var self = this;
			this.load(function() {
				for (var k in values) {
					self.set(k,values[k],false);
				}
				if (savenow) {
					self.save(func);
				}
			});
		}

		this.save = function(func) {
			if (PERFORMANCE) { trace_start('options.save',null,true); }
			var json = JSON.stringify(this.prefs);
			setValue(this.userid+"/prefs",json,func);
			if (PERFORMANCE) { trace_end('options.save',null,true); }
		};
		this.save.name="options.save";
		
		this.addSectionHeader = function(title) {this.addHtml("<h2>"+title+"</h2>");};
		this.addOption = function(name,type,def,opt,style) {opt = opt || {};opt.name = name;opt.type = type;opt['default'] = def;opt.style=style;this.options.push( opt );this.optionsObj[opt.name] = opt;};
		this.addHtml = function(html) {this.options.push( {'type':'html', 'value':html } );};
		this.addFunction = function(func) {this.options.push( {'type':'function', 'value':func } );}
		this.renderOption = function(opt) {
			opt.value = this.get(opt.name);
			opt.onchange = opt.onchange || "";
			var input = '';
			// CHECKBOX Option
			if (opt.type=="checkbox") {
				opt.checked = (opt.value?"checked":"");
				input = _template('<input type="checkbox" name="%name%" onclick="%onchange%" %checked% style="%style%">', opt);
			}
			// TEXTAREA option
			else if (opt.type=='textarea') {
				input = _template('<textarea name="%name%" nowrap class="textarea" style="width:90%;" onchange="%onchange%" rows="%rows%" cols="%cols%" style="%style%">%value%</textarea>', opt);
			}
			// INPUT option
			else {
				input = _template('<input name="%name%" class="text" onfocus="this.select()" onchange="%onchange%" value="%value%" size="%size%" style="%style%">', opt);
			}
			return input;
		};
		this.render = function(tab_id) {
			var self = this;
			var alt = 0;
			var content = ((<><![CDATA[
				<div class="bfb_tabs" id="bfb_tabs">
					<div class="bfb_tab" id="bfb_t_popular">Popular</div>
					<div class="bfb_tab" id="bfb_t_layout">Layout</div>
					<div class="bfb_tab" id="bfb_t_posts">Posts</div>
					<div class="bfb_tab" id="bfb_t_display">Display</div>
					<div class="bfb_tab" id="bfb_t_hidden">Hidden</div>
					<div class="bfb_tab" id="bfb_t_chat">Chat</div>
					<div class="bfb_tab" id="bfb_t_theme">Theme</div>
					<div class="bfb_tab" id="bfb_t_filter">Filtering</div>
					<div class="bfb_tab bfb_option_advanced" id="bfb_t_advanced">Advanced</div>
					<div class="bfb_tab bfb_option_advanced" id="bfb_t_css">CSS</div>
					<div class="bfb_tab bfb_option_advanced" id="bfb_t_debug">Debug</div>
					<div class="bfb_tab" id="bfb_t_prefs">User Prefs</div>
					<div class="bfb_tab" id="bfb_t_about">About</div>
				</div>
				<div id="bfb_options_body">
					<div class="bfb_option_body" id="bfb_t_popular_body" style="display:block;vertical-align:bottom;">
						<div class="no_hover">
							<div class="bfb_featured_option">
								<help>When you move your mouse over thumbnail images, Better Facebook will show the full-sized image in a popup, so you don't have to click on the picture to see the whole thing.</help>
								<img src="https://s3.amazonaws.com/BFB/options/image_hover.gif">
								<div class="desc">
									%show_image_previews% Show full images when hovering over thumbnails
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>In February 2011, Facebook introduced a new "Light Box" photo viewer with a black background when you click on photos. If you don't like this new photo viewer, check this option to disable it.</help>
								<img src="https://s3.amazonaws.com/BFB/options/lightbox.gif">
								<div class="desc">
									%disable_theater_view% Disable the "Lightbox" (aka "Theater") photo viewer
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>If you (or your friends) play Facebook games or often use Facebook applications, Better Facebook can automatically move those posts to their own tab, so they don't interrupt the flow of the rest of your feed.</help>
								<img src="https://s3.amazonaws.com/BFB/options/app.gif">
								<div class="desc">
									%tab_all_apps% Automatically move posts from Apps into their own tabs
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>Facebook changed their default font size from 13px to 12px in 2010. Many users find the new font size to be too small. You can use this option to set any font size you wish.
									<br><br>
									To restore sizes to the old settings, enter a value of 13.
								</help>
								<img src="https://s3.amazonaws.com/BFB/options/fontsize.gif">
								<div class="desc">
									%enable_font_size% Change font size to %post_font_size%px for posts and %comment_font_size%px for comments
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>When you post comments on friends' status, like pages, or take other actions on Facebook, one-line "Recent Activity" posts will appear in your profile and let others know what you are up to. Enable this option to automatically remove these posts every time you visit your profile.<br><br>In the Display tab, you can select exactly which types of stories to delete, while preserving others.</help>
								<img src="https://s3.amazonaws.com/BFB/options/recent_activity.gif">
								<div class="desc">
									%auto_remove_recent_activity% Auto-remove Recent Activity posts from my profile
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>By default, when entering comments, clicking Enter will submit the comment. Enable this option to restore the old functionality, where Enter = New Line, and a Comment button exists to post the message.</help>
								<img src="https://s3.amazonaws.com/BFB/options/comments.gif">
								<div class="desc">
									%fix_comments% Fix "Enter" key behavior to be a newline when adding comments
									<br style="clear:both;">
								</div>
							</div>

							<div class="bfb_featured_option">
								<help>Facebook groups "Top Stories" into a section at the top of the page. This option gets you back to a purely chronological feed, and removed the section headers like "Top Stories" or "Earlier Today", etc.</help>
								<img src="https://s3.amazonaws.com/BFB/options/most_recent.gif">
								<div class="desc">
									%chronological% Force the news feed to be chronological and hide "Top Stories"
									<br style="clear:both;">
								</div>
							</div>

							<br style="clear:both;">

							<div class="bfb_featured_option">
								<help>When enabled, a "reply" link will appear in each post comment next to Like. When clicked, you will easily be able to reply to a specific comment, tag the person you are replying to, and even quote part of their message.</help>
								<img src="https://s3.amazonaws.com/BFB/options/reply.gif">
								<div class="desc">
									%comment_reply% Add "Reply" links to comments and %comment_reply_float_textarea% float the reply box up to the comment
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help></help>
								<img src="https://s3.amazonaws.com/BFB/options/staticheader.gif">
								<div class="desc">
									%static_header% <b>Lock</b> the header bar at the top so it scrolls</th>
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>By default, Facebook shows you 15 posts. In the footer of the page is a link to "Older Posts" which retrieves more posts. Better Facebok can auto-click this link any number of times to retrieve more posts, so you won't miss anything.</help>
								<img src="https://s3.amazonaws.com/BFB/options/older_posts.gif">
								<div class="desc">
									%auto_click_older_posts% Auto-click "Older Posts" %auto_click_more_times% times to get more posts
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>
									When friends or pages post multiple posts in a small amount of time, Facebook will show just the first one, with a link to "show similar posts".<br>
									This option automatically clicks to expand these groupings of posts wherever they occur.
								</help>
								<img src="https://s3.amazonaws.com/BFB/options/expand.gif">
								<div class="desc">
									%expand_similar_posts% Automatically expand "SHOW X SIMILAR POSTS" links
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>Friends change their profile pictures often, and it can be difficult to tell who is who.<br><br>Select this option to revert to names instead of pictures.</help>
								<img src="https://s3.amazonaws.com/BFB/options/chat.gif">
								<div class="desc">
									%chat_images_to_names% Change profile images in Chat to names
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>When someone unfriends you, the Friend Tracker panel in the right column will alert you!</help>
								<img src="https://s3.amazonaws.com/BFB/options/unfriend.gif">
								<div class="desc">
									%show_friend_tracker% Show "Friend Tracker" to get Unfriend notifications
									<br style="clear:both;">
								</div>
							</div>
							<div class="bfb_featured_option">
								<help>Turn this option on to DISABLE all Better Facebook's features temporarily. In place of the "Options" link in the header will be an "Enable BFB" link that will restore normal operation (and access to these options)<br><br>After saving Options, the page must be refreshed for this to take effect.</help>
								<img src="https://s3.amazonaws.com/BFB/options/power.gif">
								<div class="desc">
									%disabled% POWER OFF - Disable all Better Facebook functionality (requires refresh)
									<br style="clear:both;">
								</div>
							</div>
						<br style="clear:both;">
						</div>
						%disabled_on_apps% Prevent BFB from running when playing games on apps.facebook.com<br>
						<div style="font-weight:bold;color:#880000;">Run the <a id="bfb_guided_setup" style="text-decoration:underline;" href="#" onclick="return false;">Guided Setup Wizard</a> to familiarize yourself with popular features!</div>
					</div>
					
					<div class="bfb_option_body" id="bfb_t_layout_body" style="vertical-align:bottom;">
						<table border="0">
							<tr>
								<th colspan="3" style="background-color:#3B5998;color:white;">%static_header% Lock the blue header bar so it scrolls with the page</th>
							</tr>
							<tr style="background-color:#3B5998;color:white;">
								<th style="width:200px;border:1px solid #ccc;text-align:center;">Left Column</th>
								<th style="width:300px;border:1px solid #ccc;text-align:center;">Content Area</th>
								<th style="width:250px;border:1px solid #ccc;text-align:center;">Right Column</th>
							</tr>
							<tr>
								<td style="width:200px;border:1px solid #ccc;vertical-align:top;background-color:white;">
									<div>
										<help>This makes the left column stay static on the screen so it doesn't scroll along with the page, giving you easy access to menu items</help>
										%static_left_col% Lock the left column in place
									</div>
									<div>
										<help>These links are added to the top left navigation area, under "News Feed", "Messages", etc</help>
										<b>Add Useful Links</b>:
										<div class="bfb_sub_option " style="font-family:lucida grande,tahoma,verdana,arial,sans-serif;font-size:11px;">
											%show_nav_all_connections% All Connections<br>
											%show_nav_edit_friends% Edit Friends <br>
											%show_nav_write_a_note% Write A Note <br>
											%show_nav_pages_i_admin% Pages I Admin <br>
											%show_nav_unblock_applications% Unblock Applications<br>
										</div>
									</div>
									<div>
										<b>Hide</b>:
										<div class="bfb_sub_option" style="font-family:lucida grande,tahoma,verdana,arial,sans-serif;font-size:11px;">
											%hide_left_nav_groups% Groups<br>
											<div class="bfb_sub_option">
												%hide_left_nav_groups_create% Create Group
											</div>
											%hide_left_nav_pages% Pages<br>
											%hide_left_nav_apps% Apps<br>
											%hide_chat_panel% Friends on Chat<br>
											%hide_status_updater% Name and picture
										</div>
									</div>
									<div>
										<help>These navigation sections on the left side expand to show the sub-categories when you click on them. If you want them expanded by default (for example, to see the count of "Other" messages at all times), you can do that here</help>
										<b>Auto-expand</b>:
										<div class="bfb_sub_option" style="font-family:lucida grande,tahoma,verdana,arial,sans-serif;font-size:11px;">
											%expand_nav_messages% Messages<br>
											%expand_nav_events% Events<br>
											%expand_nav_photos% Photos<br>
											%expand_nav_apps% Apps<br>
											%expand_nav_friends% Friends
												<div>&nbsp;&nbsp;&nbsp;%expand_nav_friends_full% Auto-expand all friend groups</div>
										</div>
									</div>
									<div class="">
										<help>These are handy boxes that Better Facebook can add to help you quickly jump to your favorite pages, events, etc. You can click the box title to collapse/expand them, and you can even click "edit" on each box to choose which items you don't want to see listed.</help>
										<b>Add Quick-Link Boxes</b>:
										<div class="bfb_sub_option" style="font-family:lucida grande,tahoma,verdana,arial,sans-serif;font-size:11px;">
											%show_my_pages% "My Pages"<br>
											%show_my_events% "My Events"<br>
											%show_my_groups% "My Groups"<br>
											%show_my_apps% "My Apps"
										</div>
									</div>
								</td>
								<td style="vertical-align:top;background-color:white;">
									<div>
										<help>
											The "control" panel is the box that appears at the top of feeds.<br>
											This is convenient because it holds controls to mark the entire feed as read or muted in one click. The status line shows you a count of different actions performed by Better Facebook.
										</help>
										%display_control_panel% Display the "<b>Control Panel</b>" at the top.<br>
										<img src="https://s3.amazonaws.com/Wizard/cp.png" style="width:295px;"><br>
										<help>
											As you scroll down the page, the control panel can float down with you. This is useful because when you reach the bottom of the page, you can access the control panel to mark everything as read without having to scroll back to the top of the page.
										</help>
										%float_control_panel% Float it down the page as you scroll</div>
									</div>
									<br><hr><br>
									<div>
										<img src="https://s3.amazonaws.com/Wizard/post_actions.png"><br>
										<help>When you hover over individual posts, a "tray" of action icons appears in the upper right of the post.<br>
										This option controls which icons you want to appear in the icon tray and how they should appear.
										</help>
										%show_post_actions% Show <b>Post Action Icons</b> on each post. 
									</div>
									<br><hr><br>
									<div>%stretch_wide% <b>&lt;--- Stretch the layout</b> to full screen width ---&gt;</div>

								</td>
								<td style="width:250px;border:1px solid #ccc;vertical-align:top;background-color:white;">
									<div>%hide_happening_now% Hide the "ticker" feed of friends activity</div>
									<div>%hide_game_sidebar% Hide the Game icon sidebar</div>
									<div>%hide_game_ticker% Hide friends' real-time Game activity</div>
									<div>%ticker_scroll% Scroll the ticker down with the page rather than keeping it static</div>
									<div>%unlock_right_col% Unlock the right column so it scrolls with the page</div>
									<div>
										<div style="background-color:#f3f3f3;color:#333;font-weight:bold;padding:2px;">
											<help>These are the boxes you have hidden from the right column by clicking the "X" in the title bar. To add them back to your page, click the "x" here to remove them from the "hidden" list.</help>
											Hide these boxes (click the X to unhide):
										</div>
										<div class="bfb_sub_option">%right_panels_hidden_list%</div>
									</div>
									<br>
									<div class="">
										<div style="background-color:#f3f3f3;color:#333;font-weight:bold;padding:2px;">Add these boxes:</div>
										<div>
					<!--					<div>%show_sticky_note% Show Sticky Note</div> -->
											<div>
												<help>Friend Tracker monitors your friend list and informs you when someone goes missing - usually a sign that they have unfriended you!</help>
												%show_friend_tracker% Friend Tracker (Unfriend Notifier)
												<div class="bfb_sub_option bfb_option_advanced">Refresh every %friend_tracker_interval% hours</div>
											</div>
											<div>
												<help>This box will let you know when a friend changes their profile information, such as address, favorite quotes, etc.</help>
												%show_friend_activity% Friend Activity
												<div class="bfb_sub_option bfb_option_advanced">Refresh every %friend_activity_interval% hours</div>
											</div>
											<div>
												<help>Tips of the day will appear at most once every day or two, and will tell you about features or options you may not know about!</help>
												%tips_of_the_day% Tips of the Day
											</div>
										</div>
									</div>
								</td>
							</tr>
						</table>
					</div>

					<div class="bfb_option_body" id="bfb_t_posts_body" style="vertical-align:bottom;">
						<div>
							<help>These are the action icons to show in the upper right corner of posts when you hover over them.<br><br>If you want the icons to be invisible until you hover, check the "Hid euntil hover" box.<br>When you hover over a post, the icons are semi-transparent, which is the opacity. 0=invisible, 1=no transparency. (When you move your mouse over the icons themselves, they will be fully visible). The "zoom" setting makes the icons bigger, for those browsers that support it.</help>
							%show_post_actions% Show <b>Post Action Icons</b> on each post. <br>
							Post Action Icons: %hide_post_actions_until_hover% Hide until hover / Opacity=%post_action_opacity2% / Zoom=%post_action_zoom%%
							<div>Show: 
								%show_post_action_info% Post Info
								%show_post_action_google% Google It
								%show_post_action_info_add_app% Add App
								%show_post_action_mark_unread% Mark Unread
								%show_post_action_info_mute% Mute
								%show_post_action_info_mark_read% Mark Read
							</div>
						</div>
						<div>%fix_timestamps% Fix timestamps to show actual date/time ("one hour ago" becomes "12:34am (one hour ago)")</div>
						<div>
							<help>Facebook indicates which posts it considers to be "Top Story" by a shaded triangle in the upper left posts. If you don't care which posts it thinks are Top Stories, you can hide them by enabling this option.</help>
							%hide_top_story_indicator% Hide the "Top Story" triangle indicators in the upper left of posts
						</div>
						<div>
							<help>Due to a bug in Facebook's code, some users don't see a cursor when they focus into a comment box to add a comment. This fix puts the cursor back again.</help>
							%fix_comment_cursor% Fix the missing cursor problem in comment boxes
						</div>
						<div>
							<help>Due to a bug in Facebook's code, when typing comments some users don't see text wrap to the next line until they type more characters past the end of the line. This makes it hard to see what you're typing on tne next line. This fixes that problem.</help>
							%fix_comment_wrap% Fix the line wrap problem in comments as you type past the end of line
						</div>
						<div>
							<help>Facebook has a feature built in that watches your page scroll and automatically loads new posts when you get near the bottom. This cause cause Facebook to slow down, and in particular when Better Facebook is running. By default, BFB turns this feature off.</help>
							%disable_scroll_load% Disable Facebook's auto-loading of more posts as you scroll down
						</div>
						<div>
							<help>Posts by applications like games often have a link to claim a gift or item. With this option, you can force those links to open in a new tab, so you don't lose your place in the feed.<br><br>If you enable the second option, the post will also be marked as read and disappear from view, so you can concentrate on the unclaimed posts that are left.</help>
							When clicking a link in an application post, %open_app_link_in_tab% open in a new browser tab/window and %open_app_link_marks_read% automatically mark the story as read
						</div>
						<div>
							<help>Often after you comment on a post, you want it to disappear unless someone else posts a followup. This is also a great way to manage a Page if you are Admin. As you reply to user posts, they will disappear from the wall until your wall is empty and you're done!</help>
							%mark_read_on_comment% Automatically mark a post as "read" after commenting on it
						</div>
						<div>%auto_expand_comments% Auto-expand collapsed comment threads on posts by Pages so all comments are visible</div>
						<div>
							<help>When someone posts multiple times in a row, Facebook groups those together under a "Similar Posts" link. When you expand this, all the posts are shown in a group. Instead, this option will re-order those inserted posts to the correct place in the feed timeline.</help>
							%reorder% Put expanded "similar" posts in proper chronological order after expanding
						</div>
						<div>
							<help>If you only want to mark posts as read on your news feed, and not on Pages or Profiles, you can disable that here. This will make the control panel go away at the top.</help>
							%process_profiles% Process posts on Profiles and Pages, add control panel, and allow Mark As Read
							<div>(But %dont_hide_posts_on_profiles% don't hide read posts on pages/profiles)</div>
						</div>
						<div>
							<help>If you don't want to process posts on Groups, you can disable that here</help>
							%process_groups% Process posts on Group Walls, add control panel, and allow Mark As Read
						</div>
						<div>%process_recent_activity% Add post icons to "Recent Activity" posts so they can be marked read individually</div>
						<div>%expand_see_more% Auto-expand "see more" links in posts to show the full post</div>
						<div>
							<help>"Read" posts re-appear if new comments are made. You can turn that feature off entirely, or set a threshold for a number of posts to trigger it to be turned off. This is useful on posts by Pages, for example. If a post gets more than 100 comments, for example, you can automatically make it stop re-appearing in your news feed.</help>
							Hide new notification of comments (%auto_mute_all% always) or when there are more than %auto_mute_count% comments
						</div>
						<div>%hide_old_comments% Hide old (read) comments when new comments are found on a post</div>
						<div>%undo_ctrl_z% Map Ctrl+z to "undo"</div>
						<div>
							<help>When you click links to external sites from within Facebook, it first sends you through a redirection service that checks for malicious links and logs the site you are going to, then redirects you there. You should not disable this unless you are sure of what you're doing.</help>
							%prevent_link_redirection% Prevent external link redirection
						</div>
					</div>
					
					<div class="bfb_option_body" id="bfb_t_display_body" style="vertical-align:bottom;">
						<div class="">%remove_recent_activity% Add a "remove all activity" link to <b>RECENT ACTIVITY</b> blocks
								<div>
									<help>You can select only specific types of "Recent Activity" posts to remove</help>
									<b>Auto-Remove Types</b>: 
									%remove_recent_activity_write_on_wall% Wall posts 
									%remove_recent_activity_comment_on_status% Status comments
									%remove_recent_activity_comment_on_photo% Photo comments
									%remove_recent_activity_comment_on_link% Link comments
									%remove_recent_activity_like_page% "Liking" a Page 
									%remove_recent_activity_added_friend% Adding a friend 
									%remove_recent_activity_relationship_change% Relationship changes
									%remove_recent_activity_added_other% Others 
								</div>
							<div>
								<help>After Recent Activity posts are removed, a yellow message box will appear in the upper right telling you what was removed. You can disable that here.<br><br>Also, by default, the removed posts on your wall are crossed out to show they have been removed (they will be completely gone when you refresh). Instead, you can choose to completely remove them from view.</help>
								%show_remove_recent_activity_message% Show message for %remove_recent_activity_message_duration% seconds when successful
							    (%erase_after_recent_activity_remove% Erase removed items rather than cross them out)
							</div>
						</div>
						<div>
							<help>Many users have wider screens and find it convenient to always have their notifications list handy. This option puts the Notifications list on the right side of the screen on every page, for quick access. You don't have to click the Notifications icon to view the list.</help>
							<b>Pin the notifications</b> panel to the %pin_notifications_right_panel% right sidebar or the %pin_notifications% far right
						</div>
						<div>
							<help>The comments list on Questions pages is in chronological order, so in order to see new comments you have to continually expand 10 at a time. Enabling this option will auto-expand these links for you.</help>
							%auto_expand_questions_comments% Auto-expand comments on Questions post pages
						</div>
						<div>
							<help>When you move your mouse over Notification items, this option will show you a popup view of the post or picture referenced in the notification so you don't need to click the notification to navigate to the page.</help>
							%show_notification_previews% Show previews when hovering over notification list items
						</div>
						<div>%tab_count% Show post count in tabs</div>
						<div>%hide_options_icon% Hide the icon next to the Better Facebook "Options" button in the header</div>
						<div>%options_in_account% Put the "Options" link under the "Account" menu</div>
						<div>%left_align% Left align the page rather than center</div>
<!--
						<div>
							<help>The "Top News" view picks the posts it thinks you would be most interested in, so you may miss out on posts by friends. The "Most Recent" view shows you all posts, in reverse chronological order. This is the view most people prefer, and Better Facebook by default switches you there if Facebook moved you back to Top News.</help>
							%force_most_recent_feed% Force the main news feed to be "<b>Most Recent</b>" instead of "Top News"
						</div>
-->
						<div>%alternate_read_display% Show old stories as grayed out rather than hiding them completely</div>
						<div>%reload_when_mark_all_read% Reload automatically when Mark All Read is clicked</div>
						<div>
							<help>This notification box only shows up for some users</help>
							%hide_update_email% Hide the "Please update your email address" box that appears repeatedly
						</div>
						<div>%show_char_counter% Add a character count down in status update boxes with a max of %char_counter_max% characters</div>
						<div>%hide_notification_pictures% Hide profile pictures in the notification list</div>
						<div>
							<help>By default, Facebook will show you a preview of a person or Page's profile when you hover over their name. You can disable that.</help>
							%hide_hovercard% Hide information popup when hovering over user name links
						</div>
						<div>
							<help>When taking a screenshot to post ina  public place, you may not want to reveal all of your friends' names and profile pictures. The anonymizer gets added to the Account dropdown in the blue header bar, and lets you anonymize the screen. If you do not want this added, uncheck this box.</help>
							%enable_anonymize% Add an "Anonymize Screen" option to the "Account" dropdown
						</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_advanced_body" style="vertical-align:bottom;">
						<div><b>These options give you complete control over lots of settings! Tweak it all you want!</b></div>
						<div>"Older Posts" selector:%older_posts_selector%</div>
						<div>
							<help>Each post on Facebook has an FBID that uniquely identifies it. Better Facebook uses this to remember which posts have been read. Unfortunately, some post types have their FBID change with each reload (I don't know why) which causes BFB to "forget" those posts. This is a list of story types that have this problem.</help>
							Story types requiring alternate FBID: %alt_fbid_types4%
						</div>
						<div>Notification preview Image max-width:%preview_img_max_width2% max-height:%preview_img_max_height2%</div>
						<div>%show_options_save_message% Show "Refresh the page" alert after saving Options</div>
						<div>Clean out data for individual posts after %comment_expire_days% days (per post) to save space in preferences</div>
						<div>%show_version_changes% Show changes after installing a new version</div>
<!-- /*UPDATECHECK*/-->
						<div>%check_for_updates% Check for script updates every %update_check_interval% hours
							<div>%check_for_beta_updates% Also check for BETA updates</div>
						</div>
<!-- /*/UPDATECHECK*/-->
						<div>%check_for_messages% Check for important Better Facebook messages every %message_check_interval% minutes</div>
						<div>%show_page_post_message% Show the Help message for new posts on the Better Facebook Page</div>
						<div>%allow_bfb_formatting% Allow posts by Better Facebook to retain html formatting</div>
						<div>Pause for %expand_similar_posts_delay%ms between clicks when expanding "Similar Posts" links</div>
						<div>Wait for %image_preview_delay% seconds before showing thumbnail previews on hover</div>
						<div>When Notifications are pinned to the right side, force it to be %pin_notifications_width% wide (ex:200px)</div>
						<div>Floating control panel opacity: %floating_cp_opacity% / Manual offset: %floating_cp_offset%px</div>
						<div>
							<help>
								When you click the Facebook logo in the upper left or any "Home" navigation item to return to your home page, Facebook actually uses an internal navigation mechanism that confuses Better Facebook and sometimes causes features to malfunction.
								 <br><br>
								 Enabling this option fixes this problem by redirecting you to the proper home page url when clicking these links.
							</help>
							</span>
							%fix_logo2% Fix navigation on the upper left logo and "News Feed" links to go to %home_url%
						</div>
						<div>%pagelet_toggle% Enable collapse/expand of boxes in right panel by clicking their headers</div>
						<div>Hide right column panels:<br>%right_panels_hidden%</div>
						<div>Hide these page sections:<br>%hidden_elements%</div>
						<div>Hide the "x" option from these page sections:<br>%hidden_elements_x%</div>
						<div>My Pages: %my_pages_new_window% Open in a new window | %my_pages_max_height%px high in position %my_pages_position%</div> 
						<div>My Events %my_events_new_window% Open in a new window | %my_events_max_height%px high in position %my_events_position%</div> 
						<div>My Groups: %my_groups_new_window% Open in a new window | %my_groups_max_height%px high in position %my_groups_position%</div> 
						<div>My Apps: %my_apps_new_window% Open in a new window | %my_apps_max_height%px high in position %my_apps_position%</div>
						<div>%show_friend_tracker_no_activity_msg% Show Friend Tracker message when there is no activity</div>
						<div>Show unfriends in Friend Tracker for %friend_tracker_duration% days</div>
						<div>%friend_activity_show_pics% Show small profile pictures in Friend Activity</div>
						<div>Hide Friend Activity if it matches pattern: %friend_activity_hide_text%</div>
						<div>Show control panel buttons: %cp_button_mark_all_read%Mark All Read
																		%cp_button_show_hide_all%Show/Hide All
																		%cp_button_mute_all%Mute All
																		%cp_button_reload%Reload
																		%cp_button_help%Help
																		%cp_show_status%Status
																		%cp_button_undo%Undo
						</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_filter_body">
						<div>
							<help>Disabling filters entirely lets you debug problems or temporarily switch to an unfiltered view</help>
							%filters_enabled% Enable Filters
						</div>
						<div>
							<help>If you have defined tabs in filter rules, they will only be created if there are actually posts to move there. This is to conserve space. If you would rather have all your tabs created - every time - then enable this.</help>
							%always_show_tabs% Always show all defined tabs (even if no posts are moved there)
						</div>
						<div>
							<help>If you don't want tabs created or "hiding" rules to run on profiles and pages, disable this option</help>
							%filter_profiles% Filter posts on pages and profiles
						</div>
						<div class="bfb_option_advanced">Don't auto-tab these apps: %untab_apps%</div>
						<div class="bfb_option_advanced">Custom App list: (format:  app_id:app_name,app_id:app_name&nbsp;&nbsp;&nbsp;&nbsp;ex: 12345:MyFarm)<br>%custom_apps%</div>
						<div class="no_hover">
							<table class="bfb_filter_list" border=1 width=100%>
							<thead>
								<tr>
									<th colspan="6" id="bfb_filter_add_row">Click to add another filter: </th>
								</tr>
								<tr>
									<th><help>Select one or more specific authors to filter (hold Ctrl when clicking to select multiple). If no authors are selected, then the filter applies to post by anyone. See <a href="http://betterfacebook.net/#ff" target="_blank">Documentation</a></help>
										Author
									</th>
									<th><help>Select one or more types of posts (hold Ctrl when clicking to select multiple). If no types are selected, then the filter applies to all types of posts.  See <a href="http://betterfacebook.net/#ff" target="_blank">Documentation</a></help>
										Type
									</th>
									<th><help>Select one or more Applications (hold Ctrl when clicking to select multiple). If no applications are selected, then the filter applies to all applications.  See <a href="http://betterfacebook.net/#ff" target="_blank">Documentation</a></help>
										Application
									</th>
									<th><help>Match any text in the post body itself. For example, type in "politics" (without the quotes) to select all posts with the word politics in them. Regular expressions may also be used, for expert users. See <a href="http://betterfacebook.net/#ff" target="_blank">Documentation</a></help>
										Other
									</th>
									<th><help>Select what to do with the posts that match your critieria. For a full explanation, see the <a href="http://betterfacebook.net/#ff" target="_blank">Documentation</a>.</help>
										Action
									</th>
									<th>&nbsp;</th>
								</tr>
							</thead>
							<tbody id="bfb_filter_list"></tbody>
							<tfoot id="bfb_filter_list_tfoot"></tfoot>
							</table>
						</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_hidden_body">
						<div class="no_hover">
						Some sections of the page may be hidden by hovering over them, and clicking on the "x" that appears. You can unhide sections by removing them from the list here.
						</div>
						<div class="no_hover"><b>Hidden Page Elements</b></div>
						<div class="no_hover" style="padding:10px 0px;">
							%hidden_elements_list%
						</div>
						<div class="no_hover"><b>Page Elements With "x" Removed</b></div>
						<div class="no_hover" style="padding:10px 0px;">
							%hidden_elements_x_list%
						</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_chat_body">
						<div>
							<help>Not all users have this, but many see a tall sidebar on the far right that goes all the way from the top to the bottom of the screen - but only when the screen is wide enough. This option lets you stop that bar from appearing, and instead revert to the "pop up" chat box.</help>
							%chat_disable_sidebar% Turn off the chat sidebar on the far right (if it exists) and go back to popup chat list
						</div>
						<div>
							<help>Facebook by default now shows friends it thinks you want to chat with. This restores previous behavior where all online friends are shown.</help>
							%chat_show_all_online% Show all online friends in chat list
						</div>
						<div>
							<help>Group friends by online status (active on top, idle below)</help>
							%chat_group_by_status% Group friends by online status (active on top, idle below)
						</div>
						<div>
							<help>If your chat list is tall, this will hide the profile pictures so the list is more compact.</help>
							%chat_compact% Use compact chat list (no thumbnail images)
						</div>
						<div>
							<help>If you never want to chat, but Facebook puts you back online for some reason, this will force it to logout every time you load a page.</help>
							%chat_force_offline% Automatically force chat logout on every page load		
						</div>
						<div>
							<help>If you never chat at all, you can hide the whole chat dock so you never have to see it!</help>
							%chat_hide% Hide the chat dock entirely (if you are logged in, this will NOT log you out!)
						</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_theme_body">
						<div class="no_hover">
							Select a theme to change the style of Facebook. Only you will see these changes in your browser. Others visiting your page or profile will not see your theme. For questions or to develop your own theme, see <a href="http://www.facebook.com/pages/ThemesSkins-with-Better-Face-book/187087164651628">Themes/Skins with Better Face book</a>.<br>
							<iframe src="http://BetterFacebook.net/themes/select.php?current_theme=%escaped_theme_url%" style="height:270px;width:90%;border:1px solid #ccc;" frameBorder="0"></iframe>
							<br>
							<span class="bfb_option_advanced">Theme URL: %theme_url% </span><input type="button" id="bfb_minimize_options" value="Click to preview"><br>
							Note: Not all themes may be compatible with all Better Facebook options. Some themes are created by third party authors. Try them out and see what works for you!
						</div> 
					</div>
					<div class="bfb_option_body" id="bfb_t_css_body">
						<div>Insert a reference to an external stylesheet:<br>%css_url%</div> 
						<div>Custom post action "sprite" url: %sprite_url%</div>
						<div class="no_hover">Add any arbitrary CSS rules to insert into the page:<br>
						For some useful CSS code to do common things, see: <a href="http://BetterFacebook.net/css_snippets.php">CSS Snippets</a> on BetterFacebook.net<br>
						%css%</div> 
					</div>
					<div class="bfb_option_body" id="bfb_t_prefs_body">
						<div class="no_hover">All of your stored preferences, story "read" statuses, comment counts, etc are stored in the JSON format below. This can be useful for backing up your preferences. You may also copy preferences into the box and import.</div> 
						<div class="no_hover"><textarea id="bfb_user_prefs"></textarea></div> 
					</div>
					<div class="bfb_option_body" id="bfb_t_debug_body">
						<div>If things aren't working right, this is where we'll fix it!</div>
						<div>%debug% Enable Debug Mode</div>
						<div>%performance_monitor% Enable Performance Monitoring: %performance_monitor_auto_scroll% Auto-Scroll %performance_monitor_dom_insertions% Show DOM Inserts %performance_monitor_show_messages% Show Messages</div>
						<div>%show_errors% Show errors</div>
						<div>Test setting/getting preferences: <input type="button" id="bfb_debug_test_set" value="Set Pref"> <input type="button" id="bfb_debug_test_get" value="Get Pref"></div>
						<div class="no_hover">Trace Log: <i>(Copy the contents of this box along with bug reports, please!)</i></div>
						<div class="no_hover" id="bfb_tracelog">%tracelog%</div>
					</div>
					<div class="bfb_option_body" id="bfb_t_about_body">
						<div class="no_hover" style="font-size:16px !important;">
							<img src="https://s3.amazonaws.com/BFB/matt.jpg" style="float:left;margin:10px;border:1px solid black;">
							My name is <a href="http://MattKruse.com">Matt Kruse</a>, and I am the author of Better Facebook.<br><br>
							To learn more about me, my family, and this project, visit the <a href="http://BetterFacebook.net/about.php">About Me</a> page on <a href="http://BetterFacebook.net">BetterFacebook.net</a>!
							<br><br>
							<a href="http://BetterFacebook.net/donate.php" target="_blank"><img border="0" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif"></a> to support development!
							<br><br>
							The Facebook logo under the "Better" sign in the Better Facebook logo was originally designed by <a href="http://chris.ivarson.name/">Chris Ivarson</a>.
							<br><br>
							Special thanks to the members of the <a href="http://Facebook.com/bfbdev">Better Facebook Dev</a> page for helping to find problems, helping debug them, and tirelessly testing new features!
						</div> 
					</div>
				</div>
			]]></>).toString());
			content = content.replace("%tracelog%",tracelog);
			content = content.replace(/\<help\>/gi,'<span class="bfb_help"><span class="bfb_helptext">').replace(/\<\/help\>/gi,'</span></span>');
			// Replace the options place-holders with the actual options
			content = content.replace('%escaped_theme_url%',encodeURIComponent(options.get('theme_url')));
			this.options.forEach(function(opt,i) {
				if (opt.name) {
					content = content.replace( new RegExp("%"+opt.name+"%","g"), self.renderOption(opt));
				}
			});
			// List the hidden right side panels
			var hidden_panels = split(self.get('right_panels_hidden'),';');
			var hidden_panels_html = '';
			$each(hidden_panels, function(){ 
				if(this && this.length>0) { 
					hidden_panels_html+='<div><img src="'+x_img+'" style="cursor:pointer;" onclick="i=document.querySelector(\'input[name=&quot;right_panels_hidden&quot;]\');i.value=i.value.replace(/'+this+';?/,\'\');this.parentNode.style.display=\'none\';"> '+this+'</div>'; 
				} 
			});
			content = content.replace('%right_panels_hidden_list%',hidden_panels_html);
			
			// List the hidden sections
			var hidden_elements_list = split(self.get('hidden_elements'),',');
			var hidden_elements_html = '';
			$each(hidden_elements_list, function(){ 
				if(this && this.length>0) { 
					hidden_elements_html+='<div><img src="'+x_img+'" style="cursor:pointer;" onclick="i=document.querySelector(\'input[name=&quot;hidden_elements&quot;]\');i.value=i.value.replace(/'+this+';?/,\'\');this.parentNode.style.display=\'none\';"> '+this+'</div>'; 
				} 
			});
			content = content.replace('%hidden_elements_list%',hidden_elements_html);

			// List the sections with hidden "x" options
			var hidden_elements_x_list = split(self.get('hidden_elements_x'),',');
			var hidden_elements_x_html = '';
			$each(hidden_elements_x_list, function(){ 
				if(this && this.length>0) { 
					hidden_elements_x_html+='<div><img src="'+x_img+'" style="cursor:pointer;" onclick="i=document.querySelector(\'input[name=&quot;hidden_elements_x&quot;]\');i.value=i.value.replace(/'+this+';?/,\'\');this.parentNode.style.display=\'none\';"> '+this+'</div>'; 
				} 
			});
			content = content.replace('%hidden_elements_x_list%',hidden_elements_x_html);
			
			return content;
		};

		// When the Feed Filters tab is loaded, get the typeahead content so we can generate the filters list with the typeahead content
		onIdLoad('bfb_filter_list',function(tbody) {
			trace("bfb_filter_list loaded");
			if (options.get('feed_filter_show_help')) {
				var div = tbody.parentNode.parentNode;
				insertFirst( div, message('<b>Feed Filters</b> allow you to control which posts you see and how they are displayed. This powerful interface gives you full control.<br><br>When a post is displayed, it will first be checked against each filter rule below. If it matches the selections for Author, Type, Application, and Other, then the Action will be taken. You can find <b>full documentation</b> of how to use the Feed Filter <b><a href="http://BetterFacebook.net/#ff" target="_blank">on the Better Facebook web site</a></b>.<br><br><b>NOTE!</b> Using filters may slow down Facebook while posts are being processed. Using many filters may cause increased slowdown on slower computers.', function() { options.set('feed_filter_show_help',false); }) );
			}
			get_remote_content('typeahead',function(response) {
				trace("typeahead content loaded for filters");
				var renderOption = function(v,t,sel) {
					return '<option value="'+v+'"'+(sel?' selected':'')+'>'+t+'</option>';
				};
				var renderFilter = function(filter,options) {
					trace("Rendering filter");
					return '<tr class="bfb_filter '+((filter!=null&&filter.disabled)?"bfb_filter_disabled":"")+'">'+renderFilterBody(filter,options)+'</tr>';
				};
				var renderFilterBody = function(filter,options,tr) {
					if (!filter || !filter.criteria) { filter = {criteria:{},actions:{}}; }
					var tds = [], c="";
					tds.push('<select class="nosave actrs" style="width:150px;" name="actrs" size="10" multiple>'+options+'</select>');
					
					c='<select class="nosave sty" name="sty" size="10" style="width:175px;" multiple onchange="var sel=false;for(var i=0;i<this.options.length;i++){if(this.options[i].selected){sel=true;break;}};var a=this.parentNode.parentNode.getElementsByClassName(\'app_id\')[0];a.style.display=(sel?\'none\':\'\');a.selectedIndex=-1;a=this.parentNode.parentNode.getElementsByClassName(\'app_id_custom_wrap\')[0];a.style.display=(sel?\'none\':\'\');">';
					for (var i in storyTypes) { 
						// For each story type, check to see if any of the comma-separated values are selected. If so, select the option
						var selected = false;
						var type_list = i.split(/\s*,+\s*/);
						for (var j=0; j<type_list.length; j++) {
							if (filter.criteria.sty && (type_list[j] in filter.criteria.sty)) {
								selected = true; break;
							}
						}
						c += renderOption(i,storyTypes[i],selected); }
					c+='</select>';
					tds.push(c);

					c='<select class="nosave app_id" style="width:150px;" name="app_id" size="8" multiple onchange="var sel=false;for(var i=0;i<this.options.length;i++){if(this.options[i].selected){sel=true;break;}};var a=this.parentNode.parentNode.getElementsByClassName(\'sty\')[0];a.style.display=(sel?\'none\':\'\');">';
					for (var i in apps) { c += renderOption(i,apps[i],(filter.criteria.app_id && (i in filter.criteria.app_id))); }
					// Build a list of app_id's that are not "known"
					var app_id_custom = [];
					if (filter.criteria.app_id) {
						for (var i in filter.criteria.app_id) {
							if (typeof apps[i]=="undefined") { app_id_custom.push(i); }
						}
					}
					c+='</select><div class="app_id_custom_wrap">Custom app_id(s):<br><input name="app_id_custom" class="nosave app_id_custom" value="'+app_id_custom.join(',')+'" size="15"></div>';
					tds.push(c);
					
					tds.push('Matching<br>text:<br> <input class="nosave regex" name="regex" value="'+(filter.criteria.regex?htmlescape(filter.criteria.regex):'')+'" size="6"><br>Advanced:<br>Use regular<br>expressions<br>like<br>/text|text2/<br>( | = OR )');
					tds.push(''+
					'	<input class="nosave action-hide" '+(filter.actions.hide?' checked ':'')+' type="checkbox" name="action" value="hide"> Hide<br>'+
					'	<input class="nosave action-minimize" '+(filter.actions.minimize?' checked ':'')+' name="action" value="minimize" type="checkbox"> Minimize<br>'+
					'	<input class="nosave action-addclass" '+(filter.actions.add_class?' checked ':'')+' name="action" value="add_class" type="checkbox"> Apply CSS Class: <br>'+
					'		<input class="nosave add-class" name="add_class" size="8" value="'+(filter.actions.add_class?filter.actions.add_class:'')+'" onkeyup="this.parentNode.getElementsByClassName(\'action-addclass\')[0].checked=(this.value!=\'\');"><br>'+
					'	<input class="nosave action-movetotab" '+(filter.actions.move_to_tab?' checked ':'')+' name="action" value="move_to_tab" type="checkbox"> Move to Tab: <br>'+
					'		<input class="nosave move-to-tab" name="move_to_tab" size="8" value="'+(filter.actions.move_to_tab?filter.actions.move_to_tab:'')+'" onkeyup="this.parentNode.getElementsByClassName(\'action-movetotab\')[0].checked=(this.value!=\'\');"><br>'+
					'	<input class="nosave action-stop" '+(filter.stop?' checked ':'')+' name="action" value="stop" type="checkbox"> Stop processing rules');
					var action_buttons = '<img class="bfb_up" style="cursor:pointer;" src="'+up_img+'" onclick="tr=this.parentNode.parentNode;tr.parentNode.insertBefore(tr,tr.previousSibling);"><br><img style="cursor:pointer;" src="'+delete_img+'" onclick="if(confirm(\'Delete this filter row?\')){var tr=this.parentNode.parentNode;tr.parentNode.removeChild(tr);}"><br><img class="bfb_down" style="cursor:pointer;" src="'+down_img+'" onclick="tr=this.parentNode.parentNode;tr.parentNode.insertBefore(tr.nextSibling,tr);">';
					action_buttons += '<br><input type="hidden" class="nosave filter-disabled" value="'+(filter.disabled?'true':'false')+'"><img src="'+pause_img+'" class="bfb_filter_pause" onclick="this.previousSibling.value=\'true\';this.parentNode.parentNode.className+=\' bfb_filter_disabled\';" style="cursor:pointer;" title="Disable this filter but do not remove it">';
					action_buttons += '<br><img src="'+play_img+'" class="bfb_filter_play" onclick="this.parentNode.querySelector(\'input.filter-disabled\').value=\'false\';this.parentNode.parentNode.className=\'bfb_filter\';" style="cursor:pointer;" title="Enable this filter">';
					tds.push(action_buttons);
					
					// If passed in a tr, append the tds, otherwise make a string
					c = "";
					for (var i=0; i<tds.length; i++) {
						var td = tds[i];
						if (tr) { tr.appendChild( el('td',null,null,null,td) ) }
						else { c+="<td>"+td+"</td>"; }
					}
					return c;
				}

				var friends=[],pages=[];
				var list = "";
				if (response) {
					var json = parse(response.substring(9),"Typeahead content");
					if (json.payload) {
						var connections = json.payload.entries;
						if (connections) {
							connections = connections.sort( function(a,b) { return (a.t>b.t)?1:-1; } );
							for (var i=0; i<connections.length; i++) {
								var c = connections[i];
								if (c.ty=="u") { friends.push(c); }
								if (c.ty=="p") { pages.push(c); }
							}
							friends = friends.sort( function(a,b) { return (a.t>b.t)?1:-1; } );
							pages = pages.sort( function(a,b) { return (a.t>b.t)?1:-1; } );
							var renderAuthorOptions = function(friendlist,pagelist,filter) {
								if (!filter || !filter.criteria) { filter = {criteria:{},actions:{}}; }
								var list = '<optgroup label="Friends">';
								for (var i=0; i<friends.length; i++) {
									list += renderOption(friends[i].i,friends[i].t,(filter.criteria.actrs && (friends[i].i in filter.criteria.actrs)));
								}
								list += '</optgroup>';
								list += '<optgroup label="Pages">';
								for (var i=0; i<pages.length; i++) {
									list += renderOption(pages[i].i,pages[i].t,(filter.criteria.actrs && (pages[i].i in filter.criteria.actrs)));
								}
								list += '</optgroup>';
								return list;
							}
							// For each filter, render the filter. Pass in the options for authors
							var filters = self.get('filters');
							var fcontent = "";
							// If there are no filters, create an empty shell
							if (!filters || filters.length==0) {
								fcontent = renderFilter(null,renderAuthorOptions(friends,pages,null));
							}
							else {
								for (var i=0; i<filters.length; i++) {
									trace("Rendering Filter: "+JSON.stringify(filters[i]));
									fcontent += renderFilter(filters[i],renderAuthorOptions(friends,pages,filters[i]));
								}
							}
							
							// Populate all the content into the tbody
							tbody.innerHTML = fcontent;
						}
						else {
							showerror("No connections");
						}
					}
					else {
						showerror("No json.payload");
					}
				}
				else {
					showerror("No response!");
				}
				
				var add_filter = function(position) {
					var body = renderFilterBody(null,renderAuthorOptions(friends,pages,null));
					var tr = el('tr','bfb_filter');
					renderFilterBody(null,renderAuthorOptions(friends,pages,null),tr);
					if (position=="top") {
						insertFirst( tbody, tr );
					}
					else {
						append( tbody, tr );
					}
				}
				// Attach an "add" button
				append($('bfb_filter_add_row'),button('Add at the Top', function(){ add_filter('top'); },null));
				append($('bfb_filter_add_row'),button('Add at the Bottom',function(){ add_filter('bottom'); },null));
			});
		});
			
		this.displayOptions = function(tab_id) {
			var doc = document;
			// Scroll to the top
			scroll_to_top();
			var optionsContent = this.render(tab_id);
			var optionsWrapper = _template( ''+
		'		<div class="GM_options_wrapper_inner">'+
		'			<form name="%key%" id="form_%key%">		\n'+
		'				<div class="GM_options_header">		\n'+
		'					<div class="GM_options_buttons bfb_options_minimized_hide">		\n'+
		'						<input type="button" name="GM_options_save" id="GM_options_save" value="Save">		\n'+
		'						<input type="button" name="GM_options_cancel" id="GM_options_cancel" value="Cancel">\n'+
		'					</div>		\n'+
		'					<img id="bfb_options_icon" src="https://s3.amazonaws.com/BFB/thumb.png" style="max-height:50px;margin-right:20px;cursor:pointer;" align="left" border="0" title="Click to minimize/maximize options">		\n'+
		'					<div class="bfb_options_minimized_hide"><i>Version '+version+'</i><span style="padding-left:50px;">Official Site: <b><a href="http://BetterFacebook.net" target="_blank">BetterFacebook.net</a></b></span><br>What\'s New? See <b><a href="http://betterfacebook.net/blog/blog/category/releasenotes/" target="_blank">Release Notes</a></b></div>'+
		'					<div class="bfb_options_minimized_hide"><input id="bfb_show_advanced_options" type="checkbox" name="show_advanced_options" '+(this.get('show_advanced_options')?'checked':'')+'> <label for="bfb_show_advanced_options"><b>Advanced Options Mode</b></label></div>'+
		'				</div>		\n'+
		'				<div class="GM_options_body bfb_options_minimized_hide">		\n'+
		'						%options%		\n'+
		'				</div>		\n'+
		'				<div class="bfb_options_minimized_hide" style="text-align:center;">		\n'+
		'					<div class="GM_options_buttons" style="float:none;text-align:center;width:auto;">		\n'+
		'						<input type="button" name="GM_options_save" id="GM_options_save2" value="Save">		\n'+
		'						<input type="button" name="GM_options_cancel" id="GM_options_cancel2" value="Cancel">		\n'+
		'					</div>		\n'+
		'				</div>		\n'+
		'				<div style="float:right;" class="bfb_options_minimized_hide"><a href="http://BetterFacebook.net/faq.php#uninstall" onclick="alert(\'Before uninstalling, please review the FAQ if you are having any problems or issues. You may find the solution there. Also, I would appreciate an email at matt@mattkruse.com letting me know why you uninstalled, so I can improve BFB in the future!\');">Uninstall</a></div><div style="clear:both;"></div> \n'+
		'			</form>		\n'+
		'		</div>', {'options':optionsContent,'key':this.key} );

			var div = this.optionsDiv;
			var self = this;
			if (div==null) {
				this.optionsDiv = doc.createElement('div');
				div = this.optionsDiv;
				div.className = 'GM_options_wrapper bfb_window_height100 '+this.key+'_wrapper '+(!this.get('show_advanced_options')?'bfb_options_simple_mode':'');
				div.id = "bfb_options";
				html( div, optionsWrapper );
				doc.body.appendChild(div);
				bind(div,'click',function(e) { e.stopPropagation(); });
			}
			else {
				div.innerHTML = optionsWrapper;
				div.className = 'GM_options_wrapper bfb_window_height100 '+this.key+'_wrapper '+(!this.get('show_advanced_options')?'bfb_options_simple_mode':'');
			}
			var minimize_options = function() { toggleClass( QS(document,'.GM_options_wrapper_inner'),"bfb_options_minimized"); };
			bind('bfb_show_advanced_options','click',function(e){ var c='bfb_options_simple_mode'; if ($('bfb_show_advanced_options').checked) { removeClass($('bfb_options'),c); } else { addClass($('bfb_options'),c); } });
			bind('bfb_options_icon','click',minimize_options);
			bind('bfb_minimize_options','click',minimize_options);
			bind('GM_options_save','click',function() { self.saveOptions(); });
			bind('GM_options_cancel','click',function() { self.cancelOptions(); apply_theme(undef,options.get('theme_url')); });
			bind('GM_options_save2','click',function() { self.saveOptions(); });
			bind('GM_options_cancel2','click',function() { self.cancelOptions(); apply_theme(undef,options.get('theme_url')); });
			bind('bfb_guided_setup','click',function(){ if(typeof guided_setup_action=="function"){guided_setup_action();} });
			append($('bfb_t_prefs_body'), button("Export Options",function(){ var json=JSON.stringify(self.prefs,function(k,v){if(k=="story_data"){return undefined;}return v;},1); if(confirm("The text box above will now be populated with your current preferences ("+json.length+" bytes). Continue?")) { $('bfb_user_prefs').value=json;} },"bfb_prefs_export_options") );
			append($('bfb_t_prefs_body'), button("Export All (including story data)",function(){ var json=JSON.stringify(self.prefs,null,1); if(confirm("The text box above will now be populated with your current preferences ("+json.length+" bytes). Continue?")) { $('bfb_user_prefs').value=json;} },"bfb_prefs_export_all") );
			append($('bfb_t_prefs_body'), button("Import",function(){ 
				if(confirm('Are you sure you want to overwrite your existing preferences and import the prefs above?')){
					var json = $('bfb_user_prefs');
					if (json) { json = json.value; }
					if (json) {
						try {
							var prefs = JSON.parse(json);
							self.prefs = prefs;
							self.save();
						}
						catch(e) {
							alert("There was an error importing your preferences:\n"+e.toString());
							alert("To make sure that your prefs are in valid JSON format, visit JSONLint.com");
						}
					}
					else {
						alert("Couldn't find input with import text!");
					}
					self.cancelOptions();
				}
			},"bfb_prefs_import") );
			append($('bfb_t_prefs_body'), button("Clean Story Data",function(){ if(confirm('This will prune old story data from your preferences. (This is also done automatically once a day!)')){clean_prefs();}},"bfb_prefs_clean") );
			append($('bfb_t_prefs_body'), button("Reset Prefs",function(){ 
				if(confirm('ALL OPTIONS WILL BE RESET TO THEIR DEFAULT VALUES! ARE YOU SURE?')){
					options.options.forEach(function(opt,i) {
						if (opt.name) {
							options.set(opt.name,opt['default'],false);
						}
					});
					options.save();
				}
			},"bfb_prefs_reset") );
			bind('bfb_debug_test_set','click',function() { self.set('debugtest',time()); alert("Test preference saved"); });
			bind('bfb_debug_test_get','click',function() { var v=self.get('debugtest'); if(v){ alert("Test preference set on:"+((new Date(v)).toString())); }else{alert("No saved preference found"); } });
			// Keep check boxes in sync!
			var cb_sync = function(cb) { 
				if (cb && cb.name && cb.name!="action") { QSA(document,'#bfb_options input[name="'+cb.name+'"]',function(cb2){cb2.checked=cb.checked;}); }
			};
			QSA(this.optionsDiv,'.bfb_featured_option',function(fo) {
				bind(fo,'click',function(e){ var o=e.target; if(o&&o.tagName&&o.tagName=="INPUT"){return;}; QSA(this,'input[type="checkbox"]',function(cb){ cb.checked=!cb.checked; cb_sync(cb); }); });
			});
			bind(this.optionsDiv,'click',function(e) { var o=e.target; if(o&&o.tagName&&o.tagName=="INPUT"&&o.type&&o.type=="checkbox") { cb_sync(o); } });
			
			// Add an event listener for switching tabs
			var showtab = function(e) { 
				var tabs = $('bfb_tabs');
				if (typeof e=="string") {
					var tabid = $(e).id;
				}
				else {
					var tabid = target(e).id
				}
				for(var i=0;i<tabs.childNodes.length;i++){
					removeClass(tabs.childNodes[i],'bfb_tab_selected');
				}
				addClass($(tabid),"bfb_tab_selected"); 
				$$('bfb_option_body',"this.style.display='none';",$('bfb_options_body'));
				$(tabid+"_body").style.display="block";
			}
			bind($('bfb_tabs'),'click',showtab);

			tab_id = tab_id || 'bfb_t_popular';
			showtab(tab_id);
			div.style.display="block";
		};
		this.hideOptions = function() {
			if (this.optionsDiv!=null) {
				this.optionsDiv.style.display='none';
				this.optionsDiv.innerHTML='';
			}
		};
		this.cancelOptions = function() {
			this.hideOptions();
		};
		this.saveOptions = function() {
			this.load();
			var doc = document;
			var f = doc.getElementById('form_'+this.key);
			if (f && f.elements) {
				for (var i=0; i<f.elements.length; i++) {
					var e = f.elements[i];
					if (e.name && e.name.indexOf("GM_")!=0 && !hasClass(e,"nosave")) {
						if (e.type=="checkbox") {
							this.set(e.name,e.checked,false);
						}
						else if (e.type=='text') {
							this.set(e.name,e.value,false);
						}
						else if (e.type=='textarea') {
							this.set(e.name,e.value,false);
						}
						else if (e.type=='select-one') {
							this.set(e.name,e.options[e.selectedIndex].value,false);
						}
					}
				}
			}
			else {
				alert('Form not found!');
			}
			
			// Read in the filter rules to create filters list
			var getSelectValue = function(sel){var r=null;for (var i=0; i<sel.options.length; i++) {var o = sel.options[i];if (o.selected) {if(r==null){r={};};r[o.value]=o.text;}}return r;};
			var hasprops = function(o){for(var i in o){return true;}};

			var savefilters = [];
			var tbody = $('bfb_filter_list');
			try {
				if (tbody) {
					var trs = tbody.getElementsByTagName('TR');
					if (trs && trs.length>0) {
						for (var i=0; i<trs.length; i++) {
							var tr = trs[i];
							var filter = {criteria:{},actions:{}};
							var cr=function(name) { return tr.getElementsByClassName(name)[0]; }
							// Criteria
							var actrs = getSelectValue(cr('actrs'));
							if (actrs) { filter.criteria.actrs = actrs; }
							var sty = getSelectValue(cr('sty'));
							if (sty) {
								var styo = {};
								for (var sty_id in sty) {
									var id_list = sty_id.split(/\s*,+\s*/);
									if (id_list) {
										for (var j=0; j<id_list.length; j++) {
											styo[id_list[j]] = id_list[j];
										}
									}
								}
								filter.criteria.sty = styo; 
							}
							var app_id = getSelectValue(cr('app_id'));
							if (app_id) { filter.criteria.app_id = app_id; }
							var app_id_custom = cr('app_id_custom');
							if (app_id_custom) {
								var app_ids_custom = app_id_custom.value.split(/\s*,\s*/);
								if (app_ids_custom && app_ids_custom.length>0) {
									for (var j=0; j<app_ids_custom.length; j++) {
										if (app_ids_custom[j].length>0) {
											if (typeof filter.criteria.app_id=="undefined") {
												filter.criteria.app_id={};
											}
											filter.criteria.app_id[app_ids_custom[j]] = "Custom app_id:"+app_ids_custom[j];
										}
									}
								}
							}
							var regex = cr('regex').value;
							if (regex && regex.length>0) { filter.criteria.regex=regex; }
							// Actions
							if (cr('action-hide').checked) { filter.actions.hide=true; }
							if (cr('action-minimize').checked) { filter.actions.minimize=true; }
							if (cr('action-addclass').checked) { filter.actions.add_class=cr('add-class').value; }
							if (cr('action-movetotab').checked) { filter.actions.move_to_tab=cr('move-to-tab').value; }
							if (cr('action-stop').checked) { filter.stop=true; }
							filter.disabled = (cr('filter-disabled').value=="true");
							
							if (filter.criteria && filter.criteria.sty && filter.criteria.app_id) {
								// Can't have a filter on both sty and app_id! Doesn't make sense!
								delete filter.criteria.app_id;
							}
							if (hasprops(filter.criteria)) {
								savefilters.push(filter);
							}
						}
						this.set('filters',savefilters,false);
						filters = savefilters;
					}
				}
			} catch(e) { }
			
			this.save(false);
			if (options.get('show_options_save_message')) {
				alert("Refresh the page to see your changes");
			}
			this.hideOptions();
		};
	}
	catch(e) { return null; }
}

// ==================================================================
// Context-Sensitive Help
// ==================================================================
(function() {
	var bfb_help_popup = null;
	var bfb_help_popup_visible = false;
	document.addEventListener('click',function(e) {
		var o = target(e);
		if (hasClass(o,"bfb_help")) {
			if (!bfb_help_popup) {
				bfb_help_popup = el('div','bfb_helptext mini_x',{title:'Click to close Help'});
				document.body.appendChild(bfb_help_popup);
			}
			var helptext = QS(o,".bfb_helptext",'innerHTML');
			if (helptext) {
				bfb_help_popup.innerHTML = helptext;
				bfb_help_popup.style.visibility="hidden";
				show(bfb_help_popup);
				var x = (e.pageX-bfb_help_popup.offsetWidth);
				if (x<0) { x=e.pageX; }
				bfb_help_popup.style.left = x+'px';
				bfb_help_popup.style.top = (e.pageY+16)+'px';
				bfb_help_popup.style.visibility="visible";
				bfb_help_popup_visible = true;
				if (e.stopPropagation) { e.stopPropagation(); }
				if (e.preventDefault) { e.preventDefault(); }
			}
		}
		else if (bfb_help_popup_visible) {
			hide(bfb_help_popup);
			bfb_help_popup_visible = false;
		}
	},true);
})();

// ==================================================================
// LOAD OPTIONS AND BEGIN THE REAL PROCESSING!
// ==================================================================
var options = new GM_options('better_facebook',userid);
// Asynchronous for Chrome
options.load(function(prefs){
	var option_keys = [];
	// Script Options
	if (options) {
		var a = function(name,type,def,opt,style) { options.addOption(name,type,def,opt,style); /* trace(name+"="+options.get(name)); */ }
		a('show_advanced_options','checkbox',false);
		a('disabled','checkbox',false);
		a('disabled_on_apps','checkbox',false);
		
		// RIGHT SIDEBAR
		a('pagelet_toggle','checkbox','true');
		a('show_friend_tracker','checkbox',true);
		a('show_friend_tracker_no_activity_msg','checkbox',true);
		a('friend_tracker_duration','input',3,{size:2} );
		a('friend_tracker_interval','input',1,{size:2} );
		a('friend_tracker_last_update','hidden',null);
		a('friend_tracker_content','hidden',null);

		a('show_group_activity','checkbox',true);
		a('group_activity_interval','input',1,{size:2} );
		a('group_activity_last_update','hidden',null );
		a('group_activity_content','hidden',null );

		a('show_friend_activity','checkbox',true );
		a('friend_activity_interval','input',1,{size:2} );
		a('friend_activity_show_pics','checkbox',true );
		a('friend_activity_hide_text','input','^Profile Picture$',{size:15} );
		a('friend_activity_last_update','hidden',null );
		a('friend_activity_content','hidden',null );
		a('friend_activity_last_seen','hidden','' );
		
		a('show_sticky_note','checkbox',true);
		a('right_panels_hidden','input','',{size:80});

		a('ticker_scroll','checkbox',true);
		a('hide_happening_now','checkbox',false);
		a('unlock_right_col','checkbox',true);
		a('hide_game_sidebar','checkbox',false);
		a('hide_game_ticker','checkbox',false);

		// LEFT PANEL
		a('show_nav_all_connections','checkbox',true );
		a('show_nav_edit_friends','checkbox',true );
		a('show_nav_write_a_note','checkbox',true );
		a('show_nav_pages_i_admin','checkbox',true );
		a('show_nav_unblock_applications','checkbox',true );

		a('expand_nav_apps','checkbox',false );
		a('expand_nav_messages','checkbox',false );
		a('expand_nav_events','checkbox',false );
		a('expand_nav_photos','checkbox',false );
		a('expand_nav_friends','checkbox',false );
		a('expand_nav_friends_full','checkbox',false );
		a('hide_status_updater','checkbox',false );
		
		a('hide_chat_panel','checkbox',false);
		a('hide_left_nav_groups','checkbox',false);
		a('hide_left_nav_groups_create','checkbox',false);
		a('hide_left_nav_apps','checkbox',false);
		a('hide_left_nav_pages','checkbox',false);

		a('show_my_pages','checkbox',true );
		a('my_pages_new_window','checkbox',true );
		a('my_pages_default_open','checkbox',true );
		a('my_pages_position','input','3',{size:2} );
		a('my_pages_max_height','input','700',{size:3} );

		a('show_my_events','checkbox',true );
		a('my_events_new_window','checkbox',true );
		a('my_events_default_open','checkbox',false );
		a('my_events_position','input','4',{size:2} );
		a('my_events_max_height','input','700',{size:3} );

		a('show_my_groups','checkbox',true );
		a('my_groups_new_window','checkbox',true );
		a('my_groups_default_open','checkbox',false );
		a('my_groups_position','input','5',{size:2} );
		a('my_groups_max_height','input','700',{size:3} );

		a('show_my_apps','checkbox',true );
		a('my_apps_new_window','checkbox',true );
		a('my_apps_default_open','checkbox',false );
		a('my_apps_position','input','6',{size:2} );
		a('my_apps_max_height','input','700',{size:3} );

		a('show_friends_by_network','checkbox',true );
		a('friends_by_network_new_window','checkbox',true );
		a('friends_by_network_default_open','checkbox',false );
		a('friends_by_network_position','input','7',{size:2} );
		a('friends_by_network_order_by_count','checkbox',false );
		a('friends_by_network_max_height','input','700',{size:3} );

		// DISPLAY OPTIONS
		a('expand_similar_posts','checkbox',false );
		a('expand_similar_posts_delay','input','1000',{size:4} );
		a('display_control_panel','checkbox',true );
		a('process_profiles','checkbox',true );
		a('process_groups','checkbox',true );
		a('dont_hide_posts_on_profiles','checkbox',false);
		a('hide_options_icon','checkbox',false );
		a('options_in_account','checkbox',false);
		a('left_align','checkbox',false );
		a('pin_notifications','checkbox',false );
		a('pin_notifications_right_panel','checkbox',false );
		a('pin_notifications_width','input','',{size:5} );
//		a('force_most_recent_feed','checkbox',true );
		a('force_most_recent_feed_pages','checkbox',true );
		a('auto_click_more_times','input',3,{size:2},'padding:0;width:20px;font-size:11px;');
		a('auto_click_older_posts','checkbox',false );
		a('disable_scroll_load','checkbox',true);
		a('older_posts_selector','input','.fbOlderPosts, .uiMorePager a.lfloat, .uiMorePager a.uiMorePagerPrimary, #profile_pager_container .uiMorePager, #profile_pager_container .uiMorePagerPrimary',{size:50});
		a('alternate_read_display','checkbox',false );
		a('reload_when_mark_all_read','checkbox',false );
		a('auto_mute_count','input',0,{size:3} );
		a('auto_mute_all','checkbox',false );
		a('hide_old_comments','checkbox',true );
		a('hide_update_email','checkbox',false );
        a('reorder','checkbox',false);
		a('chronological','checkbox',true);
		a('hide_top_story_indicator','checkbox',false);
//		a('reorder_page_walls','checkbox',false);
		a('show_char_counter','checkbox',true);
		a('char_counter_max','input','420',{size:4});
		a('static_header','checkbox',false);
		a('static_left_col','checkbox',false);
		a('hide_notification_pictures','checkbox',false);
		a('show_post_actions','checkbox',true);
		a('post_action_opacity2','input','.5',{size:3});
		a('post_action_zoom','input','100',{size:3});
		a('hide_post_actions_until_hover','checkbox',true);
		a('show_notification_previews','checkbox',true);
		a('float_control_panel','checkbox',false);
		a('floating_cp_opacity','input','.75',{size:3});
		a('floating_cp_offset','input','0',{size:2});
		a('hide_hovercard','checkbox',false);
		a('cp_button_mark_all_read','checkbox',true);
		a('cp_button_show_hide_all','checkbox',true);
		a('cp_button_mute_all','checkbox',true);
		a('cp_button_reload','checkbox',true);
		a('cp_button_help','checkbox',true);
		a('cp_button_undo','checkbox',true);
		a('cp_show_status','checkbox',true);
		a('auto_expand_comments','checkbox',false);
		a('expand_see_more','checkbox',false);
		a('process_recent_activity','checkbox',false);
		a('chat_images_to_names','checkbox',false);
		a('enable_font_size','checkbox',false);
		a('post_font_size','input','13',{size:3},'padding:0;width:20px;font-size:11px;');
		a('comment_font_size','input','13',{size:3},'padding:0;width:20px;font-size:11px;');
		a('remove_recent_activity','checkbox',true);
		a('show_remove_recent_activity_message','checkbox',true);
        a('erase_after_recent_activity_remove','checkbox',false);
		a('remove_recent_activity_message_duration','input','5',{size:2});
		a('auto_remove_recent_activity','checkbox',false);
		a('stretch_wide','checkbox',false);
		a('show_image_previews','checkbox',true);
		a('image_preview_delay','input','.5',{size:3});
		a('fix_timestamps','checkbox',true);
		a('disable_theater_view','checkbox',false);
		a('fix_comments','checkbox',false);
		a('undo_ctrl_z','checkbox',true);
		a('fix_comment_cursor','checkbox', (SCRIPT_TYPE=="greasemonkey" || SCRIPT_TYPE=="firefox_addon" || SCRIPT_TYPE=="firefox_addon_official") );
		a('fix_comment_wrap','checkbox',false);
		// Questions
		a('auto_expand_questions_comments','checkbox',true);
		
		// Comment replies
		a('comment_reply','checkbox',true);
		a('comment_reply_float_textarea','checkbox','true');
		a('comment_reply_first_name_only','checkbox',false);
		
		// post actions
		a('show_post_action_info','checkbox',true);
		a('show_post_action_google','checkbox',true);
		a('show_post_action_mark_unread','checkbox',true);
		a('show_post_action_info_mute','checkbox',true);
		a('show_post_action_info_mark_read','checkbox',true);
		a('show_post_action_info_add_app','checkbox',true);
		// Recent Activity Types
		a('remove_recent_activity_write_on_wall','checkbox',true);//20
		a('remove_recent_activity_comment_on_status','checkbox',true);//107
		a('remove_recent_activity_comment_on_photo','checkbox',true);//46
		a('remove_recent_activity_like_page','checkbox',true);//47
		a('remove_recent_activity_comment_on_link','checkbox',true);//32
		a('remove_recent_activity_added_friend','checkbox',true);//21
		a('remove_recent_activity_relationship_change','checkbox',true);//3
		a('remove_recent_activity_added_other','checkbox',true);
		
		// Chat
		a('chat_disable_sidebar','checkbox',false);
		a('chat_force_offline','checkbox',false);
		a('chat_hide','checkbox',false);
		a('chat_show_all_online','checkbox',true);
		a('chat_compact','checkbox',false);
		a('chat_group_by_status','checkbox',true);
		
		// ADVANCED
		a('fix_logo2','checkbox',true);
		a('home_url','input','/',{size:20} );
		a('preview_img_max_width2','input','200',{size:4} );
		a('preview_img_max_height2','input','150',{size:4} );
		a('show_options_save_message','checkbox',true);
		a('comment_expire_days','input','21',{size:4} );
		a('open_app_link_in_tab','checkbox',false);
		a('open_app_link_marks_read','checkbox',false);
		a('mark_read_on_comment','checkbox',false);
		a('show_page_post_message','checkbox',true);
		a('allow_bfb_formatting','checkbox',true);
		a('sprite_url','input','',{size:20});
		
		// PAGELETS
		a('donated','hidden',false);
		a('no_donate','hidden',false);
		a('donate_check_time','hidden',0);
		a('check_for_messages','checkbox',true);
		a('last_message_check','hidden',0);
		a('message_check_interval','input',30,{size:5});
		a('last_message_id','hidden',0);
		a('show_message','hidden',true);
		a('tips_of_the_day','checkbox',true);
		a('last_tip_check','hidden',0);
		a('last_tip_id','hidden',0);
		a('show_current_tip','hidden',true);
		a('show_update','hidden',true);
		
		// MISC
		a('show_version_changes','checkbox',true );
		a('check_for_updates','checkbox',true );
		a('check_for_beta_updates','checkbox',false );
		a('update_check_interval','input','3',{size:3} );
		a('debug','checkbox',false );
		a('show_errors','checkbox',true);
		a('performance_monitor','checkbox',false);
		a('performance_monitor_auto_scroll','checkbox',true);
		a('performance_monitor_dom_insertions','checkbox',true);
		a('performance_monitor_show_messages','checkbox',true);
		a('alt_fbid_types4','input','15,60,10,313,263,316,285,7,8,116,278,62,3,77,9,55,56,245,-1,257,400,447',{size:50});
		
		// Hidden elements
		a('hidden_elements','input','',{size:80});
		a('hidden_elements_x','input','',{size:80});
		
		// CSS
		a('css_url','input','',{size:50} );
		a('css','textarea','',{rows:25,cols:80} );
		a('theme_url','input','',{size:60});

		// FEED FILTER
		a('always_show_tabs','checkbox',false);
		a('tab_all_apps','checkbox',true);
		a('tab_count','checkbox',true);
		a('filters','hidden',[]);
		a('feed_filter_show_help','hidden',true);
		a('filters_enabled','checkbox',true);
		a('custom_apps','input','',{size:80});
		a('untab_apps','input','',{size:80});
		a('filter_profiles','checkbox',true);
		
		a('friend_list_interval','input',1,{size:3} );
		
		a('enable_anonymize','checkbox',true);
		a('prevent_link_redirection','checkbox',false);

		// Hidden options
		a('version','hidden',0 );
		a('version_ack','hidden',0 );
		a('last_update_check','hidden',0 );
		a('last_msg2','hidden',0 );
		a('installed_on_5','hidden',0 );
		a('last_cleaned_on','hidden',0);
	}	
	
	// Don't run on Apps?
	if (options.get('disabled_on_apps') && host=="apps.facebook.com") { return; }
	
	// ===================================================
	// Options button
	// ===================================================
	onIdLoad('pageNav',function(nav) {
		if ($('bfb_options_button')==null) {
			var src = "data:image/gif,GIF89a%17%00%16%00%D5%00%00%00%00%00%FF%FF%FFbz%AD%D7%0C%10%E2pr%D648%D1LP%CB%16%1F%BB%1C(%BA%2B9%A4%234%9C-E%AB%40Y%BA%5Er%875R%88%40%60g0P%96o%93vMufBf%B1%A5%B8qX%84I%3FfUQ%7Cok%94%87%8A%ABWe%8F%3CMv(%3Bg%3ER~CV%7F0CkLi%A6BY%896Iph%84%B7%A5%BC%E4%3CZ%8Dq%92%C8%82%A1%D3%86%A6%D9%8F%B0%E5%8D%AB%DD%91%AE%DF%B0%C0%D9%3Cf%A6%C8%D5%E91T%83y%A3%DB%83%AB%DF%8F%B2%DE%D4%DA%E0%E7%EA%ED%F8%FA%FB%FD%FF%FF%FB%FD%FD%F9%FC%F9%FC%DC%DA%E2%1F%1F%E5BB%EC%95%95%F3%C2%C1%F9%ED%ED%FD%FD%FD%2C%00%00%00%00%17%00%16%00%00%06%FF%40%81pH%2C%1A%87%1A%8E%F2%C3l29%22M%26%83Iz%84%1B%CEG%C4%DDx%BD%D1Y%60%1C%C0y8%D8m%D7%DBiw%C4%E4%00M%F4I%8B%D8%1D%8F%BE%A3%B1%8D%7D%3D%04%3B%0Au%02%1Ewmz!!%25%25%18%3D%3C%04%06%0A%10%16%10%0AB%87y%8C%25!%17%0F%0B%09%04%3C9%14%2F%13%0E%2F%98%86%2F%9D%17%13%A0%0E%0F%15%19%80%3C%05%08%0A%07%2F%10%3C%02%AF%B2%0A%0F%12%1A%1A%18%04%04%05%3B%3C%3A%3A%3C%07%17%10%06%02%0A%0B%12!%C5%12%0A%08%09%3A%C8%05%CC%A2%04%13%1D%05%0D%16%2F%9F%12%07%09%0C%03%19%82%3D%03%3D%3B%06%05%04%10%2F%09%06%1E%16%03%07%0B%B6U8%20%A1%82%8E%1C%3Av%10pp%A1%04%2F%03%06%2C%9480%20%C1%82%01%1A%16%2Ch%81%A0%87G%16!P)%C0%C4%03B%8B%05%07%00%0E%B0%F6%A0%C5%08%5B%93%AC5%14%D0%C3%A4%84%01%08%24H%C0%00%02%83%04%7F%06%C8xP%00%D1%A2h%09!%09%8AV%00%01%A2%C2%83%04%09%1ED%F01%86E%0B%A6-%8E%0Ax%E0%20%C2%03%06%06%1AD%C8%00%03%86%0C%3F%01%5C%98X%3B%02%84%90%11%11%1A4%C8%A0%22%85%DD%15*H%FC%18%E3%E2%04%8A%13'%86%8C(%9BB%85%E1%15%88%F3%EEM%0B%18%F0%88%B7~Q%1C%5Ea7%85%5E%BE(%FE%A2x%2C%60%84%89%CC%86%2B%DB%25Q%E3%C6%0D%17%99Q%98%E0%7C%A4%F5%91%20%00%3B";
			var inaccount = options.get('options_in_account');
			if (options.get('disabled')) {
				var a = el('a',null,{href:'#',title:'Click to enable Better Facebook',id:'bfb_options_button'},{click:function() { options.set('disabled',false,true,function(){ try { location.reload(true); } catch(e){} }); return false; }},'<span style="color:'+(inaccount?'red':'yellow')+';font-weight:bold;">Enable BFB</span>');
			}
			else {
				var a = el('a',null,{href:'#',title:'Better Facebook! Options',id:'bfb_options_button'},{click:function() { if(inaccount){clickLink($('navAccountLink'),true);} options.displayOptions(); return false; }},'<img id="bfb_options_button_icon" src="'+src+'" style="float:left;margin-right:5px;"> '+(inaccount?'Better Facebook ':'')+'Options');
			}
			var li = el('li');
			append(li,a);
			var ul = QS(nav,'ul[role="navigation"]');
			if (inaccount && ul) {
				insertAtPosition(ul,li,-1);
			}
			else {
				insertFirst(nav,li);
			}
		}
	});

	// ===================================================
	// POWERED OFF?
	// ===================================================
	if (options.get('disabled') || !options.get('disable_scroll_load')) { 
		setScrollLoad(true); 	
	}
	if (options.get('disabled')) { return; }
	
	function toggle(o,default_open_option) {if (typeof o=="string") { o=$(o); }if (o && o.style) {var closed = (o.style.display=="none");o.style.display = closed?"":"none";if (default_open_option) {options.set(default_open_option,closed);}}}

	// some global option vars
	remote_content.typeahead.ttl=options.get('friend_tracker_interval')*3600;
	remote_content.friend_lists.ttl=options.get('friend_list_interval')*3600;
	remote_content.group_activity.ttl=options.get('group_activity_interval')*3600;
	remote_content.friend_activity.ttl=options.get('friend_activity_interval')*3600;
	show_errors = options.get('show_errors');
	performance_monitor_enabled = options.get('performance_monitor');

	var hidden_elements_string = options.get('hidden_elements') || '';
	var hidden_elements_x_string = options.get('hidden_elements_x') || '';
	var hidden_elements = array_to_object(hidden_elements_string.split(','));
	var hidden_elements_x = array_to_object(hidden_elements_x_string.split(','));
	
	// ===================================================
	// STICKY NOTES
	// ===================================================
	function sticky_note(o,position,content,pref,closefunc,opts,el_style,after) {
		var options_key = 'hide_sticky_'+pref;
		var opt;
		if (pref) {
			if (!options || options.get(options_key)) { return; }
			var is = installed_since();
			if (is==0) { return; }
			if (after && is()>after) { return; }
		}
		opts = opts || {};
		el_style = el_style || {};
		var prev_el_style = {};
		var c=el('div',"bfb_sticky_note bfb_sticky_note_"+position + ((opts.className)?" "+opts.className:"") );
		for (opt in opts) { if(opt!="className"){c.style[opt] = opts[opt]; } }
		for (opt in el_style) { 
			prev_el_style[opt] = o.style[opt];
			o.style[opt] = el_style[opt]; 
		}
		var inner_close_func = null;
		if (pref || closefunc) {
			inner_close_func = function() {
				if (pref) {
					options.set(options_key,true,true);
				}
				if (closefunc) {
					if (closefunc(c)===false) { return; }
				}
				removeChild(c);
				for (opt in prev_el_style) {
					o.style[opt] = prev_el_style[opt];
				}
			}
		}
		if (inner_close_func) {
			append(c, el('div','bfb_sticky_note_close',null,{'click':inner_close_func} ) );
		}
		if (typeof content=="string") {
			append(c,el('div',null,null,null,content));
		}
		else if (content && content.nodeName) {
			append(c,content);
			content.style.display="block";
		}
		append(c,el('div','bfb_sticky_note_arrow_border'));
		append(c,el('div','bfb_sticky_note_arrow'));

		var ps = current_style(o,'position');
		if (ps!="relative" && ps!="absolute" && ps!="fixed") {
			o.style.position="relative";
		}
		
		c.style.visibility="hidden";
		append(o,c);
		var height = c.offsetHeight;
		c.style.marginTop = -(height/2) + "px";
		c.style.visibility="visible";
	}
	
	// ===================================================
	// RPC MESSAGING
	// ===================================================
	var rpc_queue = [];
	var rpc_iframe = null;
	var rpc_window = null;
	var rpc_ready = false;
	var rpc_id = 0;
	var rpc_callbacks = {};
	function rpc(message,data,func) {
		var message_object = {'id':++rpc_id,'message':message,'data':data};
		trace_log("Posted Msg: "+JSON.stringify(message_object),'bfb_trace_message');
		if (!rpc_ready) {
			rpc_queue.push({'message':message_object,'func':func});
			// If the remote iframe doesn't exist, create it
			if (!rpc_iframe && document.body) {
				trace_log("Creating RPC iframe");
				rpc_iframe = el('iframe','bfb_rpc_iframe',{id:'bfb_rpc_iframe',src:'http://BetterFacebook.net/post_message.php'});
				document.body.appendChild(rpc_iframe);
			}
			return;
		}
		post_message(message_object,func);
	}
	function post_message(message_object,func) {
		rpc_callbacks[message_object.id] = func;
		if (rpc_window) {
			var msg = JSON.stringify(message_object);
			trace_log("Sending RPC message:"+msg,'bfb_trace_message');
			rpc_window.postMessage(msg,"*");
		}
	}
	
	bind(window,'message',function(e) {
		var msg = e.data;
		trace_log("Msg:"+msg,'bfb_trace_message');
		try {
			if (msg) {
				msg = JSON.parse(msg);
				if (msg.message) {
					if (msg.message=="ready") {
						try { rpc_window = rpc_iframe.contentWindow; } catch(e){}
						if (!rpc_window) { try { rpc_window = rpc_iframe.wrappedJSObject.contentWindow; } catch(e){} }
						rpc_ready = true;
						// Send all the queued messages
						for (var i=0; i<rpc_queue.length; i++) {
							post_message(rpc_queue[i].message,rpc_queue[i].func);
						}
					}
					else if (msg.message=="select_theme") {
						QSA(document,'input[name="theme_url"]',function(i){ i.value=msg.href; });
						apply_theme(msg.href,options.get('theme_url'));
					}
					else if (typeof msg.id!="undefined") {
						var func = rpc_callbacks[msg.id];
						delete rpc_callbacks[msg.id];
						func(msg.message,msg.data);
					}
				}
			}
		}
		catch(e) { }
	});

	// ===================================================
	// Auto-click "Older Posts"
	// ===================================================
	var misfires=0;
	var olderPostsSelector = options.get('older_posts_selector');
	var maxOlderPostsClickCount = +options.get('auto_click_more_times') || 0;
	var maxmisfires= maxOlderPostsClickCount * 25;
	findAndClickOlderPosts = function() { 
		clickOlderPosts(QS(document,olderPostsSelector));
	}
	if (maxOlderPostsClickCount>0) {
		onIdLoad('pagelet_stream_pager',function() { delay(findAndClickOlderPosts,2500); });
		onIdLoad('profile_pager',function(){ delay(findAndClickOlderPosts,2500) });
		onUnload(['pagelet_stream_pager','profile_pager'],function() {
			olderPostsClickCount = 0;
			misfires = 0;
		});
	}
	// Function to actually click Older Posts
	function clickOlderPosts(a) {
		var clicked = false;
		if (!options.get('auto_click_older_posts')) { return; }
		try {
			if ( !unsafeWindow.JSCC && (!unsafeWindow.UIIntentionalStream || !unsafeWindow.UIIntentionalStream.instance || !unsafeWindow.UIPagelet) ) {
				trace_log("Older Posts not clicked - JS not loaded");
				setTimeout(findAndClickOlderPosts,1000);
			}
			else if (!a) {
				// If the Older Posts link is not found at all, try again
				trace_log("Older Posts link not found");
				if (misfires++<maxmisfires) { setTimeout(findAndClickOlderPosts,1000); }
			}
			else if (olderPostsClickCount<maxOlderPostsClickCount) {
				var pager = getParentByClass(a,'uiMorePager');
				if (true) {
					if (pager && !QS(pager.parentNode,'.async_saving')) {
						trace_log("clicking Older Posts!");
						try {
							if ( !(parent(a,'#profile_pager')) && unsafeWindow.UIIntentionalStream.instance && unsafeWindow.UIIntentionalStream.instance.loadOlderPosts) { 
								unsafeWindow.UIIntentionalStream.instance.loadOlderPosts(); 
								clicked = true;
							}
							else if (a.onclick) {
								a.onclick();
								clicked = true;
							}
						} catch(e) { }
						if (!clicked) {
							clickLink(a,false);
						}
						update_status('bfb_status_older',(++olderPostsClickCount));
						// Click again after a short delay
						setTimeout(findAndClickOlderPosts,1000);
					}
					else { trace_log("Not clicking Older Posts (has class async_saving)"); if (misfires++<maxmisfires) { setTimeout(findAndClickOlderPosts,1000); } }
				}
				else {
					trace_log("Not clicking Older Posts (Javascript not loaded yet)");
					setTimeout(findAndClickOlderPosts, 1000);
				}
			}
			else { trace_log("Not clicking Older Posts (already too many)"); }
		} catch(e) { if (misfires++<maxmisfires) { setTimeout(findAndClickOlderPosts,1000); } }
	}

	trace("Browser:"+window.navigator.userAgent);
	trace("BFB Version:"+version);
	trace("Script Type:"+SCRIPT_TYPE);

	// ==================================================================
	// MAKE USE OF FACEBOOK'S INTERNAL DATA! (if possible)
	// ==================================================================
	function $Env(key) { 
		if (typeof unsafeWindow!="undefined" && typeof unsafeWindow.Env!="undefined") { return unsafeWindow.Env[key]; }
		var val = QS(document,'input[name='+key+']','value');
		if (val) { return val; }
		return null;
	}

	// Log the filters
	trace("filters="+JSON.stringify(options.get('filters')));

	// Set the install time of the script
	if (options.get('installed_on_5')==0) {
		options.set('installed_on_5',time(),false);
		options.set('last_message_check',time(),false);
		options.save();
	}
	function installed_since() {
		var io = +options.get('installed_on_5');
		if (!io) { return 0; }
		return time()-io;
	}

	// DEBUG?
	DEBUG = options.get('debug');
	PERFORMANCE = options.get('performance_monitor');
	function debugmsg(str) {
		return '<div class="debug_small">'+str+'</div>';
	}

	var info_icon = "\"data:image/gif,GIF89a%10%00%10%00%E6%7F%00%B7%8A%2BrV%1A666%9B%9B%9B%B1%86)%F5%BCB%D6%A33%CE%9D1qqq7)%0C%FF%C6%3F)%1E%09%FD%C0%3C%F5%BA%3A%DC%B2V%03%03%02%1C%1C%1C%1C%15%07%09%09%09III%0E%0E%0D%11%11%11%12%0E%032%26%0B%FF%C2%3C%FC%BF%3C%FF%C3%3D%FF%C4%3D%F9%BD%3A%FF%C2%3D%FB%BE%3B%FC%BF%3BWWW%E5%E5%E5%F1%B79%86%86%86%FA%FA%FA%95%95%95%FF%CDR%FB%BF%3C*'%20%FF%C1%3BG%3E(%FF%C6A%E4%E4%E4%9Dw%24OOO%E2%AB4%FF%D2c%F8%C2O%CF%AAY%E9%B17%FB%BF%3B%F2%B89%17%17%17%60%60%60%B8%97O%FF%C8%40%FF%C9C%F8%BC%3AK%3D%1E%F3%C1X%84n%3F%FB%BE%3A%B7%B7%B7%C7%A1MJJJ%AB%8FRhhhbJ%16%E9%B6F%A5%A5%A5%FA%C8%5B%CC%9B%2F%93w8%E1%E1%E1%B3%8B4%B1%B1%B1%7B%5D%1C%80f-%A8%A8%A8%FA%C3E%8Dk!%2C!%0A6*%10%06%07%0A%0A%08%02%FE%C2%3C%AE%AE%AE%BC%8E%2C%D5%A6C%FF%C6%3D%FF%C3%3F%C6%96%2F%3B%3B%3B%EF%B58%DF%DF%DFggg%BE%99J%E7%AE6yb4%FF%CBA%98%98%98%C1%93-%7B%7B%7B%FF%C3961(%AA%83%2F%AE%85%2C%82k%3A5%2F%24%FA%BE%3B%FB%BE9%B5%B5%B5%FD%BF9222%DC%ABA%FE%C1%3C%CF%9E1%FF%C4BC%3A%24%22%22%22%96%96%96%17%16%11%A3%7C'%F9%BD%3B%00%00%00%FF%FF%FF!%F9%04%01%00%00%7F%00%2C%00%00%00%00%10%00%10%00%00%07%DE%80%7F%82%83s%14%15%5E%83%89%83%23~U*%3C%0F~%8A%89~n81%05%04%09~%03%93~j%0E90%26%5B%07%9B%8A%126AiHCk%0D%18g%16%10%83D%0F%3E%2BW%0E%0F%0F%5D%1A%0CR~%08%82%14(Fr%5C2~~%00%1A'%22%09%15%82~m%0A%1C%1D%BB%0F%07%1Do%18-%0F%7Fy%7BZ)%7D4%05T%0B_%19%7D%193%0B%02%12xQ%3F%7D%1CwbL%0C%7D%FC%0A%01%12%12%C8%E8%E0%D0%07N%0F%25ljx%E0%A7%81%00%05%09O%CA%2C%C4%40%C7O%02%11%EC%18%7C%00%B0G%C2%02%03%1F6l%D8%C1'K%86%3A%1D%1A%18%08%F0%00%81%1F%0BE%F8%24y%81a%C3%18%3B%04%9C%5Cx%00BP%BC%97%11%A6%5CX%10%C1%8A%1FZ%8A%D0%FCq1a%C2%1F%10a%12%05%02%00%3B\"";

	// ==================================================================
	// CLEAN THE PREFS EVERY DAY!
	// ==================================================================
	clean_prefs = function() {
		var comment_expire_time = days * options.get('comment_expire_days'); 
		// Prune the old comment counts so the prefs don't get huge
		var t = time();
		var pruned_count = 0;
		var story_data = options.get('story_data');
		if (story_data) {
			for (var s in story_data) {
				var story = story_data[s];
				var cc = story.cc;
				if (cc && cc.t) {
					// First copy any new counts to the current counts
					if (cc.nt) { cc.t = cc.nt; delete cc['nt']; }
					if (cc.nc) { cc.c = cc.nc; delete cc['nc']; }
					// This is the new format
					if (t-cc.t > comment_expire_time) {
						delete story_data[s];
						pruned_count++;
					}
				}
				else if (t-story.read > comment_expire_time) {
					delete story_data[s];
					pruned_count++;
				}
				// Get rid of junk cnc props
				if (typeof story['cnc']!="undefined") {
					delete story['cnc'];
				}
				// If there are no story properties, get rid of it
				var prop_count = 0;
				for (var p in story) { prop_count++; }
				if (!prop_count) {
					delete story_data[s];
				}
			}
			options.set('story_data',story_data,false);
			options.set('last_cleaned_on',time(),false);
			options.save();
			if (pruned_count) { trace("Pruned "+pruned_count+" old story comment counts"); }
		}
		return pruned_count;
	}
	if (time()-options.get('last_cleaned_on') > 1000*60*60*24 ) {
		clean_prefs();
	}
	
	// ==================================================================
	// QUEUED LINK CLICKING
	// ==================================================================
	var clickLinkQueue = [];
	var clickLinkQueueTimer = null;
	var clickLinkQueueDelay = options.get('expand_similar_posts_delay') || 1000;
	function clickLinkQueued(el) {
		if (clickLinkQueueTimer==null || (!el && clickLinkQueue.length>0)) {
			trace("Clicking link to expand similar posts. Will check back in "+clickLinkQueueDelay+" ms");
			if (!el) { el = clickLinkQueue.pop(); }
			el.style.backgroundColor="red";
			clickLink(el);
			clickLinkQueueTimer = setTimeout( function() { clickLinkQueued(); }, clickLinkQueueDelay);
		}
		else if (el) { clickLinkQueue.push(el); trace("Added link to queue. Queue length is now:"+clickLinkQueue.length); }
		else { clickLinkQueueTimer = null; trace("Nothing more to do in the click link queue"); }
	};

	// ==================================================================
	// Mark post as read after commenting
	// ==================================================================
	var commented_stories = {};
	if (options.get('mark_read_on_comment')) {
		var mark_read_on_comment = function(story,i) {
			var fbid = story.getAttribute('fbid');
			if (commented_stories[fbid]) {
				if (commented_stories[fbid]!=i) {
					delete commented_stories[fbid];
					setTimeout(function(){mark_post_read(story,true);},10);
				}
			}
			else {
				var fbid = story.getAttribute('fbid');
				commented_stories[fbid] = i;
			}
		};
		subscribe('UserAction/new',function(e,o) {
			try {
				var story = parent(o.node,storySelector);
				if (story && hasClass(story,"bfb_processed")) {
					mark_read_on_comment(story,2);
				}
			} catch(e) { alert(e.toString()); }
		});
		onSelectorLoad('.uiUfiComment.uiUfiUnseenItem',function(comment) {
			var story = parent(comment,storySelector);
			if (story && hasClass(story,"bfb_processed")) {
				mark_read_on_comment(story,1);
			}
		},'both');
	}
	
	// ===================================================
	// Handle DOM insertions
	// ===================================================
	bind(document,"DOMNodeInserted", function (e) {
		var f,id,selector,el,els;
		var o = target(e);
		if (o.nodeType==3 || internalUpdate) { return; }
		var tn = o.tagName;

		if (tn=="SCRIPT" || tn=="LINK" || tn=="INPUT" || tn=="BR" || tn=="STYLE") { return; }
		var cn = o.className, pn=o.parentNode;
		// Insertion of comment hidden elements on every keypress!
		if (cn=="DOMControl_shadow" || (pn.className && pn.className=="highlighter")) { return; }
		
		if (PERFORMANCE) { 
			trace_start("handleDomInsertion");
			if ($('bfb_trace_cb_insert','checked')) {
				trace_log("+ "+outerHTML(o,true),"bfb_trace_inserted"); 
			}
		}

		if (options.get("fix_timestamps")) {
			fix_timestamps(o);
		}

		var processed = false;
		// If the insertion is a minifeedwall or something within a minifeedwall, check the option to make sure it should be processed
		var isMiniFeedWall = ((getParentByClass(o,"minifeedwall")!=null) || (getParentByClass(o,"fbProfileStream")!=null) || (o.getElementsByClassName('minifeedwall').length>0));
		var isGroupWall = ($('pagelet_group_mall')!=null);
		if ( (!isMiniFeedWall || processProfiles) && (!isGroupWall || processGroups) ) {
			// If it's a story itself, process it
			if ( matchesSelector(o,storySelector)) {
				processed = true;
				fixStory(o,isMiniFeedWall,isGroupWall);
			}
			// Otherwise, process any stories within it
			else if (o && o.querySelectorAll) {
				var stories = QSA(o,storySelector);
				if (stories && stories.length>0 && !QS(o,'.permalink_stream')) {
					processed = true;
					fixStories (stories , isMiniFeedWall, isGroupWall );
				}
			}
			if (processed) {
				elementLoad(o,domNodeInsertedStreamHandlers);
			}
		}
		if (!processed) {
			// Check for handling of queries
			elementLoad(o,domNodeInsertedHandlers);
		}
		
		if (PERFORMANCE) { trace_end("handleDomInsertion"); }
	});

	// ==================================================================
	// HANDLE STREAM HEADER CHANGES
	// ==================================================================
	// When the stream header is inserted, check to see if we are on the Most Recent feed
/*
	var forceMostRecent = true;
	function updateMostRecentFeedStatus(header) {
		if (PERFORMANCE) { trace_start('updateMostRecentFeedStatus'); }
		var a = header.getElementsByTagName('A');
		if (a && a[0] && a[0].href) {
			a = a[0].href;
			if (a && !/sk=lf/i.test( a ) ) {
				forceMostRecent = false;
			}
			else if (forceMostRecent && options && options.get('force_most_recent_feed')) {
				// If not most recent feed, go there!
				window.location.href = a;
			}
		}
		if (PERFORMANCE) { trace_end('updateMostRecentFeedStatus'); }
	}
	onIdLoad("pagelet_stream_header",function(header) { 
		updateMostRecentFeedStatus(header);
		header.addEventListener('DOMSubtreeModified',function(e) { updateMostRecentFeedStatus(target(e)); },false);
	});
*/	
	// Check to see if we need to click "Most Recent" on Pages
	if (options.get('force_most_recent_feed_pages')) {
		onSelectorLoad('#wall_filter_list *[data-label="Most Recent"]:not(.checked) a',function(mostrecent) {
			var href=mostrecent.getAttribute('href');
			if (href) {
				try { location.href=href; } catch(e) { }
			}
		});
	}
	
	// ==================================================================
	// Kill the "Theater" photo viewer
	// ==================================================================
	if (options.get('disable_theater_view')) {
		var manipulatePhotoTheater = function() {
			if (unsafeWindow.PhotoTheater) { unsafeWindow.PhotoTheater = null; }
			setTimeout(manipulatePhotoTheater,1000);
		}
		manipulatePhotoTheater();
        unsafeWindow.addEventListener('click',function(e) {
			if (unsafeWindow.PhotoTheater) { unsafeWindow.PhotoTheater = null; }
            var a = parent(target(e),'a');
            if (a && a.getAttribute('rel')=="theater" || hasClass(a,'uiMediaThumb') || hasClass(a,'uiPhotoThumb')) {
				a.removeAttribute('rel');
				a.removeAttribute('ajaxify');
            }
		},true);
	}

	// ==================================================================
	// Insert a character counter in status update boxes
	// ==================================================================
	(function() {
		if (options.get('show_char_counter')) {
			onSelectorLoad('textarea.mentionsTextarea',function(ta) {
				if (!matchesSelector(ta,'#pagelet_composer textarea,#profile_stream_composer textarea')) { return; }
				var counter = null;
				var counter_max = options.get('char_counter_max') || 420;
				var wrap = getParentByClass(ta,'wrap');
				if (wrap && !(QS(wrap,'.bfb_char_count')) ) {
					var was_warning = false;
					ta.addEventListener('keyup',function(e) {
						if (!counter) {
							counter = QS(wrap,'.bfb_char_count');
							if (!counter) {
								counter = el('div','bfb_char_count',{id:'bfb_char_count'});
								wrap.appendChild(counter);
							}
						}
						if (counter) {
							var remaining = counter_max-(ta.innerHTML.length-4);
							if (hasClass(ta,"mentionsTextarea")) {
								remaining = counter_max-ta.value.length;
							}
							counter.innerHTML = remaining;
							if (remaining < 10) {
								addClass(counter,"bfb_char_count_warning");
								was_warning = true;
							}
							else if (was_warning) {
								removeClass(counter,"bfb_char_count_warning");
							}
						}
					
					},true);
				}
			});
		}
	})();
	
	// ==================================================================
	// GENERAL POPUP DIALOG
	// ==================================================================
	function show_dialog(content,header,okfunc,okbutton_text,footer_content) {
		var dialog = el('div','bfb_dialog');
		var dialog_content = el('div','bfb_dialog_content');
		if (header) {
			append(dialog,el('div','bfb_dialog_header',null,null,header));
		}
		if (typeof content=="string") { html(dialog_content,content); }
		else { append(dialog_content,content); }
		append(dialog,dialog_content);
		var footer = el('div','bfb_dialog_footer');
		if (footer_content) {
			if (typeof footer_content=="string") { html(footer,footer_content); }
			else { append(footer,footer_content); }
		}
		else {
			append(footer,button( (okbutton_text?okbutton_text:'OK') ,function(e){ if(okfunc) { okfunc(e); } removeChild(dialog); },'better_fb_close'));
		}
		append(dialog,footer);
		append(document.body,dialog);
		return dialog;
	}

	// ==================================================================
	// HELP DIALOG
	// ==================================================================
	function show_help() {
		var help = el('div','bfb_help_wrapper',null,null,'<iframe id="bfb_help_iframe" src="http://BetterFacebook.net/help.php"></iframe>');
		help.id = 'bfb_help_wrapper';
		var max_height = (window.innerHeight-150);
		help.style.height = max_height+"px";
		append(help,button('     Close Help     ',function(){$('bfb_help_wrapper').parentNode.removeChild($('bfb_help_wrapper'));},'bfb_help_close'));
		append(document.body,help);
		$('bfb_help_iframe').style.height = (max_height-70)+"px";
	}

	// ==================================================================
	// CONTROL PANEL
	// ==================================================================
	function createControlPanel(beforeEl) {
		trace("Creating control panel");
		var reload = function() { window.location.reload(); };
		var markAllRead = function() {
			markRead(function() {
				if (options.get('reload_when_mark_all_read')) {
					reload();
				}
			});
		}
		if (!$('better_fb_cp')) {
			var cp = el('fieldset','better_fb_cp',{id:'better_fb_cp'});
			append(cp, el('legend',null,null,null,'Better Facebook! ver. '+version+' ') );
			if (options.get('cp_button_mark_all_read')) { append(cp, button('Mark All Read',markAllRead,'better_fb_mark_read') ); }
			if (options.get('cp_button_show_hide_all')) { append(cp, button('Show/Hide All',toggle_show_all,'better_fb_show_hide_all') ); }
			if (options.get('cp_button_mute_all')) { append(cp, button('Mute All',mute_all,'better_fb_mute_all') ); }
			if (options.get('cp_button_reload')) { append(cp, button('Reload',reload,'better_fb_reload') ); }
			if (options.get('cp_button_undo')) { append(cp, button('Undo',undo,'') ); }
			if (options.get('cp_button_help')) { append(cp, button('Help!',show_help,'bfb_button_help') ); }
			if (DEBUG) {
				append(cp, button('Toggle Debug',function(){ toggleClass(document.body,"debug"); },'better_fb_debug_button') );
				
				var lr = el('div','bfb_debug');
				var setpref = el('div',null,null,null,'Set Preference: Name:<input size=10 id="bfb_setpref_name"> Value:<input size=10 id="bfb_setpref_val">');
				append(setpref, el('input',null,{type:'button',value:'Save'},{click:function() { options.set($('bfb_setpref_name').value,$('bfb_setpref_val').value); alert('Saved');}}) );
				append(lr,setpref);
				append(cp, lr );
				
				append(cp, el('div','',{id:'better_fb_debug_console'}) );
			}
			add_hideable(cp,'BFB Control Panel','display_control_panel',true,null,"-12px","-8px");
			insertFirst( beforeEl.parentNode , cp);
			if (options.get('cp_show_status')) {
				var sc = '<span style="cursor:help;" title="The number of posts that have been delivered by Facebook and processed by BFB">Processed:<span id="bfb_status_processed">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of posts that have been hidden by a filter or because they are already read">Hidden:<span id="bfb_status_hidden">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of posts that have matched a filter rule. Toggle the checkbox to quickly turn filters on or off"><input type="checkbox" id="bfb_status_filters_cb">Filtered:<span id="bfb_status_filtered">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of posts that have been moved to a tab by a filter rule">Tabbed:<span id="bfb_status_tabbed">0</span><span class="bfb_status_separator">|</span></span>';
                sc += '<span style="cursor:help;" title="The number of posts reordered to be chronological">Reordered:<span id="bfb_status_reordered">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of duplicate posts delivered by Facebook and detected and hidden by BFB">Dupes:<span id="bfb_status_duplicate">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of SIMILAR POSTS posts automatically expanded">Expnd:<span id="bfb_status_expanded">0</span><span class="bfb_status_separator">|</span></span>';
				sc += '<span style="cursor:help;" title="The number of times Older Posts has been automatically clicked. Toggle the checkbox to quickly enable or disable this feature"><input type="checkbox" id="bfb_status_older_posts_cb">Older Posts:<span id="bfb_status_older">0</span>/<input style="font-size:inherit;padding:0px;width:15px;cursor:pointer;" onfocus="this.select()" id="bfb_status_older_posts_input" value="'+maxOlderPostsClickCount+'"></span>';
				append(cp, el('div',null,{id:'bfb_status'},null,sc));
				$('bfb_status_older_posts_cb').checked = options.get('auto_click_older_posts');
				bind($('bfb_status_older_posts_cb'),'click',function(e) {
					options.set('auto_click_older_posts',this.checked);
					if (this.checked) {
						// If turned on, then run clicking of older posts immediately
						findAndClickOlderPosts();
					}
				});
				bind($('bfb_status_older_posts_input'),'change',function(e) {
					var newval = +this.value || 0;
					var findnow = false;
					options.set('auto_click_more_times',newval);
					if (newval > maxOlderPostsClickCount) {
						findnow = true;
					}
					maxOlderPostsClickCount = newval;
					maxmisfires = maxOlderPostsClickCount * 25;
					if (findnow) {
						findAndClickOlderPosts();
					}
				});
				$('bfb_status_filters_cb').checked = options.get('filters_enabled');
				bind($('bfb_status_filters_cb'),'click',function(e) {
					options.set('filters_enabled',this.checked);
					alert("Refresh the page to view it with filters "+(this.checked?"enabled":"disabled"));
				});
			}
			
			// What to do when the control panel is removed
			subscribe('page_transition',function() {
				// Reset counters
				nofbidcount = 0;
				storyCount = 0;
				count_processed = 0;
				count_hidden = 0;
				count_filtered = 0;
				count_tabbed = 0;
				count_reordered = 0;
				count_expanded = 0;
				count_duplicate = 0;
			});
			
			// Handle page scrolling to keep control panel at the top
			var firstScroll = true;
			var manualOffset = +( options.get('floating_cp_offset') || 0);
			var originalTop = 0
			var originalWidth = 0;
			var offsetWidthSet = false;
			if (options.get('float_control_panel')) {
				document.addEventListener('scroll', function(e) {
					if (!cp) { return; }
					var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
					if (firstScroll) {
						// Capture the starting position of the control panel
						originalTop = offset(cp).top - 41;
						originalWidth = cp.offsetWidth;
						firstScroll = false;
					}
					if (scrollTop > originalTop) {
						addClass(cp,'bfb_cp_float');
						cp.style.top = ((scrollTop-originalTop)+manualOffset)+"px";
						if (!offsetWidthSet) {
							cp.style.offsetWidth = originalWidth+"px";
							offsetWidthSet = true;
						}
					}
					else {
						removeClass(cp,'bfb_cp_float');
						cp.style.top = cp.style.offsetWidth = "";
						offsetWidthSet = false;
					}
				},false);
			}

		}
	}
	var status_timeout = {};
	function update_status(id,val,prop) {
		var s = $(id);
		if (s) {
			if (status_timeout[id]) {
				clearTimeout(status_timeout[id]);
			}
			status_timeout[id] = setTimeout( function() { if (s) { s.style.color=''; } }, 2000 );
			if (prop) {
				s[prop] = val;
			}
			else {
				html(s,val);
			}
			s.style.color='red';
		}
	}

	// ==================================================================
	// STATIC CSS
	// ==================================================================
	(function() {  // Wrapped for code collapsing
		var o = {};
		var zoom = +options.get('post_action_zoom')/100;
		o.floating_cp_opacity = options.get('floating_cp_opacity');
		o.post_action_opacity2 = options.get('post_action_opacity2');
		
		// Conditional options to add as CSS classes to the HTML tag
		var condition_options = ['alternate_read_display','hide_post_actions_until_hover','hide_hovercard','expand_nav_messages','expand_nav_events','expand_nav_photos','expand_nav_friends','expand_nav_friends_full','left_align','static_header','static_left_col','hide_update_email','hide_options_icon','hide_old_comments','hide_notification_pictures','hide_chat_panel','hide_status_updater','stretch_wide','fix_comments','fix_comment_cursor','fix_comment_wrap','hide_happening_now','unlock_right_col','chat_disable_sidebar','chat_hide','hide_left_nav_groups','hide_left_nav_groups_create','hide_left_nav_apps','hide_left_nav_pages','chronological','hide_top_story_indicator','ticker_scroll'];

		var classes = "";
		for (var i=0; i<condition_options.length; i++) {
			if (options.get(condition_options[i])) { classes+=condition_options[i]+" "; }
		}
		if (classes) { addClass(document.getElementsByTagName('html')[0],classes); }

		// Add theme classes
		var add_theme_classes = function() {
			var now = new Date();
			var html_tag = document.getElementsByTagName('html')[0];
			if (html_tag) {
				var html_classes = html_tag.className;
				html_classes = html_classes.replace(/bfb_theme_[^\s]+\s*/g,"");
				html_classes += " bfb_theme_year_"+(now.getFullYear())+" bfb_theme_month_"+(now.getMonth())+" bfb_theme_date_"+(now.getDate())+" bfb_theme_hour_"+(now.getHours())+" bfb_theme_minutes_"+(now.getMinutes())+" bfb_theme_seconds_"+(now.getSeconds())+" ";
				html_tag.className = html_classes;
			}
		}
		add_theme_classes();
		// Refresh the theme classes every minute
		setInterval(add_theme_classes,60000);
		
		// Write out the CSS to the page
		var css = ((<><![CDATA[
	.better_fb_cp { padding:0px 5px 2px 5px; border:1px solid #ccc; margin:0px 0px 6px 0px; background-color:white; z-index:100; -moz-border-radius:5px; border-radius:5px; }
	.better_fb_cp legend { font-size:10px; color:#999; font-style:italic; background-color:white; }
	.bfb_cp_float { position:relative; z-index:14; opacity:.75; -moz-box-shadow:5px 5px 5px #999; -webkit-box-shadow:5px 5px 5px #999; border:2px solid #ccc; }
	.bfb_cp_float:hover { opacity:1; }

	.bfb_new_comment_notif { display:none; }
	.bfb_read, .bfb_muted { display:none !important; }
	.bfb_read.bfb_new_comments, .bfb_read.bfb_new_comments .bfb_new_comment_notif { display:block !important; }
	.bfb_hidden,.bfb_hidden.bfb_new_comments { display:none !important; }
	.bfb_minimized img, .bfb_minimized .comments_add_box { display:none !important; }
	.bfb_minimized > *, .bfb_minimized { min-height:0px !important; padding-bottom:0px; padding-left:0px !important; }
	.bfb_minimized * { margin:0 !important; }
	.bfb_minimized .uiStreamMessage, .bfb_minimized .GenericStory_Message { padding-left:0px !important; }
	.bfb_minimized .UIStoryAttachment { margin:0px !important; }
	.bfb_read.bfb_duplicate, .bfb_duplicate { display:none !important; }
	
	.bfb_undid { background-color:#ffffcc; }
	
	.bfb_hideable .bfb_hide_el { display:none; cursor:pointer; background:transparent url("data:image/gif,GIF89a%0B%00%0B%00%91%00%00%00%00%00%FF%FF%FF%9C%9A%9C%FF%FF%FF!%F9%04%01%00%00%03%00%2C%00%00%00%00%0B%00%0B%00%00%02%18%94%8F6%CB%AC%BA%9E%18%87%CA%88%B0%83%16%D7%5E%85%13w5M%82%0A%05%00%3B") no-repeat center center; width:11px; height:11px; }
	.bfb_hide_menu { display:none; position:absolute; margin-top:5px; right:0px; background-color:white; border:1px solid black; color:black; min-width:150px; }
	.bfb_hide_menu div.bfb_item { color:#3A579A; padding:4px 10px 5px; white-space:nowrap; font-weight:normal; }
	.bfb_hide_menu div.bfb_item:hover { background-color:#6D84B4; color:white; padding:3px 10px 4px; border-bottom:1px solid #3B5998; border-top: 1px solid #3B5998; }
	.bfb_hideable .bfb_hide_el.bfb_show_menu .bfb_hide_menu { display:block; }
	.bfb_hideable:hover .bfb_hide_el { display:block; }
	.bfb_hideable_hover { border:3px solid red; }
	.bfb_frame { border:2px solid red; background-color:#ccc; opacity:.3; position:absolute; top:0px; left:0px; z-index:999; }

	html.alternate_read_display .bfb_read, html.alternate_read_display  .bfb_muted { display:block !important; max-height:18px; min-height:18px !important; overflow:hidden; opacity:.25; }
	html.alternate_read_display .bfb_read:hover, html.alternate_read_display  .bfb_muted:hover { max-height:none;overflow:visible;opacity:1; }
	html.alternate_read_display .bfb_read.bfb_new_comments, html.alternate_read_display  .bfb_read.bfb_new_comments .bfb_new_comment_notif { max-height:none;overflow:visible;opacity:1; }

	/* Make sure that show all actually shows all */
	#content .bfb_show_all .bfb_processed { display:block !important; }
	#content .bfb_show_all .bfb_duplicate { display:none !important; }

	.UIButton_better_fb { margin:0px 3px !important; padding:0px 4px !important; }

	.bfb_new_comment_notif { width:350px; background-color:#edeff4 !important; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; font-size:11px; line-height:16px; padding:1px 0px 1px 5px !important; color:black; font-weight:bold; border:1px solid #aaa !important; border-right-color:#666 !important; border-bottom-color:#666 !important; border-right-width:2px !important; border-bottom-width:2px !important; }

	/* Post modifications */
	.bfb_reply_link:before { content:" · "; }
	.bfb_floating_comment { position:absolute !important; width:400px !important; z-index:999999 !important; border:1px solid #999 !important; -moz-box-shadow:5px 5px 5px #999; -webkit-box-shadow:5px 5px 5px #999;}
	.bfb_reply_active_comment { border:1px solid #999; }
	.bfb_reply_commented .bfb_reply_link { padding-right:14px; background:transparent url("data:image/gif,GIF89a%0C%00%0C%00%91%03%00%7B%D6z%00f%00%00%99%00%00%00%00!%F9%04%01%00%00%03%00%2C%00%00%00%00%0C%00%0C%00%00%02%1D%9C%8F%A9%23%7B%02%DA%82%22%CCh%99d%D8%04%10q%15%12P%5DR%9EJ%999%AD%E3%14%00%3B") no-repeat right center; }
	.bfb_reply_note { font-size:9px; color:#666; }
	
	/* Post Actions */
	.bfb_post_action_container { opacity:.5; display:block; position:absolute; z-index:14; top:0px; right:30px; padding:0; background-color:white; }
	.bfb_post_action_container:hover { opacity:1;  }
	.uiUnifiedStory:hover .bfb_post_action_container, .mall_post:hover .bfb_post_action_container { display:block; }
	.bfb_post_action { background:transparent url("data:image/gif,GIF89aZ%00%1E%00%B3%00%00%D1%00%00%98%AD%CB%E4%E6%E9%D7%D9%DC%A5%B5%D0%D7%D9%DD%C0%C5%D0%D6%D8%DC%D8%DA%DE%C6%CB%D2%D8%D9%DD%AD%BD%D6e%84%B2%FF%FF%FF%00%00%00%00%00%00!%F9%04%00%00%00%00%00%2C%00%00%00%00Z%00%1E%00%03%04%FF%B0%C9I%AB%BD8%EB%CD%BB%FF%D7%22%8E%D4h%9A%D6p%16%60%EB%96%A7(-%1B%3D%8DB%23%90X%EC%C9%1C%A0%25%06%A4%F1%1A%24%1B%12%A7C%0Dm%C2Z%B4%17%3D%CD%9CP%19%CF%A6%22%8E%0C%CFk%E7%98!%FB%96%DB%9B%13y%C5%09vk%B5X%AA%2CO%CFV%B6%BA%9Ee%C2%C9%7Bu%25%7B%3D%13%0C%0C6%87mT3%81J%7D%229%7FSr%8C%800H%87%0C%0D%9A%8B!P%8Bih%91Mq%81T%970%23%9A%8Am%5BXh%84%90%0B%92%26%04aK%A8A%40%9D%8E%B3%8D%1A6%0A%26%B5%23%09%15Ue%3F%12%AC%9B%AEEkGy%AEo%93%B8%B9%2F%16%9D%BDx%A6EvD%A8%94%D9%9C%CE%E5%CF%5Ea%82%15%07'%08%E4%F0%F1%AA%F2%1C%01%CD%F7%87%01%F6%F8%CD%FA%FC%FD%FB%FE%E5%0B(%D0%9F%C0%7C%07%13*4g%A8W%06%7C'%16J%9Cx%10%83%A2%8A%ACV%1D%D2%88O%9BBf%09%C8A%DE%B3%B8%C9%9C%C3%92%1B9%9A%E8x%AE%5CH%91%FF%1A%B6%AA%D4%B0%25%A7%9A%9A%BCpd%05%12fL%9F%2C%5D2%9C%83s%A6%C8r%11S%EEl%C5%B4%22%D0%91%3E%AF%F5%E4%09%13%E9J%A5%22%82%0A%E5y%B2%A3%26%00%00%CA%81%9D%99%EE%9C%C3%A3X%17%E4%BC%0A%F5%A7I~%CC%1A%80%05%C0%60.%D9pfM%16M%8A%88-%D5%A7C%05V%98%3B%D6(%D1%A92%0DYU9%82%40%5Bgp%01%FF%3Dd%F7%EC%E1%BC1%D7f%C5%FA%F8%22%DC%85b%09%5B%C6%96%F8(%85%8C%8C7S%EDE%F1%9F%DD%CAR%B7N%E5%A73%B2%CC%D6%F7%0A%D7%A5%3B%94%E4%EA%AD%F7%F8R%24%F8%CF%E0A%E3%05%89%DFf%80%BC8q~%01%22%00%00%3B") no-repeat 0 0; }
	.bfb_post_action { text-align:center; float:right; width:15px; display:inline; height:15px; margin:0px 2px; cursor:pointer; }
	.bfb_post_action_read { background-position:0 0; }
	.bfb_post_action_read:hover { background-position:0 -15px; }
	.bfb_post_action_unread { display:none; background-position:-15px 0; }
	.bfb_read .bfb_post_action_unread { display:block; }
	.bfb_post_action_unread:hover { background-position:-15px -15px; }
	.bfb_post_action_mute { background-position:-45px 0; }
	.bfb_post_action_mute:hover { background-position:-45px -15px; }
	.bfb_post_action_add { background-position:-30px 0; }
	.bfb_post_action_add:hover { background-position:-30px -15px; }
	.bfb_post_action_info { background-position:-60px 0; }
	.bfb_post_action_info:hover { background-position:-60px -15px; }
	.bfb_post_action_google { background-position:-75px 0; }
	.bfb_post_action_google:hover { background-position:-75px -15px; }

	/* Help Popup */
	.bfb_help, #bfb_button_help { background:transparent url("data:image/gif,GIF89a%10%00%10%00%F7%00%00%00%FF%00%10J%B5%10R%B5%10R%C6%10R%D6%10Z%D6!R%C6!Z%B5!Z%C6!Z%E7!c%F7!k%F7!k%FF1Z%8C1k%FF1s%FF9Z%8CBs%A5Bs%FFB%7B%F7B%7B%FFJk%94J%84%D6Rk%94Rs%9CR%7B%C6R%84%D6R%84%E7R%84%F7R%84%FFR%8C%D6R%8C%F7R%8C%FFZ%84%9CZ%8C%D6c%8C%C6c%8C%D6c%94%C6c%94%F7c%94%FFk%84%ADk%9C%D6s%8C%9Cs%94%ADs%94%B5s%94%F7s%9C%C6s%9C%D6s%9C%F7s%9C%FFs%A5%E7%7B%94%94%7B%9C%AD%7B%A5%D6%84%A5%D6%84%AD%D6%84%AD%E7%84%AD%FF%8C%B5%E7%94%9C%9C%94%9C%A5%94%AD%BD%94%AD%C6%94%AD%E7%94%AD%F7%94%B5%FF%A5%BD%CE%A5%BD%D6%A5%BD%DE%A5%BD%E7%A5%BD%F7%A5%BD%FF%A5%C6%FF%AD%C6%DE%B5%C6%D6%B5%C6%F7%B5%CE%E7%B5%CE%F7%B5%CE%FF%BD%BD%BD%BD%C6%C6%BD%C6%CE%C6%CE%D6%C6%CE%E7%C6%D6%DE%C6%D6%F7%C6%D6%FF%C6%DE%F7%CE%DE%E7%DE%DE%E7%E7%EF%F7%E7%F7%F7%E7%F7%FF%F7%F7%F7%F7%F7%FF%F7%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF!%F9%04%01%00%00%00%00%2C%00%00%00%00%10%00%10%00%00%08%BD%00%01%08%1CH%B0%A0A%00%3Aj%A4%B0qp%60%8D*%5B%C0%80%F1%C2%C4%C5A%22%5B%AC%E4%E8%D0!G%15-7%0A%D6%D8rDB%10%2F%60%B8%9C0%A2e%04%C1*N(%C4%00%83%E4%04%12%2F%13%8A%24%19%F8bK%0E%09%1D%828X%D0%02%CC%06%12%5BB%08%14%01%A6%83%83%A7%0ALl%A9b%E0%00%18%08%02-%80%91%E0%40A%82%0F%60%8A%20%08%60%15%2B%00%0F%5E%60%24X%8B%03%0C%81%00%022h%B90%B0%0A%93%04%03%08h%C0%11%A0%EF%10%25%04%5Dh%E1%3B%E0%07%98%BE%82Q%14%C4%A1%A5H%06%04%07%2C%10%C9%C2%E2%E0%88%24Z%24j%91%B2%A2%A1%C0%08%10.%60%F0Lz%60%40%00%00%3B") no-repeat left center; }
	#bfb_options_body .bfb_help { cursor:pointer; display:inline; float:right; width:16px; height:16px; }
	.bfb_helptext { display:none; z-index:99999; position:absolute; max-width:500px; padding:3px 15px 3px 3px; font-size:13px; -moz-border-radius:5px; border-radius:5px; -moz-border-radius:5px; background-color:white; border:2px solid #880000; -moz-box-shadow:5px 5px 5px #999; -webkit-box-shadow:5px 5px 5px #999; }
	#bfb_button_help input { padding-left:20px; }
	.bfb_help_wrapper { z-index:9999; width:700px; height:600px; position:fixed; top:25px; left:25px; border:5px solid #D8DFEA; -moz-border-radius:15px; -webkit-border-radius:15px; border-radius:15px; background-color:#F7F7F7; padding:15px 0; -moz-box-shadow:5px 5px 5px #999; -webkit-box-shadow:5px 5px 5px #999; }
	.bfb_help_wrapper iframe { width:680px; height:550px; border:none; }
	#bfb_help_close { float:right; margin:25px 50px 0 0;  }

	/* Position of Facebook's "close" X */
	.bfb_processed .hideSelector, .bfb_processed .hideButton { margin-top:-10px; }
	.profile .bfb_processed .hideSelector, .bfb_processed .hideButton { margin-top:-6px; }
	.UIRecentActivityStory .hideSelector, .UIRecentActivityStory .hideButton ,
	.uiStreamMinistory .hideSelector, .uiStreamMinistory .hideButton, 
	.UIRecentActivityStory .hideSelector, .UIRecentActivityStory .hideButton
		{ margin-top:-1px; }

	/* Data-loading iframe */
	.bfb_iframe { position:absolute; height:200px; width:200px; z-index:-5000; visibility:hidden; }

	/* Options Display */
	.GM_options_wrapper { display:none; position:absolute; top:25px; left:25px; background-color:transparent; z-index:5000;}
	.GM_options_wrapper_inner { width:800px; background-color:white; border:8px solid #3B5998; -moz-border-radius: 15px; -webkit-border-radius: 15px; border-radius: 15px; padding:10px; z-index:5001; font-size:110%; -moz-box-shadow:10px 10px 10px #999; -webkit-box-shadow:10px 10px 10px #999; }
	.GM_options_wrapper h2 { font-size:14px; background-color:#3B5998; color:white; font-weight:bold; font-style:italic; padding:1px 10px; margin:0px; }
	.GM_options_header { background-color:white; color:#3B5998; min-height:55px; }
	.GM_options_header a { color:#3B5998; }
	.GM_options_message { clear:both; background-color:yellow; padding:10px; border:1px solid black; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; margin:10px; font-weight:bold; font-size:larger; }
	.GM_options_wrapper table.GM_options { border:1px solid #999; border-collapse:collapse; width:100%; }
	.GM_options_wrapper td.label, .GM_options_wrapper td.input, .GM_options_wrapper td.html  { border:1px solid #999; margin:0px; padding:0px; }
	.GM_options_wrapper td.label { padding:0px 5px; }
	.GM_options_buttons { float:right; width:200px; height:50px; vertical-align:middle; text-align:center; }
	.GM_options_buttons input { background-color:#3B5998; color:white; font-size:24px; font-weight:bold; }
	#bfb_options_body { clear:both; border:1px solid #3B5998;padding:5px;min-height:200px;overflow:auto;background-color:#f6f6f6;}
	.bfb_option_body {display:none;}
	.bfb_option_body > div { padding:1px 2px; font-size:12px; border-top:1px solid #ddd; }
	.bfb_option_body > div:hover { background-color:#FEE9BE !important; }
	.bfb_option_body > div.no_hover:hover { background-color:inherit !important; }
	.bfb_option_body > div:nth-child(even) { background-color:#fcfcfc; }
	.bfb_option_body > div > div { margin-left:30px; }
	.bfb_option_body input[type=checkbox] { width:12px; height:12px; } 
	#bfb_tracelog, #bfb_user_prefs { font-family:courier new; font-size:12px; height:300px;overflow:auto;border:1px solid #ccc;background-color:white; }
	#bfb_user_prefs { width:600px; white-space:pre; }
	select.bfb_disabled { background-color:#eee; color:#ccc; }
	.bfb_options_minimized .bfb_options_minimized_hide { display:none; }
	.bfb_options_minimized { width:auto !important; }
	.bfb_sub_option { margin-left:15px; }
	
	.bfb_featured_option { border:2px solid #3B5998;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:2px;background-color:white;width:90px;text-align:center;float:left;height:150px; margin:5px 3px !important; }
	.bfb_featured_option:hover { border-color:#880000; cursor:pointer; }
	.bfb_featured_option .desc { text-align:left; font-size:11px; border-top:1px solid #333; }
	.bfb_options_simple_mode .bfb_option_advanced { display:none; }

	/* Tabs */
	.bfb_tabs { padding-left:4px; }
	.bfb_tabs > * {line-height:24px;float:left;font-family:arial;background-color:#3B5998;color:#ddd;border:1px solid #EDEFF4;border-bottom-color:#3B5998;-moz-border-radius-topleft:8px;-moz-border-radius-topright:8px;-webkit-border-top-left-radius:8px;-webkit-border-top-right-radius:8px;border-top-left-radius:8px;border-top-right-radius:8px;padding:0px 10px 0px 6px;margin-left:-4px;z-index:1;cursor:pointer;}
	.bfb_tabs > .bfb_tab_selected + * {margin-left:0px;}
	.bfb_tabs > .bfb_tab_selected {display:block !important;position:relative;top:1px;background-color:#f6f6f6;color:#3B5998;border-color:#3B5998;border-bottom:none;border-top:2px solid #3B5998;z-index:2;padding-right:10px;font-weight:bold;}

	/* Feed Tabs */
	#bfb_feed_tabs .bfb_tab { font-size:110%; }
	#bfb_feed_tabs .bfb_tab_selected { background-color:white; }
	.bfb_stream { border-top:1px solid #ccc; clear:both; display:none; }
	.bfb_tab_body_selected { display:block; }
	.bfb_tab_count { margin-left:8px; }
	.bfb_tab_count .new { margin-right:1px; font-weight:bold; }
	.bfb_tab_count .total { margin-left:1px; }
	.bfb_tab_empty { background-color:#ddd; color:#aaa; font-style:italic; border:1px solid #aaa; }
	.bfb_tab .bfb_tab_close { display:none; float:right; position:relative; margin-left:-5px; top:5px; left:9px; cursor:pointer; width:11px; height:11px; background:transparent url("data:image/gif,GIF89a%0B%00%0B%00%91%00%00%00%00%00%FF%FF%FF%9C%9A%9C%FF%FF%FF!%F9%04%01%00%00%03%00%2C%00%00%00%00%0B%00%0B%00%00%02%18%94%8F6%CB%AC%BA%9E%18%87%CA%88%B0%83%16%D7%5E%85%13w5M%82%0A%05%00%3B") no-repeat left center; }
	.bfb_tab_selected .bfb_tab_close { display:block; }
	.bfb_tab .bfb_tab_close:hover { -moz-box-shadow:0 0 4px red; -webkit-box-shadow:0 0 4px red; box-shadow:0 0 4px red; }

	/* Dialog */
	.bfb_dialog { position:fixed; background-color:#FFFDEA; width:600px; top:50px; left:10px; z-index:9999; padding:5px; 
					font-family:arial; font-size:14px; -moz-box-shadow:12px 12px 15px #666; -webkit-box-shadow:5px 5px 5px #999;
					border:4px solid #F4D307; -moz-border-radius:8px; -webkit-border-radius: 8px; border-radius: 8px; }
	.bfb_dialog_header { font-size:16px; font-weight:bold; }
	.bfb_dialog_content { margin:5px 10px 0px 10px; }
	.bfb_dialog_footer { margin:15px 0px; text-align:center; }
	.bfb_dialog_footer .UIButton_better_fb { padding:5px !important; }

	/* Mini "x" icon to close */
	.better_fb_mini_message, .mini_x { background-image:url("data:image/gif,GIF89a%0B%00%0D%00%F7%00%00%9C%9A%9C%FC%FE%FC%00%00%12%00%00%00%60%94%00%23%E9%D0%00%12%FD%00%00%7F)%00%80!%D0%EA%00%FD%12%00%7F%00%00J%04%00%F8%26%15A%83%00~%7C%12%00J%00%00%F8%00%00A%00%00~%00%00%00%02%00%00%00%00%00%00%00%00%00%94%00%03%E9%00%00%12%00%00%00%00%D8%FC%98%E8%05%EA%12%07%12%00%00%00%F9%F6%11%E5%05%01%81%07%00%7C%00%00%00%98%90%00%E9%EA%01%12%7D%00%00%00VJ%AC%00%F8%EA%00A%12%00~%00%E0%00%BE%E7%00c%12%00E%00%00~n%00%00%00%00%00%00%00%0C%00%00%00%00%B0%00%E9%E9%00%12%12%00%00%00%00%20%00%98%E9%00%EA%90%00%12%7C%00%00%60%00%FC%00%D0%84%91%FDA%7C%7F~%FF%C4%A4%FF%E9%85%FF%12A%FF%00~%5D%BE%0E%00c%06%91E%09%7C~%00%95%00%01%E7%00%00%81%0C%00%7C%00%00%00%00%87%00%00%F7%15%00A%00%00~%60%B0%3B%03%E9%04%00%12%D4%00%00%00%10%1AX%BE%7C%D6%1A%80A%00%18~8%00%E4_%00%EA%15%00%12%00%00%00%00%FC%87%00%05%C4%00%07A%00%00~~%00%93%00%00%C4%00%00A%C0%03~%00%11%87%00%01%F7%00%00A%00%00~%FF%F6%3B%FF%05%04%FF%07%D4%FF%00%00%FF%ECX%FF%E9%D6%FF%12A%FF%00~%00%0C%01%00%B5%00%00A%00%00~%00%00%90%BC%00%EA%EA%00%7D%12%00%00%00%00%11%00%00%01%00%15%00%00%00%00%00%A8%00p%FD%00%9E%00%00%80%00%03%7C%10%1C%00%E9%B5%00%12A%00%00~%00%AF%00%00%EB%00%00%81%00%00%7C%00%00Z%00%07%E3%00%00%81%00%00%7C%00%00%40%00%00%B9%00%00P%00%00%00%00%008%00%00_%00%40%01%00%15%00%00%00lD%00%00%EA%00%00%12%00%00%00%00L%A8%00%E8%FD%00%12%00%00%00%00%004(%00%00%EA%00%00%12%00%C0%00%00%AC%CD%00%FB%2B%00%12%83%00%00%7C%00%20%00x%E9%00%9E%90%00%80%7C%00%7C%60%00%FF%00%00%FF%91%00%FF%7C%00%FF%FF%00p%FF%00%9E%FF%00%80%FF%00%7C%5D%00%3D%00%01%00%91%00%00%7C%00%00Z1%3D%F4%2C%00%80%83%00%7C%7C%00%00L%FC%00%EA%F0%15%12%12%00%00%00%00%0C%FF%00%2C%FF%00%83%FF%00%7C%FF8%00%00_%00%00%15%00%00%00%00%00%00%18T%01%00%EB%00%00%12%00%00%00%00%7CF%00d%83%00%83L%00%7C%00g%004%F4%00%EB%80%00%12%7C%00%008Pw%EA%EBP%12%12O%00%00%008%B5h_d%EB%15%83%12%00%7C%00%00%D4%7C%00ld%0CO%83%00%00%7C%00%E0%25%00w%ED%00O%12%00%00%00%B0%00%C1%E9%01%FF%12%00%FF%00%00%7F%7CL%E8%E9%EA%EC%12%12%12%00%00%00%86%00%00%7D%01%00%80%00%00%18%00%00%CB%D0%7C%00dd%05%83%83%00%7C%7C%00%01%00%00%00%00%00%00%00%00%00%00%00%00%A8%00%00%FD%00%00%00%00%00%00%B0%00p%E9%00H%12%00%15%00%00%00%00%00%01%D0%00-%FD%00H%7F%00%00!%F9%04%00%00%00%00%00%2C%00%00%00%00%0B%00%0D%00%07%08)%00%03%08%1CH%B0%A0%C1%83%07%01%00%18%A8%90%A0%C2%85%0F%0B%3Elh0b%C5%89%12%1BZ%14H1%40G%84%20C%16%0C%08%00%3B"); }
	.better_fb_mini_message:hover, .mini_x:hover { background-image:url("data:image/gif,GIF89a%0B%00%0D%00%F7%00%00%3CZ%9C%FC%FE%FC%00%00%12%00%00%00%60%94%00%23%E9%D0%00%12%FD%00%00%7F!%00%80!%D0%EA%00%FD%12%00%7F%00%00J%04%00%F8%26%15A%83%00~%7C%12%00J%00%00%F8%00%00A%00%00~%00%00%00%02%00%00%00%00%00%00%00%00%00%94%00%03%E9%00%00%12%00%00%00%00%D8%DE%98%E8%06%EA%12%0F%12%00%00%00%F9%A2%11%E5%07%01%81%18%00%7C%00%00%00%98%B8%00%E9%DF%01%12%81%00%00%00VJ%AC%00%F8%EA%00A%12%00~%00%E0%00%BE%E7%00c%12%00E%00%00~n%00%00%00%00%00%00%00%0C%00%00%00%00%B0%00%E9%E9%00%12%12%00%00%00%00%20%00%98%E9%00%EA%90%00%12%7C%00%00%60%00%FC%00%D0%84%91%FDA%7C%7F~%FF%C4%A4%FF%E9%85%FF%12A%FF%00~%5D%BE%AE%00c%07%91E%0E%7C~%00%95%00%01%E7%00%00%81%0C%00%7C%00%00%00%00%87%00%00%F7%15%00A%00%00~%60%B0%0F%03%E9%08%00%12%24%00%00%00%40%1AX2%7C%D6!%80A%00%18~8%00%E4_%00%EA%15%00%12%00%00%00%00%DE%87%00%06%C4%00%0FA%00%00~~%00%93%00%00%C4%00%00A%C0%03~%00%11%87%00%01%F7%00%00A%00%00~%FF%A2%0F%FF%07%08%FF%18%24%FF%00%00%FF%ECX%FF%E9%D6%FF%12A%FF%00~%00%0C%01%00%B5%00%00A%00%00~%00%00%B8%BC%00%DF%EA%00%81%12%00%00%00%00%11%00%00%01%00%15%00%00%00%00%00%24%00p%7D%00%9E%00%00%80%00%03%7C%10%1C%00%E9%B5%00%12A%00%00~%00%AF%00%00%EB%00%00%81%00%00%7C%00%00Z%00%07%E3%00%00%81%00%00%7C%00%00%40%00%00%B9%00%00P%00%00%00%00%008%00%00_%00%40%01%00%15%00%00%00lD%00%00%EA%00%00%12%00%00%00%00L%24%00%E8%7D%00%12%00%00%00%00%004(%00%00%EA%00%00%12%00%C0%00%00%AC%CD%00%FB%2B%00%12%83%00%00%7C%00%20%00x%E9%00%9E%90%00%80%7C%00%7C%60%00%FF%00%00%FF%91%00%FF%7C%00%FF%FF%00p%FF%00%9E%FF%00%80%FF%00%7C%5D%00%3B%00%01%00%91%00%00%7C%00%00Z1%3B%F4%2C%00%80%83%00%7C%7C%00%00L%FC%00%EA%F0%15%12%12%00%00%00%00%0C%FF%00%2C%FF%00%83%FF%00%7C%FF8%00%00_%00%00%15%00%00%00%00%00%00%18T%01%00%EB%00%00%12%00%00%00%00%7CF%00d%83%00%83L%00%7C%00g%004%F4%00%EB%80%00%12%7C%00%008Pw%EA%EBP%12%12O%00%00%008%B5h_d%EB%15%83%12%00%7C%00%00%D4%7C%00ld%0CO%83%00%00%7C%00%E0%23%00w%ED%00O%12%00%00%00%B0%00%C3%E9%01%FF%12%00%FF%00%00%7F%7CL%E8%E9%EA%EC%12%12%12%00%00%00%86%00%00%7D%01%00%80%00%00%18%00%00%D9%D0%7C%00dd%06%83%83%00%7C%7C%00%01%00%00%00%00%00%00%00%00%00%00%00%00%24%00%00%7D%00%00%00%00%00%00%B0%00p%E9%00H%12%00%15%00%00%00%00%00%01%D0%00-%FD%00H%7F%00%00!%F9%04%00%00%00%00%00%2C%00%00%00%00%0B%00%0D%00%07%08)%00%01%08%1CH%B0%A0%C1%83%07%03%04%18%A8%90%A0%C2%85%0F%0B%3Elh0b%C5%89%12%1BZ%14H%11%40G%84%20C%16%0C%08%00%3B"); }
	.better_fb_mini_message, .mini_x {  background-repeat:no-repeat; background-position:top right; cursor:pointer; }

	/* Messages, Tips */
	.better_fb_mini_message { padding:1px 10px 1px 1px; background-color:#FFFDEA; font-family:arial; font-size:10px;font-weight:bold; margin:1px; border:2px solid #F4D307; -moz-border-radius:3px; -webkit-border-radius: 3px; border-radius: 3px; }
	.better_fb_message { clear:both; background-image:url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%23%00%00%00%23%08%02%00%00%00%91%BB%24%0E%00%00%00%06tRNS%00%00%00%00%00%00n%A6%07%91%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%06.IDATx%DA%E5%97%5Dl%DB%D6%15%C7%FF%A4%24J%B2d%C9%96%AA%C5%8A%12%3B%8E%5D%E7s%C1%92eu%8B%A4S%8B%C6Y%DD%06%CD%87%8B%3C%04%5B%83%3E5%D8V%EC%E3%A1%F0C%91%01%1D0l%E8%B0%97%14%E9%8A%AC%40%1E%16%17k%96%B5%CD%86%B9M%D6%C0%CE%9C%CD%AE%5D'UmGql%CB%B2%ADY%1F%96%25J%A4H%5E%92%F7%EEAN%90%D5%5Em%A7%C1%5E%F6%7F%22.%0F%CF%8F%FF%83s%EF!%81%FF%95%B8%95%87%8E%0Fv%C5%23%03%F3%B3%09R%92%84%0A%B7%CB%5B%B9%A6~%7B%C3%EE%C7%BD%81%E0%83!%A9R%F1%FAG%E7%BA%3B%CE%24%A2%11%00N%B7%DDQa'%84W%8A%25j%12O%20%B4%F3%3B%87%F7%1E%FBAM%5D%E3W%22M%0D%F5w%FC%ECD%22%1A%F1%04B%E1%A3%5B%EAv%B4%F8BM%8E%0A%AF%AE%5Bsi-%1D%8B%96%DF%C0%13%08%1Dx%B9%FD%B1%B6%13%F7Y%D9%A1%AE%3F%B7%EF%09%BC%D2%EC%EE%3C%7DRM%7F%C8%A8%C8%BE%20*S%7D%F8%9F%17~%FB%FAa%DF%8Fv%B8%3AO%9F%BC%1F%CCd%A4%B7%7DO%E0%E4%93%FE%5B%3D%BF%A1%FA03%A6%18%15%19%95%17%C1DF%C5%5C%E2%FC%A9%176%BC%BC%CDv%E5%EC%AFW%87Q%A5%E2%2F%DB%BE%F9J%B3%FBVw%3BcW%A8%DA%C7%CC4%A32c%84-!%C2%A8H%E6%DEx%FD%B0%AF%7DO%602%D2%BBdN~%C9%D5%7F%FC%F1%ADD4%B2%EF%F8%E3%0F7%D71%0D%9C%B5%DC%5D%06%00%40%FFb4%D3%01%D8%7C%DF%7B%FE%C7%B5J%B1%F4%D73%BFX)I%16%E7%BB%3B%DE%AEm%AA%7Cl_%08%E6%3A%C0%C5%18%01S%EF%26%BD%03%BB%07%C94%00u%CD%2F%3D%F247%DA%D35%3E%D8%B5%22R%EC%FA51%93%D8%FC%A8%C7%B5%A6%1A%00%A0%01%1Ac%04L%03%8CE%B0%3B%3C*r%F6M%FB%9F%A9d%A6y%FD%A3%0F%16%A7%B5.%5E%9A%1E%E9%07%B0%F9%EB%B5%8CV%82%8A%1C%00%D8a%C1%82-%0E%60%E5%0Db%BB%E3%D2(%DFb%1A%7C%5B%D6z%FDdl%E0%EA%8A%3C%E5fg%3DU%B6%AAj%C1%24%C4%D4%F2%8C%8A%80%0C%AA-%D4%B0%EC%0C%06%98%B2%E0%8F%8A%8C%11%C6%8A0e%00k%B7%98J%B1%24ff%97%F7%94%CF%A7%EET_%E4%E1%06%AA%60%CA%B0XA%C1x%CF%7Fnu%0D%00c%C4%24%BC%C5%22%19J%DC%02T%BA%8DIyN)%C9%CB%93%9C%82%BB%7CA%F23B%B5%97%D7f%60%07%07%C0%02P0%DE%0EF8N%00%E7%00g%07%E7%A4%B4%1A%98%26%85%9C%60%8FC%89%14%25%97%C5%E6rV%B8%96%AF%5E%E5Ck%D4%92%96%CF%11%00T%8DQSZ%A8%A1)%82%E5aJ%00%C0%FB%C1%07%00%2Bh%9E%91iUJ%F0%FC%18S%AFh%12W%9C%E5%2B%FD~%AB%60_%DES%A8i%93%A6%B0%B9X%3A%B8%D1o(%25%2Bb%BC%03L%93%60%07g%0Dq%B6%06%00%A0Yf%0C%C1LS%26%98%25%86%92%88%8A%24G%22b%9E%CF%A6-%B5%BBB.%AFoyR%FD%EE%7D%CE%CA%8A%81%3E%B5qW%D1%EAp%00%25%A6%25y%A1%CE%EE%080%3D%C3%1B%09F%C5%BB%C1T%CB%EBr%80%EA%19*%9D%85%80%DB%83%D5J%B1%B8%F3%89gp%EA%E2%F2%D5%AB%A9k%DC%F4h%CB%F8%E7%F3c%833%86%AA%EA%8An%C8I%AD%A0%15%26%FE%AE%CD%7DbH%7D0%26%60L%98%A5%A8)%F7%E9R%8E%EA%19*%7F%C8HZ%93%B8%1B%7D%8E%AA%9A%DA%AD%DF%3E%B8%A2%FD%04%E0%A9%17%7Fr%B3%E7b%CF%DF%D2%EBjy%C1%E9%B4%BA(%EF%00%91*L%E5!%00%8Ejb%B3%2B%0B%9E%88%22O%8D%D8%5D%098%F0%AF%09%F7%F4%AD%B9-%7B%9F%5Br6.%7D%EE%D5n%FF%D6%93%C7%7F%3A3%AE%BD%7F%BED%14E%2F%E8%24%3Bk%B5%DE%06%1D%D5%8B%B9%E2%94%AC%CC%8B%864D%B2%97%D5%EC%A4%C5n%02%D0%95*1c'%84%AFih%5C%C5%09%0B%A0%F5%FB%AF5%1F%3C6%FAi%E2%FD%F3%A5B%862%BD%A8%CE%17uq%9Ci%FDR%F2%B3%B9%1BS%E9%D1%92V%B0%94%83%0D%A9%A4%15%2C%B2%CC%98i%DA%2B%3C%AB%23%018%F6%F33%E1%EF%FEp%ECF%E6%F7o%A7%AEu%99rN%E0%99%0D%80%D5%A53%9BA%92%AE%DCL55%7C%00%88j1%95J%2B%AA%BE%24%9B%E5%CB%07%D5%BB%1F%F7%BEy%F6%DC%D4%CD%E1%E1%BE%C9%A1%88nR%A1%AE%C1i%B5p%16%81%A3%84S%E7%AC%BCi%DA%BC.%0BW%D4%09-%88l%F8%86l%04%B7uv%F5%AC%B4%23%EE%D5%AE%D6%A3%00%06%3B%DF%BD%F4%BB_%5D%ED%8C%025%7B%5B%AA%04%1B%84%F50U%B3%98%CC%DB%D7%04e%E2%8A%8Ed%13%F1%FC%07b%20%3C%99%5E2%8Fu%85SxW%EBQ13%7B%EE%B5%97%AEv~%2C%F8%CCmM%B6%E1Q%3D%11%CF%EF%0D%85%B4%D4lLtM%CF%ECp%EC%3E%B4%7D%EABwww2%3E%B6%F8S%C9%BA%F2%91%EF%0D%04%C5%CC%EC%9B'%0E%5C%BB8%F5%07w%AE%BC%A8K%F2%E4%CD%60%D6%16%DC%DF%D2r%E8%E0s%C9Tjh%24z%E1%2F%97%EE%DF%D3%5DXG%C7%3Bo%BD%FA%EA%F6%AD%8Fl%DA%BC%15%40%CA%E9%0AVy%B7U%7BUU%B95z%7BC%DD%06%00%FD%03%03%AB%EB%BD%25%F5l%CB%13%A1u%EBs%85%85%A1%A0*r%3E%2F%26S%A9d*%95H%24%3C%1E%CF%7F%7Bp%D5%24o%20%D8%D8%B0113%0D%C0%E7%F7%F9%FC%BE%60%CD%D7%BC%1E%AF%208%E2%F1xo_%3F%80%A6%A6%87%1F%00%09%C0%FE%96%16%00%BD%9F%F4%CFg%E7%E7%B3%F3%B1X%2C%16%8B%01p%3A%1D%9F%5D%EF%07%D0%FAt%EB%83!%B5%1D9%14%0E%87%133%D3s%D9%AC%CF%EF%AB%09%AE%AD%AF%AF'D%7D%EFO%17%86F%A2mG%8E%EC%DC%F9%8D%AF%F4%AFq%AF%E6%B2%D9%17%8F%BF04%12%05%10Z%B7%BE%5CL%00%E1p%F8%F4%1B%A7*%5C%AE%07F*%AB%A3%E3%9DK%97%2F%8F%8DO%00hl%D8%F8%7C%5B%DB%81%03%CF%E2%FFH%FF%06%DB%01b%5BR%10nj%00%00%00%00IEND%AEB%60%82"); min-height:40px; background-repeat:no-repeat; background-position:-4px 0px; background-color:#FFFDEA; padding:2px; font-family:arial; font-size:12px; margin:2px; border:2px solid #F4D307; -moz-border-radius:8px; -webkit-border-radius: 8px; border-radius: 8px; }
	.better_fb_message a { text-decoration:underline; }
	.better_fb_bulb_spacer { float:left; width:32px; height:30px; }
	.better_fb_close { background-color:#3B5998; color:white; border:3px solid white; border-color:#ddd #999 #999 #ddd; text-align:center; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; font-size:16px; cursor:pointer; margin:5px 10px; padding:5px 20px; }
	.better_fb_close:hover { background-color:white; color:#3B5998; }
	.bfb_close_wrap { clear:both; text-align:center; line-height:32px; }
	.bfb_update { background:none repeat scroll 0 0 #FFF8CC; border-bottom:1px solid #FFE222; color:#000000; padding:0 0 1px; font-size:11px; margin:1px 0px 10px 5px; }
	.bfb_h4 { margin-top:7px;}

	/* "Sticky" note */
	.bfb_sticky_note {
	  position:absolute;
	  min-height:14px;
	  min-width:100px;
	  right:100%;
	  margin-right:8px;
	  top:50%;
	  font-family:arial;
	  background-color:#ffa;
	  color:black;
	  border:1px solid #666666;
	  font-size:12px;
	  padding:3px;
	  text-align:center;
	  border-radius:6px;-moz-border-radius:6px;-webkit-border-radius:6px;
	  box-shadow:0 0 5px #888888;-moz-box-shadow:0 0 5px #888888;-webkit-box-shadow:0 0 5px #888888;
	  z-index:999999;
	}
	.bfb_sticky_note_right {left:100%;right:auto;margin-left:8px;margin-right:auto;}

	.bfb_sticky_note_arrow_border {
	  border-color: transparent transparent transparent #666666;
	  border-style: solid;
	  border-width: 7px;
	  height:0; width:0;
	  position:absolute;
	  margin-top:-7px;
	  top:50%;
	  right:-15px;
	}
	.bfb_sticky_note_right .bfb_sticky_note_arrow_border {border-color: transparent #666666 transparent transparent;top:50%;right:auto;left:-15px;}

	.bfb_sticky_note_arrow {
	  border-color: transparent transparent transparent #ffa;
	  border-style: solid;
	  border-width: 7px;
	  height:0; width:0;
	  position:absolute;
	  top:50%;
	  right:-13px;
	  margin-top:-7px;
	}
	.bfb_sticky_note_right .bfb_sticky_note_arrow {border-color: transparent #ffa transparent transparent;top:50%;right:auto;left:-13px;}

	.bfb_sticky_note_close {
		float:left;
		width:9px;
		height:9px;
		background-repeat:no-repeat; 
		background-position:center center; 
		cursor:pointer;
		background-image:url("data:image/gif,GIF89a%07%00%07%00%91%00%00%00%00%00%FF%FF%FF%9C%9A%9C%FF%FF%FF!%F9%04%01%00%00%03%00%2C%00%00%00%00%07%00%07%00%00%02%0C%94%86%A6%B3j%C8%5Er%F1%B83%0B%00%3B");
		border:1px solid transparent;
	}
	.bfb_sticky_note_right .bfb_sticky_note_close {float:right;}
	div.bfb_sticky_note_close:hover {
		background-image:url("data:image/gif,GIF89a%07%00%07%00%91%00%00%00%00%00%FF%FF%FF%FF%FF%FF%00%00%00!%F9%04%01%00%00%02%00%2C%00%00%00%00%07%00%07%00%00%02%0C%04%84%A6%B2j%C8%5Er%F1%B83%0B%00%3B");
		border:1px solid black;
	}
	
	#bfb_quickmessages { position:fixed; top:0px; right:0px; width:400px; z-index:99999; }
	.bfb_quickmessage { background-color:#FFF1A8; color:black; border:1px solid #ccc; padding:5px; font-size:13px; -moz-border-radius:4px; -webkit-border-radius:4px; border-radius:4px; }

	/* Character counter */
	.bfb_char_count { width:20px;height:12px;font-size:10px;background-color:#ccc;color:#000;float:right; margin-top:-8px;margin-right:-5px; text-align:center; }
	.bfb_char_count_warning { color:red; font-weight:bold; }
	.mentionsTextarea + .bfb_char_count { margin-top:-12px; position:relative; top:5px; }

	/* Pagelet styles */
	.pagelet_title { float:left; margin-right:5px; }
	.better_facebook_sidebar_section { width:244px !important; }
	.better_facebook_sidebar_section .mbm { margin-bottom:0px; }

	.uiSideNav .item.noimg { padding-left: 0px !important; }
	.uiHeaderNav { margin-top:2px !important; padding-top:2px !important;}
	.uiHeaderNav h4 { padding-bottom:2px !important; }
	ul.bfb_uiSideNav { border:1px solid #ccc; margin:6px 0px; padding:1px 0px; clear:both; }
	ul.bfb_uiSideNav li { width:auto; white-space:nowrap; }
	.bfb_network { padding: 1px 0px 1px 2px !important; left:0px !important; cursor:pointer; }
	.bfb_network .bfb_network_users a { font-weight:bold; padding-left:10px; }
	.bfb_network .bfb_network_users { background-color:#F7F7F7; }
	.bfb_friend_activity_img { float:left; margin-right:5px; clear:both; }

	.bfb_clear { clear:both; }
	.bfb_alt { background-color:#eee; }
	.bfb_sidebar_header_link { margin-left:6px; }
	.bfb_sidebar_close { border:1px solid transparent; padding:0px 2px; }
	.bfb_sidebar_close:hover { border:1px solid #627AAD; }

	#pagelet_better_fb_stickynote_pagelet { background-color:#FDFCC3; font-family:comic sans ms; font-size:12px; margin-bottom:10px; }
	#pagelet_better_fb_stickynote_pagelet .uiSideHeader { margin-bottom:2px; background-color:transparent; }
	#pagelet_better_fb_stickynote_pagelet .mbl { margin-bottom:0px; }

	/* Collapsable right pagelets */
	#rightCol .bfb_pagelet_closed * { margin-bottom:0; padding-bottom:0; margin-top:0; }
	#rightCol .bfb_pagelet_closed .phs { display:none; }
	#rightCol .bfb_sidebar_header_expand { font-size:10px; color:#aaa; cursor:pointer; }
	#rightCol .bfb_pagelet_closed .bfb_sidebar_header_expand { display:inline !important; }
	

	#rightCol .bfb_pagelet_closed .uiHeader { border-bottom: 1px solid #CCCCCC; margin-bottom:2px; }
	#rightCol .bfb_pagelet_closed .uiHeader .uiHeaderActions { display:none; }
	#rightCol .uiHeaderTitle { cursor:pointer; }
	#rightCol .bfb_pagelet_closed h4, #rightCol .bfb_pagelet_closed h3 { color:#ccc; }
	#rightCol .bfb_pagelet_closed.jewelFlyout > ul, #rightCol .bfb_pagelet_closed.jewelFlyout > .jewelFooter { display:none; }

	/* Notifications */
	
	.bfb_notif_preview { max-height:500px; max-width:500px; overflow:auto; position:absolute; z-index:9999; border:1px solid black; padding:2px; background-color:white; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; -moz-box-shadow:5px 5px 5px #999; -webkit-box-shadow:5px 5px 5px #999; }
	.bfb_notif_preview .uiUfiAddComment { display:none; }
	.bfb_notif_preview .hideButton { display:none; }
	.bfb_notif_preview_message { color:#aaa; background-color:#ffffe1; font-size:10px; padding:1px; }

	/* Debug */
	div.bfb_debug{ display:none; border:1px solid #ccc; background-color:#eee;color:#999; text-align:left; padding:3px 0px 3px 20px; clear:both; overflow:auto; max-height:250px; background-image: url("data:image/gif,GIF89a%10%00%10%00%E6%7F%00%B7%8A%2BrV%1A666%9B%9B%9B%B1%86)%F5%BCB%D6%A33%CE%9D1qqq7)%0C%FF%C6%3F)%1E%09%FD%C0%3C%F5%BA%3A%DC%B2V%03%03%02%1C%1C%1C%1C%15%07%09%09%09III%0E%0E%0D%11%11%11%12%0E%032%26%0B%FF%C2%3C%FC%BF%3C%FF%C3%3D%FF%C4%3D%F9%BD%3A%FF%C2%3D%FB%BE%3B%FC%BF%3BWWW%E5%E5%E5%F1%B79%86%86%86%FA%FA%FA%95%95%95%FF%CDR%FB%BF%3C*'%20%FF%C1%3BG%3E(%FF%C6A%E4%E4%E4%9Dw%24OOO%E2%AB4%FF%D2c%F8%C2O%CF%AAY%E9%B17%FB%BF%3B%F2%B89%17%17%17%60%60%60%B8%97O%FF%C8%40%FF%C9C%F8%BC%3AK%3D%1E%F3%C1X%84n%3F%FB%BE%3A%B7%B7%B7%C7%A1MJJJ%AB%8FRhhhbJ%16%E9%B6F%A5%A5%A5%FA%C8%5B%CC%9B%2F%93w8%E1%E1%E1%B3%8B4%B1%B1%B1%7B%5D%1C%80f-%A8%A8%A8%FA%C3E%8Dk!%2C!%0A6*%10%06%07%0A%0A%08%02%FE%C2%3C%AE%AE%AE%BC%8E%2C%D5%A6C%FF%C6%3D%FF%C3%3F%C6%96%2F%3B%3B%3B%EF%B58%DF%DF%DFggg%BE%99J%E7%AE6yb4%FF%CBA%98%98%98%C1%93-%7B%7B%7B%FF%C3961(%AA%83%2F%AE%85%2C%82k%3A5%2F%24%FA%BE%3B%FB%BE9%B5%B5%B5%FD%BF9222%DC%ABA%FE%C1%3C%CF%9E1%FF%C4BC%3A%24%22%22%22%96%96%96%17%16%11%A3%7C'%F9%BD%3B%00%00%00%FF%FF%FF!%F9%04%01%00%00%7F%00%2C%00%00%00%00%10%00%10%00%00%07%DE%80%7F%82%83s%14%15%5E%83%89%83%23~U*%3C%0F~%8A%89~n81%05%04%09~%03%93~j%0E90%26%5B%07%9B%8A%126AiHCk%0D%18g%16%10%83D%0F%3E%2BW%0E%0F%0F%5D%1A%0CR~%08%82%14(Fr%5C2~~%00%1A'%22%09%15%82~m%0A%1C%1D%BB%0F%07%1Do%18-%0F%7Fy%7BZ)%7D4%05T%0B_%19%7D%193%0B%02%12xQ%3F%7D%1CwbL%0C%7D%FC%0A%01%12%12%C8%E8%E0%D0%07N%0F%25ljx%E0%A7%81%00%05%09O%CA%2C%C4%40%C7O%02%11%EC%18%7C%00%B0G%C2%02%03%1F6l%D8%C1'K%86%3A%1D%1A%18%08%F0%00%81%1F%0BE%F8%24y%81a%C3%18%3B%04%9C%5Cx%00BP%BC%97%11%A6%5CX%10%C1%8A%1FZ%8A%D0%FCq1a%C2%1F%10a%12%05%02%00%3B"); background-repeat:no-repeat; background-position:left top; }
	div.bfb_debug pre { font-size:9px; }
	div.debug_small { display:none; border:1px solid #ccc; clear:both; background-color:#eee !important; }
	div.debug_small, div.debug_small * { color:#ccc !important; text-align:left; padding:0px; }
	.debug_window { position:absolute; top:45px; left:1px; border:1px solid black; width:350px; max-height:800px; overflow:auto; padding:3px; }
	body.debug .bfb_debug, body.debug .debug_small, .post_debug .bfb_debug { display:block !important; }
	body.debug .bfb_duplicate { display:block; background-color:yellow; }

	/* RPC */
	.bfb_rpc_iframe { position:absolute; visibility:hidden; top:-500px; left:-500px; width:250px; height:200px; }

	/* Trace, Debug */
	#better_fb_debug_console { max-height:500px; overflow:auto; max-width:450px; }
	#bfb_status { font-size:9px; font-family:arial; color:#999; vertical-align:bottom; }
	#bfb_status_older_posts_cb { margin:0px;padding:0px;height:13px;width:13px;margin-right:2px;position:relative;top:2px;}
	#bfb_status_filters_cb { margin:0px;padding:0px;height:13px;width:13px;margin-right:2px;position:relative;top:2px;}
	#bfb_status .bfb_status_separator { padding:0 2px; font-weight:bold; color:#696969; }
	#bfb_trace_window { position:fixed; top:5px; left:5px; border:4px solid #627AAD; background-color:white; padding:3px; z-index:1000; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; -moz-box-shadow:5px 5px 5px #ccc; -webkit-box-shadow:5px 5px 5px #ccc;}
	#bfb_trace_window tr:nth-child(even) { background-color:#eeeeee; }
	#bfb_trace_window_body { max-height:300px; white-space:nowrap; overflow:auto; }
	#bfb_trace_window_call_stack { border:1px solid #ccc; white-space:nowrap; overflow:auto; font-family:courier new; }
	#bfb_trace_window .bfb_trace_inserted { color:#67A54B; }
	#bfb_trace_window .bfb_trace_message { color:#922500; }
	#bfb_trace_window_header { background-color:#627AAD; color:white; font-weight:bold; }

	/* Themes */
	.bfb_theme_extra_div { display:none; }

	/* Update styles */
	#pagelet_bfb_update_pagelet .phs { padding:0 !important; }
	#bfb_update_pagelet { padding:5px; background-color:#FDFCC3; border: 1px solid #aaa !important; margin:0; -moz-border-radius:15px !important; }

	#install_button { float:right; background:url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%01%08%00%00%01%05%08%03%00%00%00(%B6%89%13%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%C0PLTE%CF%EF%A5%AD%DAc%F5%FB%FE%7F%C3*%B2%E0x%86%C66%C8%EB%9A%F1%F9%FD%A0%D5S%AC%E2Y%C2%E8%91%8F%CB0%FD%FE%FF%96%CEF%EE%F9%FD%F9%FD%FF%E0%F6%C1%D5%F4%B0%DD%F5%BB%D8%DC%DF%E8%F8%D1%B0%DDm%B7%E2%84%2CB%20%A5%D8%5B%9C%D2%5C%96%CFS%AB%DBr%8E%CAC%F4%F4%F4%D5%F0%AF%A4%D7h%B8%C4%AA%BD%E5%8A%DA%F2%B6%ED%ED%ED%E7%F3%D9%F5%F8%F4%A0%A9%96%C8%DC%B0%ED%F8%FDe%7B%86%DC%EF%C6%C8%CB%CB%F8%F8%F8%F0%FA%E6%F9%FE%F3%BA%E3%7F%8E%B7W%FC%FC%FC%FD%FD%FC%E5%E8%E9%A9%C2%CC%F9%FC%F2%D2%40%1E%B7%E7n%B1%CE%88%E4%F7%CA%EB%CF%BB%9D%C0i%EA%F2%F5%81%B0E%E4%E4%E4%FF%FF%FFp%DA1%B2%00%00%00%01bKGD%00%88%05%1DH%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%07tIME%07%D9%04%04%1181%D8%A2%A3V%00%00%05%D5IDATx%DA%ED%91%EDj%E3%3A%10%86%C7%10L%E8R(%E1h%D9_%82%E8%06%FC%BB%F7%7Fc'%965%D2H%B2%1D%A7%C9na%F7y%95%DA%D2%7C%BC%1A%3F%95%0B%8A%12%10%24%10%E1%A6KZ%FA%AA%B7f5%D96%9FSk%05%C6T%C3%7D%B26%EF%9CKg%E5%12%FA%0Br%BE%F5j%AE%CE%B1%08bC%97%F0%0FI%82o%22%FE%ABV%FE%C1~%7F%A4%DC%7Fq%2C%FFh%F8%06%A2%D1-%1A%9FU%C8%A6%DA%B2%A0%E1%DC%17%9A%AE*%AC%B1%D0%DD%5B%E2%DDP%F3%259%1C%F4%CA%10V%3A%C2%FA%D7%84v%AC%E4%A9g%F1%CF%E8%B9%EEWJ%5Ee%20qw%7B%CE%9Aw11%3F%F3I%C44%89m%AD*%B4Lrs2%F7%D9QRR%EA%F1%AB%DB%7C%E3%95w%C9%D3L%9DG%90%7C%81%2C%97.%8E%E2%CD%24%3A%BE%E4~%BDNj%25%97dd7%A2%B5%B6I%BD%D2g%EB%18%B6(gu'u%A2z%B6%03ys%AB%3E%7D%1D%DA%9E%DE%DAZ%7F%D3%EEm%00%CD%1A%C7Qn%2B%FE%E6%C3%18%03c%3C%DD%96%2C%AFX%B4%FC%96t%8A%8E%A92%7Bh%26-mVw%D1%F6%14%C9%96%22%A6z%CC%C6%92%1A%D2%24y%90%D1%D8%D8%EE%25%249%A2S%A6%B3%994%7D%7B%BE%A6%D8%17%89%19e%1C%CD%17VU%99E%DD%3A%B6'sCU-%05%FCX%FE%0F%E6%12%0Bn%5C%BF%C3%20%C93V%26b%7Dd%7D%CE%FE%2B6%EF%5B%3D%7FM%BF%D7%E5%89%99_3%D8_%20y%DB%D2%F8%F6%A0%1Enx%DCc%FCJ%F6%D8%5C%19%C4%F5%E9%8F%B8%BE%00%C4%1D%93%EBn%E2%FA%CC%5CrEQ%BB%20~~%C3%40%3F%BF%0B%C4%84%A2%00%A1%20N%A7%D3%14%7FY%93%BE%A6*0%9D%EA%B2%FAPNux-%F0%88%3A%DB%A9NM%07%1C%A6%23%A3%C8%91i%DC%5E%C6U5%CE%94%BB%B4k%DA%9D%B3%BE%D6!%EF%DD%EA%08n%7D%AA%BE%C5%ADM%EE%F6%3FE%1C%8A%02%84%82%18%A2%5C%FA%BB%3D%97%97%06%87r%AC%F7%A6%CB%99Di_%92m%CB%A6%99%BB%9Fvnm%A8%E1%E8%0D%C3n%A7%0Ch%01%F1%AB%D5%10%FF%86%F8%5E%1E%25~%7B%0Em%F5%60BC%E7%D4%05%AB%C0%D0%DD%B0%EE%D5Y%FCZ%2F%1D%EA%7D%DF2l%5E%25%BFP%14%20%14%C4%19E%01BA%BC%BF%9F%DF%DF%E3%A3%BC%CF%D5Y%F7e%7Bn%EB%B4%DA%D6%9A%0A%8DU7%95%E7%D9%B4u%96%E7%EE%D7%C4%FB%CAz%16%EB%DB%B4%9B)%DF%E5%1DE%01%02%10%80%D8%00%F1%C3%AC%EA%F0o-%F9%81%A2%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%08%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%81%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%88o%07%F1%F9%1Fk%5E%F2%89%A2%00%01%08%40l%81%F8%88K%DF%F5%DE%04V%E3%E6g%83%1FU%BE_%9B%C9~%FBi%2F%5E%B9%B9%19%AC%9Bf%C5%3D7%D8%94%7C%A0(%40(%88%0B%8AZ%03%11%9E1%0C%7F%A8%E7%E5%20%82%D1%A5y%DF%D1e%F7%A8%C1%CBC%26wK.%87%8B.%0F%5D%25%AB%05GH%F8%F0%15%5D%EEe%0F%FD%13%FC%8B%A6%BAX%10%3Ex%EFCz%CDk%D9x%B5%8D%81e%E7u%9F%96%CF'%D3%1DB%F0uU%A9%0B%C9%25_%94%7C%B5%B0%B2N%1D%3E%DF%5Br%3A%956%87%3C%AD%B6%E4%A1%F2%5Bg%F4%EA%91~%C9%40%CA%0D%CBuY%CD%3E%CD%96%8E%A62%D8%CAP%22%C1%EC%82%19%A7%B9%A6%EE%2F%16%F5%00MM%5B%1D%B6%EA4%1D%F6%BE*J%3C%CA%20D%2C%92%DBI%D23%26%7D%CAJ%8C%89%E6%E7%12%F3NU%8BUt%94%AA%DB8%E4J%C9W%F9%25%97%B6%E2%CD%2B%5D.y%0A_%FD%E5%D9%CA%F7%E4%9F%D7i%AC%85~%A4%247%C9%D7!%84%D64%CA8%DE%9EQR%9E%A2%A7%25%2BUZR%87V%A4*)%FD%BA%1352%B9%3AQ%EA%25%DB%89u%5D%AE%93bY%0Dkk%CD%CEN6v%AD6(%5D%B7%FD%02%13%912x%9D3%C8%AAo%EF'%E8%03%2B%5E%9B%92q%F5%DF%D3%BBK%CF%A6%9DJ%B6%AF%3E%3E%D0_.%19%DF%BAU%BF%B6%B2%1B%E9%DD%DE%03%25%87%9B%C7%83%A5%3B7%DA%CF%907%14%F5%7BA%5C_%DFr%7D%E9m%06%C4%15E%01%22%83%98z%5D%CDs%239%ED%26%AF%9B%E1%EB%A6%D7%F5%80%FD%D6%2Ce%E0%BB%FE6h%D32!%40l%818%BD%D4%F9t%3Cw%DA%AE%3B%FD%11%0A%B7%5B%E4%B4%A6%E9%B4%AF%E9%40Mk%B6_%3FM%0F%8E%F0%95%91%F7%A6%93%13%8A%12W%1D%EBSut%F6%ECZ%9F%18p%EE%E4%EA%BA%0Dc%B7%3FT%B2p%E5%E8%1E%E8ng%BD%F3%05%C9%5D%1C%8A%02%04%20%1A%10%C3%E0%E6%9F%8B%AF%F8%9C%F7%26V-%1B%2B%E16%97%3C%A3%CDF%8B%1E%3B%D7l9%D4%05z%CB%B6I%BA%CA%99%8Afj%F3nKf%10h%16%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%01%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%10%20%00%01%08%40%00%02%10%80%00%04%20%00%01%08%40%00%02%10%80%00%04%20%00%F1%DD%FA%1F5L%D8%F4.%80%00u%00%00%00%00IEND%AEB%60%82") no-repeat scroll right -130px #BAE37F; -moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border:1px solid #888888;color:#000044;display:block;font-size:1.5em;font-weight:bold;padding:2px 16px;text-align:center;text-decoration:none; }
	#install_button:hover { background-position:right 0;background-color:transparent;color:#0088FF; }

	/* Feed Filter criteria */
	.bfb_filter_list td { vertical-align:top; }
	.bfb_filter_list td:last-child { vertical-align:middle; }
	#bfb_filter_list tr:first-child .bfb_up, #bfb_filter_list tr:last-child .bfb_down { display:none; }
	#bfb_filter_list tr:nth-child(2n) { background-color:#ddd; }
	.bfb_filter_play { display:none; }
	.bfb_filter_disabled { opacity:.4; }
	.bfb_filter_disabled .bfb_filter_play { display:block; opacity:1.0 !important; }
	.bfb_filter_disabled .bfb_filter_pause { display:none; }

	/* Chat */
	.bfb_chat_name { font-weight:bold; opacity:1; }

	/* New window icon */
	.commentList a.UIImageBlock_Content { padding-left:24px; background:transparent url("data:image/gif,GIF89a%0D%00%0D%00%A2%00%00%FF%FF%FF%EF%EF%EF%EB%EB%EB%CA%CA%CA%BE%BE%BE%9A%9A%9Aeee%00%00%00!%F9%04%01%07%00%03%00%2C%00%00%00%00%0D%00%0D%00%00%0368%3AT%FE%85%ACQ%02%B87%94Y%AE%F9%06%B0-%1D%F6%89%CDc%02%A1c%89%5E%EC%60%5D%88%89%A5%F8b%C2%7C%A5%90H%EE6R%0Ci%9C%DD%A57%01B%24%8B%04%00%3B") no-repeat 6px center; }

	/* Image preview on hover */
	.bfb_image_preview { position:fixed; top:5px; right:10px; z-index:9999999; border:2px solid #ccc; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; padding:5px; min-height:50px; min-width: 50px; background-color:white; -moz-box-shadow:5px 5px 5px #333; -webkit-box-shadow:5px 5px 5px #333;}
	.bfb_image_preview_msg { font-size:16px; font-weight:bold; margin:10px; }
	.bfb_image_preview_footnote { font-size:8px; color:#999; font-family:arial; }
	.bfb_image_preview_caption { border:1px solid #ccc; padding:1px; background-color:white; font-size:10px; display:inline; }

	/* Conditional Rules */
	html.hide_post_actions_until_hover .bfb_post_action_container { display:none; }

	html.hide_hovercard .HovercardOverlay { display:none !important; }

	html.expand_nav_messages #navigation_item_messages ul, 
	html.expand_nav_messages #navItem_messages ul,
	html.expand_nav_messages #navItem_inbox ul,
	html.expand_nav_messages #sideNav .key-inbox ul,
	html.expand_nav_messages #sideNav #navItem_app_217974574879787 > ul
		{ display:block !important; }

	html.expand_nav_events #navigation_item_events ul, 
	html.expand_nav_events #navItem_events ul,
	html.expand_nav_events #sideNav .key-events ul,
	html.expand_nav_events #sideNav #navItem_app_2344061033 > ul
		{ display:block !important; }

	html.expand_nav_photos #navigation_item_media ul { display:block !important; }

	html.expand_nav_friends #navigation_item_ff ul, 
	html.expand_nav_friends #navigation_item_ff a.navMore, 
	html.expand_nav_friends #navItem_ff ul, 
	html.expand_nav_friends #navItem_ff a.navMore,
	html.expand_nav_friends #sideNav .key-ff ul,
	html.expand_nav_friends #sideNav #navItem_app_2356318349 > ul
		{ display:block !important; }

	html.expand_nav_friends_full #navigation_item_ff ul li.hiddenSubitem  { display:block !important; }
	html.expand_nav_friends_full #navigation_item_ff a.navMore  { display:none !important; }
	html.expand_nav_friends_full #navItem_ff ul li.hiddenSubitem  { display:block !important; }
	html.expand_nav_friends_full #navItem_ff a.navMore  { display:none !important; }

	html.left_align #globalContainer { margin:0px !important; }

	html.static_header.sidebarMode #blueBar { margin-left:-90px !important; }
	html.static_header #blueBar { position:fixed !important; z-index:15; }
	html.static_header #pageHead { position:fixed !important; z-index:15; width:981px; } /* Old way */
	html.static_header .ego_wide #pageHead { width:1020px !important; }
	html.static_header #blueBar #pageHead { position:static !important; } /* New way - pageHead is inside of blueBar */
	html.static_header #content { padding-top:41px !important; }
	html.static_header #globalContainer { width:981px; }
	html.static_header .ego_wide #globalContainer { width:1020px !important; }
	
	html.static_header #blueBarHolder ~ #globalContainer #content { padding-top:0px !important; } /* A fix for the whitespace ribbon in new layout */

	html.static_left_col body.home #leftCol { position:fixed !important; z-index:15; padding-top:41px; }
	html.static_left_col #leftCol {z-index:4 !important;}

	html.hide_left_nav_groups #groupsNav { display:none !important; }
	html.hide_left_nav_groups_create #groupsNav #navItem_app_230259100322928 { display:none !important; }
	html.hide_left_nav_apps #appsNav { display:none !important; }
	html.hide_left_nav_pages #pagesNav { display:none !important; }
	
	html.hide_update_email #megaphone_story_44 { display:none !important; }

	html.hide_options_icon #bfb_options_button_icon { display:none !important; }

	html.hide_old_comments .bfb_new_comments .better_fb_new_comment_unhighlight { display:none; }

	html.hide_notification_pictures #fbNotificationsList .uiProfilePhoto { display:none; }
	html.hide_notification_pictures #fbNotificationsList > li { padding-top:2px; padding-bottom:2px; }
	html.hide_notification_pictures #fbNotificationsList .info .metadata > i { display:none; }

	html.hide_chat_panel #pagelet_chat_home_facepile, html.hide_chat_panel #pagelet_friends_online { display:none; }

	html.pin_notifications_right_panel #fbNotificationsFlyout .blueName { color:#3B5998 !important; }
	html.pin_notifications_right_panel #rightCol #fbNotificationsFlyout {display:block !important; left:0 !important; position:static !important; top:0 !important; width:auto !important; }
	html.pin_notifications_right_panel #rightCol .notification { border-bottom:1px solid #ddd; }

	html.hide_status_updater #pagelet_status_updater,
	html.hide_status_updater #pagelet_welcome_box 
		{ display:none !important; } 
	html.hide_status_updater #leftCol { padding-top:3px !important; }

	html.stretch_wide #globalContainer {min-width: 100px !important; width: 100% !important}
	html.stretch_wide .left_column_container {margin-left: 0px !important}
	html.stretch_wide #profile_top_bar{margin-left: 220px !important; padding-left: 0px !important; width: inherit !important; margin-right...: 20px !important}
	html.stretch_wide .right_column_container {margin-left: 220px !important; width: inherit !important; margin-right: 20px !important}
	html.stretch_wide #right_column {position: static; width: auto !important; float: left !important}
	html.stretch_wide #pagelet_ads{position: absolute !important; right: 0px}
	html.stretch_wide #tab_canvas{width: 100% !important}
	html.stretch_wide #pageHead {left: 0px; width: 100% !important}
	html.stretch_wide #headNav {width: auto !important}
	html.stretch_wide #profile_pager_container {margin-right: 70px}
	html.stretch_wide  #headerArea {width: 100% !important; margin-left: 0px !important}
	html.stretch_wide #pagelet_header {margin-left: 0px !important}
	/*html.stretch_wide #headerArea .rfloat {position: absolute; right: 146px}*/
	html.stretch_wide #contentArea {width: 100% !important; padding-left: 0px !important}
	html.stretch_wide  #rightCol {position: absolute !important; width: 250px !important; padding-right: 0px !important; right: 10px !important}
	/*html.stretch_wide  #rightCol {padding-top: 52px !important}*/
	html.stretch_wide  #contentCol {width: auto !important; margin-left: 0px !important; padding-left: 200px !important; padding-right: 280px}
	html.stretch_wide  #contentCol {padding-left: 200px}
	html.stretch_wide .ego_page #contentCol,
		html.stretch_wide .home #contentCol 
		{padding-left: 20px}
	html.stretch_wide #pagelet_byline {width: 100% !important}
	html.stretch_wide .uiUfi {display: inline !important; width: auto !important}
	html.stretch_wide .profile_two_columns .right_column { padding-right:180px; }
	/* Fix for sidebar pushing content off the left side */
	html.stretch_wide.sidebarMode #globalContainer { position:static !important; left:0px !important; }
	
	html.fix_comments .sendOnEnterTip, 
	html.fix_comments .commentUndoTip, 
	html.fix_comments .child_is_active .sendOnEnterTip, 
	html.fix_comments .child_is_active .commentUndoTip 
		{display:none !important;} 
	#facebook.fix_comments .child_is_active .hidden_elem.commentBtn 
		{display:block !important;}

	html.fix_comment_cursor .uiUfiAddComment .UIImageBlock_Content.commentArea {display:block !important;width:auto !important;margin-left:40px;}	
	html.fix_comment_wrap .DOMControl_shadow:after { content:'XXX'; }

	/* Right Col */
	html.hide_happening_now #pagelet_rhc_ticker { display:none !important; }
	html.unlock_right_col .fixedRightCol .home_right_column {position: static !important;}
	
	/* Force the ticker to not be static */
	html.ticker_scroll .rightColumnWrapper.fixed_elem { position:static !important; } 
	
	/* Chat */
	html.static_header #pagelet_presence, html.static_header .fbChatSidebar  { z-index:20 !important; }
	html.chat_hide #pagelet_presence { display:none !important; }
	
	.fbChatOrderedList.compact img { display:none !important; }
	.fbChatOrderedList.compact .name { line-height:normal !important; }
	/* Shrink the popup chat list to fit the contents */
	.fbDockChatBuddyListNub .fbNubFlyoutBody, .bb .fbNub.maxHeight .fbNubFlyoutOuter { height:auto !important; }
	/* Hide our list when the search is active */
	.fbChatOrderedList ~ .fbChatTypeaheadView { display:none; }
	.fbChatOrderedList.hidden_elem ~ .fbChatTypeaheadView { display:block; }
	.fbChatOrderedList.hidden_elem ~ .fbChatOrderedList { display:none !important; }
	
	/* Chronological Order, Top Stories */
	html.chronological .uiStreamHeaderTall { display:none; }
	html.hide_top_story_indicator .highlightIndicator { display:none; }
	
		]]></>).toString());

		// Options that have to be written directly to the page. Bummer.
		var dialog_max_height = (window.innerHeight-200);
		var css2 = ''+
		'html.static_header #fbNotificationsList { max-height:'+(window.innerHeight-100)+'px !important; overflow:auto !important; } '+
		'.bfb_cp_float { opacity:%floating_cp_opacity%; } '+
		'.bfb_post_action_container { opacity:%post_action_opacity2%; } '+
		'.bfb_window_height { max-height:'+window.innerHeight+'px; }'+
		'.bfb_window_height100 { max-height:'+(window.innerHeight-100)+'px; }'+
		'.bfb_dialog .bfb_dialog_content { max-height:'+dialog_max_height+'px; overflow:auto; }'+
		'#bfb_options_body { max-height:'+(window.innerHeight-100-200)+'px;}'+
		'';
		var sprite_url = options.get('sprite_url');
		if (sprite_url && sprite_url.indexOf("http")==0) { 
			css2 += '.bfb_post_action { background-image:url('+sprite_url+'); }';
		}
		if (options.get('enable_font_size')) {
			var post_size = options.get('post_font_size');
			var comment_size = options.get('comment_font_size');
			if (!comment_size) { comment_size = post_size; }
			if (post_size) { css2 += '.uiStreamMessage,.UIStory_Message,.mall_post_body {font-size:'+post_size+'px !important;} '; }
			if (comment_size) { css2 += '.commentContent {font-size:'+comment_size+'px !important;} '; }
		}

		if (zoom!=100) {
			css2 += ''+
			'.bfb_post_action { width:'+(15*zoom)+'px; height:'+(15*zoom)+'px; -moz-background-size: '+(90*zoom)+'px background-size: '+(90*zoom)+'px '+(30*zoom)+'px; -webkit-background-size: '+(90*zoom)+'px '+(30*zoom)+'px; -o-background-size: '+(90*zoom)+'px '+(30*zoom)+'px;  } '+
			'.bfb_post_action_read:hover { background-position:0 -'+(15*zoom)+'px; } '+
			'.bfb_post_action_unread { display:none; background-position:-'+(15*zoom)+'px 0; } '+
			'.bfb_read .bfb_post_action_unread { display:block; } '+
			'.bfb_post_action_unread:hover { background-position:-'+(15*zoom)+'px -'+(15*zoom)+'px; } '+
			'.bfb_post_action_mute { background-position:-'+(45*zoom)+'px 0; } '+
			'.bfb_post_action_mute:hover { background-position:-'+(45*zoom)+'px -'+(15*zoom)+'px; } '+
			'.bfb_post_action_add { background-position:-'+(30*zoom)+'px 0; } '+
			'.bfb_post_action_add:hover { background-position:-'+(30*zoom)+'px -'+(15*zoom)+'px; } '+
			'.bfb_post_action_info { background-position:-'+(60*zoom)+'px 0; } '+
			'.bfb_post_action_info:hover { background-position:-'+(60*zoom)+'px -'+(15*zoom)+'px; } '+
			'.bfb_post_action_google { background-position:-'+(75*zoom)+'px 0; } '+
			'.bfb_post_action_google:hover { background-position:-'+(75*zoom)+'px -'+(15*zoom)+'px; } ';
		}
		css2 = _template(css2,o);
		addGlobalStyle( css + css2 );
		
		var css_url = options.get('css_url');
		if (css_url && css_url.length>0 && css_url!="null") {
			insertStylesheet(css_url);
		}

		var theme_url = options.get('theme_url');
		if (theme_url && theme_url.length>0 && theme_url!="null") {
			insertStylesheet(add_theme_url_parameters(theme_url),'bfb_theme');
		}
		if (document.body) {
			for (var i=0; i<10; i++) {
				append(document.body,el('div','bfb_theme_extra_div',{id:"bfb_theme_div_"+i}));
			}
		}

		css = options.get('css');
		if (css && css.length>0 && css!="null") {
			addGlobalStyle(css);
		}

	})();

	// =================
	// TAB Functionality
	// =================
	var previous_tab_id = null;
	var home_tab="Home";
	var home_tab_content_id = "home_stream";
	function addTabContainer() {
		var hs = getStream();
		if (PERFORMANCE) { trace_start('addTabContainer'); }
		if (hs) {
			trace("Adding tab container");
			var c = el('div','bfb_tabs',{id:'bfb_feed_tabs'});
			insertBefore( c, hs);
			insertBefore( el('div','bfb_clear'), hs );
			attachTabContainerClickHandler(c);
			if (PERFORMANCE) { trace_end('addTabContainer'); }
			return c;
		}
		if (PERFORMANCE) { trace_end('addTabContainer'); }
		return null;
	}
	function attachTabContainerClickHandler(container) {
		bind(document,'click',function(e) {
			var new_tab = getParentByClass(target(e),'bfb_tab');
			if (!new_tab) { return; }
			var tab_id = new_tab.id;
			if (tab_id==previous_tab_id) { return; } // Same tab clicked
			// Unselect previous tab
			var previous_tab = document.querySelector(".bfb_tab_selected");
			if (previous_tab) { removeClass(previous_tab,"bfb_tab_selected"); }
			// Select new tab
			addClass(new_tab, "bfb_tab_selected");
			// Unselect previous body
			var previous_body = document.querySelector(".bfb_tab_body_selected");
			if (previous_body) { removeClass(previous_body,"bfb_tab_body_selected"); }
			// Select new body
			var body_id = getTabBodyId(tab_id);
			var new_body = document.querySelector("#"+body_id);
			if (new_body) { addClass(new_body,"bfb_tab_body_selected"); }
		});
	}
	function getTabId(name) {
		return "bfb_feed_tab_"+(name.replace(/[^a-zA-Z0-9_]/g,""));
	}
	function getTabBodyId(tab_id) {
		return (tab_id=='bfb_feed_tab_Home')?home_tab_content_id:tab_id+"_body";
	}
	function addTab(name,add_close_icon,close_func) {
		if (PERFORMANCE) { trace_start('addTab'); }
		var tab_id = getTabId(name);
		var home_stream = getStream();
		if (home_stream) {
			var content, tab_feed_id;
			if ($(tab_id)==null) {
				trace("Adding tab: "+name);
				var container = $('bfb_feed_tabs');
				// If there is no tab container, and the first tab we are adding is not Home, then first add Home!
				if (!container) {
					if (name!=home_tab) {
						addTab(home_tab);
						container = $('bfb_feed_tabs');
					}
					else {
						container = addTabContainer();
					}
				}
				if (container) {
					var selected = (container.getElementsByTagName('div').length==0);
					var tab = el('div','bfb_tab '+(selected?"bfb_tab_selected":""),{id:tab_id},null,name);
					if (add_close_icon) {
						append(tab,el('div','bfb_tab_close',{title:"Remove this application from auto-tabbing. Posts from this app will return to the Home tab."},{click:close_func}));
					}
					var counter_id = tab_id+"_count";
					append(tab, el('span','bfb_tab_count',{id:counter_id}) );
					append(container, tab );
					if (name==home_tab) {
						addClass(home_stream,"bfb_tab_body_selected");
						addClass(home_stream,"bfb_stream");
						content = home_stream;
						home_tab_content_id = home_stream.id;
					}
					// Add a new feed container for this tab
					else {
						tab_feed_id = tab_id+"_body";
						content =el('ul','uiList uiStream bfb_stream '+(selected?"bfb_tab_body_selected":""),{id:tab_feed_id});
						insertAfter( content, home_stream );
					}
					// Watch for changes in the content, to update the tab
					attachTabCountUpdateHandler(tab_id);
				}
			}
			if (PERFORMANCE) { trace_end('addTab'); }
			var $tab = $(tab_id);
			if ($tab==null) {
				trace("Tab not created: "+tab_id);
			}
			return $tab;
		}
		else {
			trace("No stream found while trying to add tab ["+name+"]");
		}
		if (PERFORMANCE) { trace_end('addTab'); }
		return null;
	}
	function attachTabCountUpdateHandler(tab_id) {
		var content = $(getTabBodyId(tab_id));
		var update_tab_count = function(e) { setTimeout(function(){updateTab(tab_id);},250) };
		if (content) {
			content.addEventListener('DOMSubtreeModified',update_tab_count,false);
		}
		update_tab_count();
	}
	function moveToTab(name,o) {
		if (PERFORMANCE) { trace_start('moveToTab'); }
		var ret = "";
		var t = addTab(name);
		if (t) {
			var tab_id = t.id;
			var content = $(tab_id+"_body");
			if (!content) { ret+="Tab content object not found! "; }
			if (name!=home_tab) { 
				var p = o.parentNode;
				append(content,o); // It's already in the Home tab by default!
				if (o.parentNode==p) {
					ret += "After append(), the posts's parent node is still the same! ";
				}
			}
		}
		else {
			ret += "Tab does not exist after addTab()! ";
		}
		if (PERFORMANCE) { trace_end('moveToTab'); }
		return ret;
	}
	var tabCountTimers = {};
	var show_tab_count = options.get('tab_count');
	function updateTab(tab_id) {
		if (show_tab_count) {
			// Try to only update tab counts if it's not in rapid succession
			if (typeof tabCountTimers[tab_id]!="undefined") {
				clearTimeout(tabCountTimers[tab_id]);
			}
			tabCountTimers[tab_id] = setTimeout( function() { updateTabItemCount(tab_id); }, 500 );
		}
	}
	function updateTabItemCount(tab_id) { 
		if (PERFORMANCE) { trace_start('updateTabItemCount'); }
		var content = $(getTabBodyId(tab_id));
		var c=0,total=0;
		var cn = findStoriesInContainer(content);
		if (cn && cn.length) {
			var L = cn.length;
			// If the user is using the alternate display type, then process visible posts differently
			var is_show_all = false;
			var stream = getStream();
			if (stream && hasClass(stream,"bfb_show_all")) {
				is_show_all= true;
			}
			for (var i=0; i<L; i++) {
				var o = cn[i];
				if (!hasClass(o,"bfb_duplicate") && !hasClass(o,'UIRecentActivity_Stream')) {
					total++;
					if (is_show_all) {
						c++;
					}
					else if (!hasClass(o,'bfb_hidden') && (!hasClass(o,'bfb_read') || hasClass(o,'bfb_new_comments'))) {
						c++;
					}
				}
			}
			html( $(tab_id+"_count"), '(<span class="new">'+c+'</span>/<span class="total">'+total+'</span>)' );
			// Change classes depending on if there are any posts in the tab
			if (c==0) { addClass($(tab_id),"bfb_tab_empty"); } else { removeClass($(tab_id),"bfb_tab_empty"); }
		}
		delete tabCountTimers[tab_id];
		if (PERFORMANCE) { trace_end('updateTabItemCount'); }
	}
	
	// ==================================================================
	// POST PROCESSING
	// ==================================================================
	function hideStory(o) {
		while (o && o.parentNode) {
			if (matchesSelector(o, storySelector )) {
				removeClass(o,"bfb_new_comments");
				return;
			}
			o = o.parentNode;
		}
	}
	function getData(o,container) {
		if (PERFORMANCE) { trace_start('getData'); }
		var data = o.getAttribute(container);
		if (data) {
			var attrs = parse(data,"getDataProperty");
			if (PERFORMANCE) { trace_end('getData'); }
			return attrs;
		}
		if (PERFORMANCE) { trace_end('getData'); }
		return {};
	}
	function getDataProperty(o,prop,container) {
		return getData(o,container)[prop];
	}
	function getStoryProperty(o,prop) { return getDataProperty(o,prop,'data-ft'); }

	// Read in the custom apps and add them
	var custom_apps = trim(options.get('custom_apps'));
	if (custom_apps && custom_apps.length>0) {
		custom_apps = custom_apps.split(/\s*,\s*/);
		if (custom_apps && custom_apps.length>0) {
			for (var i=0; i<custom_apps.length; i++) {
				var props = custom_apps[i].split(':');
				apps[''+props[0]] = props[1];
				}
		}
	}

	var auto_mute_count = options.get('auto_mute_count');
	var auto_mute_all = options.get('auto_mute_all');
	var filters = options.get('filters');
    var reorder = options.get('reorder');
	var chronological = options.get('chronological');
//	var reorder_page_walls = options.get('reorder_page_walls');
	var always_show_tabs = options.get('always_show_tabs');
	var tab_all_apps = options.get('tab_all_apps');
	var expand_similar_posts = options.get('expand_similar_posts');
	var show_post_actions = options.get('show_post_actions');
	var processProfiles = options.get('process_profiles');
	var processGroups = options.get('process_groups');
	var dontHidePostsOnProfiles = options.get('dont_hide_posts_on_profiles');
	var filterProfiles = options.get('filter_profiles');
	var filters_enabled = options.get('filters_enabled');
	var display_control_panel = options.get('display_control_panel');
	var open_app_link_in_tab = options.get('open_app_link_in_tab');
	var open_app_link_marks_read = options.get('open_app_link_marks_read');
	var auto_expand_comments = options.get('auto_expand_comments');
	var expand_see_more = options.get('expand_see_more');
	var allow_bfb_formatting = options.get('allow_bfb_formatting');
	var process_recent_activity = options.get('process_recent_activity');
	var untabs = options.get('untab_apps');
	var untabs_array = untabs.split(",");
	var untabs_hash = {};
	for (var ui=0; ui<untabs_array.length; ui++) {
		if (untabs_array[ui]) { untabs_hash[untabs_array[ui]] = true; }
	}

	function addAllTabs(o) {
		addTab(home_tab);
		if (filters && filters.length) {
			for (i=0; i<filters.length; i++) {
				filter = filters[i];
				if (!filter.disabled && filter.actions && typeof filter.actions.move_to_tab!="undefined" && filter.actions.move_to_tab.indexOf("<")!=0) {
					addTab(filter.actions.move_to_tab);
				}
			}
		}
		tabs_added = true;
	}
	function tabs_exist() { return !!$('bfb_feed_tabs'); }
	function fixStory(o,isPageOrProfile,isGroupWall,saveprefs) {
		var href = "";
		try { href = window.location.href; } catch(e) { } 
		if (typeof saveprefs=="undefined") { saveprefs = true; }
		
		// If viewing a single wall post, don't process anything!
		if (href.indexOf("story_fbid=")>0 || href.indexOf("share_id=")>0) { return; }
		
		if (PERFORMANCE) { trace_start('fixStory'); }

		// Don't pocess the post if it isn't in a stream!
		if (parent(o,'.uiContextualDialogContent')) { return; }

		if (filters_enabled && always_show_tabs && !tabs_exist() && !isPageOrProfile) {
			addAllTabs(o);
		}

		if (!process_recent_activity && (hasClass(o,"UIRecentActivity_Stream") || hasClass(o,"uiStreamMinistory") || hasClass(o,"UIRecentActivityStory"))) { if(PERFORMANCE){trace_end ('fixStory');}return; } // Don't process recent activity posts

		// Create the control panel if it's not already there
		if (display_control_panel) {
			var cp = $('better_fb_cp');
			if (cp==null) { 
				var hs = $('home_stream');
				if (hs!=null) {
					createControlPanel(hs);
				}
				else {
					// If we're on profile/page
					hs = $('profile_stream_container');
					if (hs) {
						createControlPanel(hs);
					}
					else {
						hs = $('profile_minifeed');
						if (hs) {createControlPanel(hs);}
						else {
							hs = $('pagelet_group');
							if (hs) {createControlPanel(hs);}
							else {
								createControlPanel(o.parentNode);
							}
						}
					}
				}
			} else {
				cp.style.display="block"; 
			} 
		}

		// Check to see if this post has already been processed
		if (hasClass(o,'bfb_processed')) {
			if (PERFORMANCE) { trace_end ('fixStory'); }
			return; 
		}
		addClass(o,'bfb_processed');
		update_status('bfb_status_processed',++count_processed);
		
		// Get the story properties from the data-ft attribute
		var props = getData(o,"data-ft");
		var type = props.sty || -1;
		
		// Lookup the app_id if it doesn't exist
		if (!props.app_id) {
			try {
				var dataappname = QS(o,'a[data-appname]');
				var appid = dataappname.href.match(/id=(\d+)/)[1];
				if (appid) {
					props.app_id = appid;
				}
			}
			catch (e) { }
		}
		
		// If there is no fbid, then we can't uniquely identify this post. We're screwed.
		var fbid = getFbid(o,props);
		if (!fbid || fbid<=1) {
			if (++nofbidcount > 3) {
				showerror("Facebook has delivered content (posts) with no meta-data attached, so Better Facebook could not process the posts. This is a random Facebook glitch. Please reload and hope it goes away, or close this window to ignore it.");
				nofbidcount=0;
			}
			addClass(o,"nofbid");
			if (PERFORMANCE) { trace_end('fixStory'); }
			return;
		}
		
		// Handle duplicate stories
		if (QS(document,'*[fbid="'+fbid+'"]')) {
			addClass(o,"bfb_duplicate");
			update_status('bfb_status_duplicate',++count_duplicate);
			return;
		}
		o.setAttribute('fbid',fbid);

		// Enhance links in application stories
		if (props.app_id && (open_app_link_in_tab || open_app_link_marks_read) && o.querySelectorAll) {
			var links = o.querySelectorAll("a[href*=http\\:\\/\\/apps\\.facebook]");
			for (var i=0; i<links.length; i++) {
				if (open_app_link_in_tab) {
					links[i].target="_blank";
				}
				if (open_app_link_marks_read) {
					bind(links[i],'click',function() { mark_post_read(o,true); });
				}
			}
		}
		
		// Apply filter rules
		var fdebug = "";
		var show_add_app_icon = (typeof props.app_id!="undefined");
		var tabbed = false;
		var filtered = false;
		var hidden = false;
		if (filters_enabled && (!isPageOrProfile || filterProfiles)) {
			var i, filter, fmatch, dataft_key, criteria, rule, action;
			var stop_processing = false;
			var inner_text = "";
			QSA(o,'.actorName,.messageBody,.uiStreamAttachments,.uiStreamFooter,.uiStreamMessage',function(o) { inner_text += " " + innerText(o); });
			if (!inner_text) {
				inner_text = innerText(o);
			}
			fdebug += '<div style="border:1px solid #999;">'+inner_text+'</div>';
			if (filters && filters.length) {
				for (i=0; i<filters.length; i++) {
					filter = filters[i];
					if (filter.disabled) { continue; }
					fmatch = true;
					for (dataft_key in filter.criteria) {
						criteria = filter.criteria[dataft_key];
						if (dataft_key=="regex") {
							if (typeof criteria=="string" && criteria.indexOf("/")==0) {
								// This is regular expression text, so convert it!
								criteria = convert_string_to_regex(criteria);
							}
							if (typeof criteria=="string") {
								if (!o || !inner_text || inner_text.toLowerCase().indexOf(criteria.toLowerCase())==-1) {
									fmatch = false; break;
								}
							}
							else if (criteria && criteria.test) {
								if (!criteria.test(inner_text)) {
									fmatch = false; break;	
								}
							}
							else {
								fmatch = false; break;
							}
						}
						// Special case for app "Pages" to be treated as the app itself
						else if (dataft_key=="app_id") {
							if ( !(props['app_id'] && (props['app_id'] in criteria)) && !(props['actrs'] && (props['actrs'] in criteria)) ) {
								fmatch = false; break;
							}
						}
						else if (!props[dataft_key] || !(props[dataft_key] in criteria)) {
							if (dataft_key=='actrs' && !props['actrs']) { // Check to see if actrs are defined in class name
								if (!o.className || !o.className.match(/aid_\d+/)) { 
									fmatch = false;
								}
								else {
									match(o.className,/aid_\d+/g,function(aid) {
										if (!(aid.substring(4) in criteria)) { fmatch=false; }
									});
								}
								if (!fmatch){break;}
							}
							else {
								fmatch = false; 
								break;
							}
						}
					}
					if (fmatch && filter.actions) {
						fdebug+="Matched filter #"+i+". ";
						filtered = true;
						for (action in filter.actions) {
							if (action=="move_to_tab") {
								// Check for special handlers in tab names
								var tabname = filter.actions[action];
								var app_id = props['app_id'];
								if (tabname=="<app_name>") {
									if (app_id && typeof apps[app_id]!="undefined") { tabname = apps[app_id]; }
									else { tabname = "Unknown App"; }
								}
								fdebug+='Moving to tab ['+tabname+'].';
								fdebug += moveToTab(tabname,o);
								tabbed = true;
								show_add_app_icon = false;
							}
							else if (action=="add_class") { addClass(o,filter.actions[action]); }
							else if (action=="hide") { addClass(o,"bfb_hidden"); hidden = true; }
							else if (action=="minimize") { addClass(o,"bfb_minimized"); }
						}
						if (filter.stop) {
							stop_processing = true;
							break;
						}
					}
				}
			}
			// check if we need to move all app posts
			if (!tabbed && tab_all_apps) {
				if (props.app_id || (props.actrs && typeof apps[props.actrs]!="undefined" )) {
					var app_id = props.app_id;
					if (!app_id) {
						app_id = props.actrs;
					}
					if ( (app_id in apps) && !(untabs_hash[app_id])) {
						addTab(apps[app_id],true,function(x) {
							if (confirm("This will cause posts from "+apps[app_id]+" to no longer be in their own tab. The page will refresh to re-filter after this change. Are you sure you want to stop "+apps[app_id]+" posts from being automatically tabbed?")) {
								untabs += (untabs==""?"":",")+app_id;
								options.set('untab_apps',untabs,true,function() {
									try { location.reload(true); } catch(e){}
								});
							}
						});
						fdebug += moveToTab(apps[app_id],o);
						tabbed = true;
						show_add_app_icon = false;
					}
				}
			}
		}
		else {
			fdebug+="Filtering disabled";
		}
		if (tabbed) { update_status('bfb_status_tabbed',++count_tabbed); }
		if (filtered) { update_status('bfb_status_filtered',++count_filtered); }

		// Auto-expand the comments
		if (auto_expand_comments) {
			var comment_link = o.querySelector('.commentable_item');
			if (comment_link && o.querySelector('.feedbackBling')) {
				removeClass(comment_link,'collapsed_comments');
				removeClass(comment_link,'hidden_add_comment');
			}
		}
		
		// If there is a grouping of similar posts, click it!
		if (expand_similar_posts) {
			QS(o,'.'+streamCollapsedClass+' a ', function(similar) {
				similar.style.backgroundColor = "yellow";
				html( similar, "<strong>AUTO-EXPANDING...</strong>"+similar.innerHTML );
				try {
					clickLinkQueued(similar);
					update_status('bfb_status_expanded',++count_expanded);
				} catch (e) { showerror("Failed on clickLinkQueued! Please report this error!"+e.toString()); }
			});
		}

		// Get the stored data for this post
		var post_data = options.get('story_data.'+fbid);
		if (!post_data) {
			post_data = {};
			post_debug(fbid,'<br>No post data found for this post. It has not been seen before. If this post keeps coming back after marking it as read or muted, see <a href="http://BetterFacebook.net/faq.php#fbid">this FAQ entry</a> for an explanation and fix.<br><br>');
		}
		
		// Check to see if it's already been marked as read
		if (post_data.read && (!isPageOrProfile || !dontHidePostsOnProfiles)) {
			addClass(o,"bfb_read");
			hidden = true;
		}
		
		// Check to see if it has new comments
		var c = get_comment_container(o);
		var count = get_post_comment_count(o);
		
		// This is tricky. Store the number of comment childNodes of the comment container.
		// If the post has "view all X comments", and you add one, the comment counting code will still see that same number because it's not updated.
		// So we stored the childNode length and compare it later when marking as read. Yuck!
		// cnc = childNodeCount
		post_data.cnc = 0;
		if (c && c.getElementsByClassName) { post_data.cnc = c.getElementsByClassName(comment_class_name).length; }

		// But not if the user has disabled following of comments
		var new_comments_exist = false;
		if (count>0) {
			if (post_data.read && (auto_mute_all || post_data.no_comments || (auto_mute_count>0 && count>auto_mute_count))) {
				addClass(o,"bfb_muted");
			}
			else {
				var t = time();
				var stored_count = 0;
				if (post_data.cc && typeof post_data.cc.c!="undefined") {
					stored_count = post_data.cc.c
				}
				if (post_data.read && (count > stored_count)) {
					addClass(o,"bfb_new_comments");
					hidden = false;
					// Add a new box into the comment area?
					if (c!=null && (o && o.getElementsByClassName && o.getElementsByClassName('bfb_new_comment_notif').length==0)) {
						var new_count = count-stored_count;
						var text = new_count+" new comment"+((new_count>1)?"s":"") + " ("+count+" total)";
						var section = el('div','ufi_section bfb_new_comment_notif',{'innerHTML':text});
						new_comments_exist = true;
						
						// Highlight the new comments
						if (c.childNodes && c.childNodes.length>0) {
							var start = c.childNodes.length - new_count;
							if (start < 0) { start = 0; }
							for (var i=0; i<start && i<c.childNodes.length; i++) {
								var n = c.childNodes[i];
								if (n.id) {
									addClass(n,"better_fb_new_comment_unhighlight");
								}
							}
						}
						// Add the notification
						insertFirst(c,section);
					}
				}
			}
		}
        var filter = props.filter || '';

		if (!isGroupWall && (chronological || reorder || tabbed)) {
			var reorder_debug = "";
			// Record the timestamp of the post as an attribute, based on the timestamp's title attribute
			var post_time = o.getAttribute('timestamp') || 0;
			if (!post_time) {
				QS(o,'.timestamp,.livetimestamp,.bfb_timestamp',function(timestamp) {
					try { 
						post_time = (((new Date(timestamp.getAttribute('data-date'))).getTime())*10000) + (post_counter++);
						o.setAttribute('timestamp',post_time);
						reorder_debug += "<b>Timestamp</b>: "+post_time+"\n";
						post_hash[post_time] = o;
					} catch (e) { alert(e); }
				});
			}
			// Find the ID of which tab this post is in
			var tab_id = 'bfb_feed_tab_Home';
			var parent_stream = parent(o,streamContainerSelector) || getParentByClass(o,"bfb_stream");
			if (parent_stream) {
				tab_id = parent_stream.id;
			}
			reorder_debug += "Post tab id: "+tab_id+"\n";
			var tab_post_array = post_array[tab_id];
			if (typeof tab_post_array=="undefined") {
				tab_post_array = post_array[tab_id] = [];
			}
			// Loop through the post_array to find a post that is older than this one, then insert before
			var inserted = false;
			for (var i=0, L=tab_post_array.length; i<L; i++) {
				if (tab_post_array[i] < post_time) {
					var reference_post = post_hash[tab_post_array[i]];
					if (reference_post) {
						// Insert the timestamp into the array in the right place
						tab_post_array.splice(i,0,post_time);
						// Move the post
						reorder_debug += "<b>Re-ordered</b> to position #"+i+" in tab "+tab_id+" before "+getFbid(reference_post)+"\n";
						insertBefore(o,reference_post);
                        update_status('bfb_status_reordered',++count_reordered);
						inserted = true;
						break;
					}
				}
			}
			if (!inserted) {
				tab_post_array.push(post_time);
				reorder_debug += "<b>Not re-ordered</b>\n";
			}
			else {
				addClass(o,'bfb_reordered');
			}
			post_debug(fbid,reorder_debug);
		}
		
		if (hidden) { update_status('bfb_status_hidden',++count_hidden); }

		// Auto-expand the "see more" link 
		if (expand_see_more || (allow_bfb_formatting && (props.actrs=='119314224763738' || props.actrs=='174424289341'))) {
			// There are two different formats for "see more"
			QSA(o,'.text_exposed_root',function(div) {
				var hidden_html = QS(div,'.text_exposed_show','innerHTML');
				if (hidden_html) {
					QSA(div,'.text_exposed_hide,.text_exposed_show',function(span){ removeChild(span); });
					appendhtml(div,hidden_html);
				}
			});
			QSA(o,'.UIStory_Message',function(span) {
				var hidden_content = QS(span,'.text_exposed_show','innerHTML');
				if (hidden_content) {
					QSA(o,'.text_exposed_link',function(span){ removeChild(span); });
					QSA(span,'.text_exposed_hide,.text_exposed_show',function(span){ removeChild(span); });
					appendhtml(span,hidden_content);
				}
			});
		}
		
		// Add the post action tray
		if (show_post_actions) {
			var mark_post_unread = function(o,fbid,a) {
				delete post_data.read;
				delete post_data.cc;
				options.set('story_data.'+fbid,post_data);
				removeClass(o,"bfb_read");
				removeClass(o,"bfb_new_comments");
				a.parentNode.removeChild(a);
			}

			o.style.position="relative";
			var pcp = '<div class="bfb_post_action_container_inner">';
			if (options.get('show_post_action_info_mark_read')) {
				var mark_read_desc = "Mark Read: Mark this post as read and hide it until/unless new comments are posted";
				if (post_data.read) {
					mark_read_desc = "Mark Read: Update the stored comment count for this post, mark it as read, and hide it again.";
				}
				pcp += '		<div class="bfb_post_action bfb_post_action_read" title="'+mark_read_desc+'">&nbsp;</div> ';
			}
			if (options.get('show_post_action_info_mute')) {
				var mute_desc = "Mute Comments: mute this post so new comments will not be shown.";
				if (!new_comments_exist) {
					mute_desc = "Mark Read and Mute: Mark this post as read and mute any future comments";
				}
				pcp += '<div class="bfb_post_action bfb_post_action_mute" title="'+mute_desc+'">&nbsp;</div>';
			}
			if (options.get('show_post_action_mark_unread')) {
				pcp += '<div class="bfb_post_action bfb_post_action_unread" title="Mark Unread: mark this post as unread so it shows up in your feed again.">&nbsp;</div>';
			}
			if (options.get('show_post_action_info_add_app')) {
				if (show_add_app_icon) {
					pcp += '<div class="bfb_post_action bfb_post_action_add" title="Add App: add this application to your list of known apps. (It will then be automatically tabbed by name if that feature is enabled).">&nbsp;</div>';
				}
			}
			if (options.get('show_post_action_google')) {
				pcp += '<div class="bfb_post_action bfb_post_action_google" title="Google It!">&nbsp;</div>';		
			}
			if (options.get('show_post_action_info')) {
				pcp += '<div class="bfb_post_action bfb_post_action_info" title="Post Info: View debug information about this post and how it was processed. Useful for debugging or reporting problems!">&nbsp;</div>';
			}
			
			pcp += '</div>';
			var d = el('div','bfb_post_action_container',null,null,pcp);
			bind( $first(d,'bfb_post_action_add'),'click',function(e) {
				try {
					var appname = null;
					if (o.querySelector) {
						// This is the old way of identifying an application. Left here just in case it comes back.
						var applinks = o.querySelectorAll("a[href*=application\\.php\\?id\\=]");
						for (var j=0; j<applinks.length; j++) {
							if (applinks[j].getElementsByTagName("IMG").length==0) {
								appname = applinks[j].innerHTML.replace(/[,:'"\<\>\&\*\@\$]/g,'');
							}
						}
						if (!appname) {
							appname = prompt("What would you like to label this application? (This is also the name of the tab where it will appear if you have the option set to automatically send known apps to tabs)","");
						}
						if (appname) {
							if (custom_apps.length>0) { custom_apps+="," };
							custom_apps += props.app_id+':'+appname;
							options.set('custom_apps',custom_apps);
							apps[props.app_id] = appname;
							moveToTab(apps[props.app_id],o);
						}
					}
				}
				catch(e) { }
			} );
			bind( $first(d,'bfb_post_action_mute'),'click',function(e) { mute_post(o,true); } );
			bind( $first(d,'bfb_post_action_read'),'click',function(e) { mark_post_read(o,true); } );
			bind( $first(d,'bfb_post_action_unread'),'click',function(e) { mark_post_unread(o,fbid,target(e)); } );
			bind( $first(d,'bfb_post_action_info'),'click',function(e) { 
				toggleClass(o,'post_debug');
				// If the debug info isn't already there, populate it
				var db = QS(o,'.bfb_debug');
				if (!db) {
					db = el('div','bfb_debug');
					append(o,db);
				}
				html( db, get_post_debug(fbid) );
                if (db.scrollIntoView) { db.scrollIntoView(false); }
			} );
			bind( $first(d,'bfb_post_action_google'),'click',function(e) { google_it(o); } );
			
			// If this post has the "audience" selector, shit the post actions to the left
			if (QS(o,'.audienceSelector')) {
				d.style.marginRight = "24px";
			}
			insertFirst(o,d);
		}
		
		// Add debug info to the story
		var c = _template("<b>fbid</b>=%1%, <b>type=%2% (%6%)</b>, <b>post_data</b>=%3%, <b># Comments found</b>=%5%, <b>className</b>='%4%'",fbid,type,JSON.stringify(post_data), o.className, count, story_types[type]);
		var dataft = o.getAttribute('data-ft');
		if (dataft) { c+="<br><b>data-ft</b>:"+ dataft.replace(/,/g,", "); }
		if (fdebug) { c+="<br><b>Filter Debug:</b>"+fdebug; }
		post_debug(fbid,c);
		
		if (PERFORMANCE) { trace_end('fixStory'); }
	}
	
	var post_debug_info = {};
	function post_debug(fbid,str) {
		post_debug_info[fbid] = (post_debug_info[fbid]||"") + str;
	}
	function get_post_debug(fbid) {
		var debug = post_debug_info[fbid]+"<br>";
		// Output some settings
		debug += "<b>Options:</b><br>";
		var opts = ['version','alt_fbid_types4','always_show_tabs','tab_all_apps','filters_enabled','custom_apps','untab_apps','filter_profiles'];
		for (var i=0; i<opts.length; i++) {
			debug += opts[i]+":"+(options.get(opts[i]))+"<br>";
		}
		// Generate a summary of filters
		var filters = options.get('filters');
		if (filters) {
			debug += "<br><b>Filters:</b><pre>";
			filters.forEach(function(filter,i) {
				debug += "Filter #"+i+": "+JSON.stringify(filters[i],null,0)+"<br>";
			});
			debug += "</pre>";
		}
		return debug;
	}

	function google_it(o) {
		var q = QS(o,'.messageBody','innerHTML');
		if (!q) { q = QS(o,'.UIStory_Message','innerHTML'); }
		if (!q) { q = QS(o,'.uiStreamMessage','innerHTML'); }
		if (q) {
			// Clean up the source
			q = q.replace(/^\s*<span.*?<\/span>/," ");
			q = q.replace(/<.*?>/g," ");
			q = q.replace(/[^\w\d\s\_\-\.]/g,' ');
			q = q.replace(/\s+/g,' ');
			q = trim(q);
			q = q.replace(/ /g,"+");
			window.open("http://google.com/search?q="+q);
		}
		else {
			alert("Couldn't find post message content, sorry!");
		}
	}

	// Get the container where comments are stored
	function get_comment_container(o) {
		return $first(o,feedCommentClass);
	}
	// Get the count of how many comments a post has
	var comment_class_name = 'uiUfiComment';
	function get_post_comment_count(o,cnc) {
		var c = get_comment_container(o);
		var new_comment_count = 0;
		if (c) {
			if ( /view all ([,.\d]+) comments/i.test(c.innerHTML) ) {
				var view_all_count = +(RegExp.$1.replace(/[,.]/g,""));
				// If a ChildNodeCount is passed, compare it to the current CNC to see if the "view all" count is unreliable
				if (typeof cnc!="undefined") {
					var comments = c.getElementsByClassName(comment_class_name);
					if (comments && comments.length>cnc) {
						// We need to do some math!
						// # new comments = new CNC - old CNC
						new_comment_count = +(comments.length - cnc);
					}
				}
				return view_all_count + new_comment_count;
			}
			var comments = c.getElementsByClassName(comment_class_name);
			if (comments && comments.length>0) {
				return comments.length;
			}
			return c.childNodes.length || 0;
		}
		return 0;
	}

	// Mark an individual post as "read"
	function mark_post_read(o,save,func,store_undo) {
		if (typeof save!="boolean") { save=false; }
		if (typeof store_undo!="boolean") { store_undo=true; }
		var t = time();
		var fbid = getFbid(o,getData(o,"data-ft"));
		if (fbid && !hasClass(o,"bfb_duplicate")) {
			var post_data = options.get('story_data.'+fbid) || {};
			
			// Store this post in the "undo" buffer
			if (store_undo) {
				var undo_post = {type:"read", post:o, "fbid":fbid, "post_data":JSON.stringify(post_data) };
				if (save) { undo_posts=[ undo_post ]; }
				else { undo_posts.push(undo_post); }
			}
			
			post_data.read = t;

			var cc = post_data.cc || {};
			cc.c = get_post_comment_count(o,post_data.cnc);
			if (post_data.cnc) {
				delete post_data['cnc'];
			}
			cc.t = t;
			if (cc.nt) { delete cc['nt']; }
			if (cc.nc) { delete cc['nc']; }
			post_data.cc = cc;
			options.set('story_data.'+fbid,post_data,save,func);
			addClass(o,"bfb_read");
			removeClass(o,"bfb_new_comments");
		}
	}
	function mute_post(o,save) {
		var fbid = getFbid(o,getData(o,"data-ft"));
		var post_data = options.get('story_data.'+fbid) || {};
		var undo_post = {type:"mute", post:o, "fbid":fbid, "post_data":JSON.stringify(post_data) };
		if (save) { undo_posts=[ undo_post ]; }
		else { undo_posts.push(undo_post); }

		options.set('story_data.'+fbid+'.no_comments',true,false);
		mark_post_read(o,false,null,false);
		addClass(o,"bfb_muted");
		options.save();
	}

	function fixStories(o,isPageOrProfile,isGroupWall) { 
		if (PERFORMANCE) { trace_start('fixStories'); }
		// We are processing a live list. If we move a post to a tab, that changes the list!
		// So instead, copy all posts to an array first, then process each one
		if (o && o.length) {
			var posts = [];
			for (var i=0; i<o.length; i++) {
				posts.push(o[i]);
			}

			for (var i=0; i<posts.length; i++) {
				fixStory(posts[i],isPageOrProfile,isGroupWall,false);
			}
			options.save();
		}
		if (PERFORMANCE) { trace_end('fixStories'); }
	}
	function findStoriesInContainer(container) {
		if (container && container.querySelectorAll) {
			return QSA(container,storySelector);
		}
		return null;
	}

	// ==================================================================
	// Fix timestamps on posts
	// ==================================================================
	var remove_current_year = new RegExp(", "+current_year);
	function fix_timestamps(o) {
		QSA(o,'abbr[data-date][title]',function(a){ 
			if ($('MessagingDashboard')) { return; }
			if (hasClass(a,'bfb_timestamp')) { return; }
			var new_label = (""+a.title).replace(remove_current_year,"");
			if (a.innerHTML.indexOf("ago")>0) {
				try {
					var now = new Date();
					var d = new Date(a.getAttribute('data-date'));
					if ( ((now.getTime()-d.getTime()) < (days*1)) && (now.getDate()==d.getDate()) ) {
						new_label = new_label.replace(/.+ /,'');
					}
				} catch(e) { }
				new_label += " ("+a.innerHTML+")";
			}
			html(a,"");
			append(a,document.createTextNode(new_label));
			removeClass(a,"timestamp");
			removeClass(a,"livetimestamp");
			addClass(a,"bfb_timestamp");
		});
	}
	if (options.get("fix_timestamps") && document.body) {
		fix_timestamps(document.body);
	}

	// ==================================================================
	// Notifications
	// ==================================================================
	subscribe('presence/started',function(){
		onIdLoad('fbNotificationsFlyout',function(notifications) {
			if (!unsafeWindow.presenceNotifications) { return false; }
			var pinned = false;
			// PIN NOTIFICATIONS
			if (options && options.get('pin_notifications')) {
				notifications.style.position="fixed";
				notifications.style.top="40px";
				notifications.style.right="0px";
				notifications.style.display="block";
				notifications.style.left="auto";
				notifications.style.maxHeight=(window.innerHeight-25)+'px';
				notifications.style.overflow="auto";
				notifications.style.zIndex=9998;
				var w = options.get('pin_notifications_width');
				if (w && w!="") {
					notifications.style.width=w;
				}
				pinned = true;
			}
			else if (options && options.get('pin_notifications_right_panel')) {
				var rc = QS(document,'#rightCol');
				if (rc) {
					insertFirst(rc,notifications);
					pinned=true;
					addClass(QS(document,'html'),'pin_notifications_right_panel');
				}
			}
			if (pinned) {
				removeClass(notifications,'toggleTargetClosed');
				unsafeWindow.presenceNotifications.fetch();
				unsafeWindow.presenceNotifications.markRead(true);
			}

			if (options && options.get('show_notification_previews')) {
				// Add hovering features
				var retrieving_preview = null;
				var preview_top=0, preview_left=0;
				var preview_window = null;
				var preview_content = {};
				var hide_notif_preview = function() {
					if (preview_window!=null) {
						preview_window.style.display="none";
						retrieving_preview = null;
					}
				}
				var show_notif_preview = function(content) {
					if (preview_window==null) {
						preview_window = document.createElement("div");
						preview_window.className="bfb_notif_preview bfb_window_height";
						append(document.body,preview_window);
					}
					html(preview_window,content);
					preview_window.style.display="block";
					position_notif_preview();
				}
				var position_notif_preview = function() {
					if (preview_window!=null) {
						preview_window.style.top = preview_top+10+"px";
						if (preview_left+preview_window.offsetWidth>document.body.offsetWidth) {
							preview_window.style.left = preview_left-10-preview_window.offsetWidth+"px";
						}
						else {
							preview_window.style.left = preview_left+10+"px";
						}
	//					if (preview_top+preview_window.offsetHeight>window.innerHeight) {
	//						var newtop = preview_top - 10 - (preview_top+preview_window.offsetHeight-window.innerHeight);
	//						if (newtop<0) { newtop=0; }
	//						preview_window.style.top = newtop + "px";
	//					}
					}
				}
				var scrollhandler = function(e) {
					if (preview_window!=null) {
						var distance = e.detail || e.wheelDelta || 0;
						if (e.wheelDelta) { 
							var newScrollTop = preview_window.scrollTop + (-(distance/3));
						}
						else {
							var newScrollTop = preview_window.scrollTop - (-(distance/3))*20;
						}
						if (newScrollTop<0) { newScrollTop = 0; }
						preview_window.scrollTop = newScrollTop;
						e.preventDefault();
						e.stopPropagation();
					}
				}
				var clicked = false;
				notifications.addEventListener('click',function(){clicked=true;hide_notif_preview();},true);
				bind(notifications,'DOMMouseScroll',scrollhandler );
				bind(notifications,'mousewheel',scrollhandler );
				bind(notifications,'mousemove',function(e) {
					if (clicked){return;}
					var t = target(e);
					if (!t) { return; }
					preview_top = e.pageY;
					preview_left = e.pageX;
					while (t.tagName!="A" && t.id!="jewelNotifs" && t.parentNode) {
						t=t.parentNode;
					}
					if (!t) { return; }
					if (t.tagName && t.tagName=="A") {
						var url = t.href.replace(/http:/, protocol);
						var type = null;
						if (url.indexOf("photo.php")>-1) { type="photo"; }
						if (url.indexOf("permalink.php")>-1 || url.indexOf("/posts/")>-1 || url.indexOf("notif_t=feed_comment")>-1) { type="permalink"; }
						if (type) {
							if (retrieving_preview!=url) {
								retrieving_preview = url;
								if (typeof preview_content[url]=="undefined") {
									var preview_html = '<div class="bfb_notif_preview_message">Use your scroll wheel to scroll down if necessary</div>';
									show_notif_preview("Loading preview...");
									if (type=="photo") {
										fetch_content_in_iframe(url,'content',function(content) {
											if (content) {
												var img = content.querySelector('#myphoto');
												var comments = content.querySelector('#photocomment');
												if (img) {
													preview_html += '<img class="bfb_notif_photo_preview" src="'+img.src+'" style="max-height:'+options.get('preview_img_max_height2')+'px;max-width:'+options.get('preview_img_max_width2')+'px;">';
												}
												if (comments) {
													preview_html += '<br>'+comments.innerHTML;
												}
												preview_content[url] = preview_html;
												if (url==retrieving_preview) {
													show_notif_preview(preview_html);
												}
											}
											else if (url==retrieving_preview) {
												show_notif_preview("Error retrieving preview");
											}
										});
									}
									else if (type=="permalink") {
										fetch_content_in_iframe(url,'content',function(ca) {
											if (ca) {
												var post = ca.querySelector('.storyContent');
												if (post) {
													preview_html += post.innerHTML;
													preview_content[url] = preview_html;
													if (url==retrieving_preview) {
														show_notif_preview(preview_html);
													}
												}
											}
											else if (url==retrieving_preview) {
												show_notif_preview("Error retrieving preview");
											}
										});
									}
								}
								else { show_notif_preview(preview_content[url]); }
							}
							else { position_notif_preview(); }
						}
						else { hide_notif_preview(); }
					}
				});
				bind(notifications,'mouseout',function(e) {
					var t = target(e);
					if (!t) { return; }
					while (t.tagName!="A" && t.id!=notifications.id && t.parentNode) { t=t.parentNode; }
					if (!t||t.tagName!="A") { hide_notif_preview(); }
					else {
						// Check to see if we've moved quickly to something outside our container
						if (t=e.relatedTarget) {
							while (t.id!=notifications.id && t.parentNode) { t=t.parentNode; }
							if (!t || t.id!=notifications.id) {
								// We've gone outside the container, so hide
								hide_notif_preview();
							}
						}
					}
				});
			}
		});
	});

	function getStream() {
		var s;
		var tab_content = document.querySelector('.bfb_tab_body_selected');
		if (tab_content) { 
			return tab_content; 
		}
		if (processProfiles) {
			if (s=$('profile_minifeed')) { 
				return s; 
			}
		}
		if (processGroups) {
			if (s=QS(document,'#pagelet_group_mall ul.uiStream')) { 
				return s; 
			}
		}
		if (s=$('home_stream')) { return s; }
		s = QSA(document,streamContainerSelector);
		if (s && s.length) { return s[0]; }
		trace("No stream found!");
		return null;
	}
	
	var bad_fbid_sty_types = array_to_object(split(options.get('alt_fbid_types4'),',')) || {};
	function getFbid(o,props) {
		// Some stories change their fbid, so we need to remembers the actrs involved to uniquely identify it
		var prop_keys_exist = false, key=null;
		if (props) { for (key in props) { prop_keys_exist=true; } }
		if (props && prop_keys_exist && (typeof props.sty=="undefined" || props.sty==-1 || typeof bad_fbid_sty_types[props.sty]!="undefined")) {
			var found_prop = false;
			var id = "sty"+(props.sty||-1);
			// Return the actrs instead, which can unfortunately be in random, comma-separated order
			if (props.actrs && props.actrs.split) {
				var actrs = props.actrs.split(/\s*,\s*/).sort( function(a,b) { return (a>b)?1:-1; } ).join(",");
				id+= ":"+actrs;
			}
			else {
				match(o.className,/aid_\d+/g,function(m) {
					id+=":"+m.substring(4);
				});
			}
			if (!o.className || !o.className.match(/aid_\d+/)) { 
				fmatch = false;
			}
			if (props.object_id) {
				id+=":"+props.object_id; found_prop = true;
			}
			if (props.pub_time) {
				id+=":"+props.pub_time; found_prop = true;
			}
			if (!found_prop && props.mf_story_key) {
				id+=":"+props.mf_story_key;
			}
			return id;
		}
		if (props && props.fbid) { 
			return props.fbid; 
		}
		var fbid = getStoryProperty(o,'fbid');
		if (!fbid && o.id) {
			var parts = o.id.split("_");
			if (parts) {
				fbid = parts[parts.length-1];
			}
		}
		return fbid;
	}
	function process_visible_posts(func) {
		var stream = getStream();
		if (stream) {
			removeClass(stream,"bfb_show_all");
			var posts = findStoriesInContainer(stream);
			for (var i=0, L=posts.length; i<L; i++) {
				var o = posts[i];
				if (!hasClass(o,'bfb_hidden') && (!hasClass(o,'bfb_read') || hasClass(o,'bfb_new_comments'))) {
					func(o);
				}
			}
		}
	}
	function markRead(func) {
		trace("Mark All Read clicked");
		undo_posts = [];
		process_visible_posts(function(o) {
			mark_post_read(o,false);
		});
		options.save(func);
		scroll_to_top();
	}
	function mute_all() {
		trace("Mute All Read clicked");
		undo_posts = [];
		process_visible_posts(function(o) {
			mute_post(o,false);
		});
		options.save();
		scroll_to_top();
	}
	function toggle_show_all() {
		var e = getStream();
		if (e) { toggleClass(e,"bfb_show_all"); }
	}
	function createSidebarSection(o) {
		if (PERFORMANCE) { trace_start('createSidebarSection'); }
		var d = el('div','better_facebook_sidebar_section');
		d.id="pagelet_"+o.id;
		
		// Check to see if it should be collapsed by default
		var pagelets = options.get('pagelet_collapsed');
		if (pagelets) {
			if (typeof pagelets[d.id]!="undefined" && pagelets[d.id]) { d.className="bfb_pagelet_closed"; }
		}
		var h = ''+
		'<div>'+
	'		<div class="mbl">'+
	'			<div class="uiHeader uiHeaderBottomBorder uiHeaderTopAndBottomBorder uiSideHeader mbm mbs pbs">'+
	'				<div class="clearfix uiHeaderTop">'+
	'					<div>'+
	'						<h4 class="uiHeaderTitle pagelet_title">%title%</h4><span id="%id%_title_after"></span>'+
	'					</div>'+
	'				</div>'+
	'			</div>'+
	'			<div class="UIRequestBox phs">'+
	'				<div id="%id%" class="UIImageBlock clearfix UIRequestBox_Request UIRequestBox_RequestFirst UIRequestBox_RequestOdd">'+
	'					%content%'+
	'				</div>'+
	'			</div>'+
	'		</div>'+
		'</div>';
		html( d, _template( h, o ) );
		var dd = d.getElementsByClassName('uiHeaderTop')[0];
		if (dd) {
			if (o.links) {
				o.links.forEach( function(link,i) {
					var a = el('a','bfb_sidebar_header_link',{href:'#',innerHTML:link.linktext},{click:link.linkonclick});
					var nd = el('div','uiTextSubtitle uiHeaderActions rfloat');
					append(nd,a);
					insertFirst(dd,nd);
				} );
			}
			if (o.close_pref && !o.close_func) {
				o.close_func = function(){
					var close_msg = o.close_msg || "Are you sure you want to remove this widget?";
					if (confirm(close_msg)) {
						options.set(o.close_pref,false);
						removeChild(d);
					}
				};
			}
			if(o.close_func) {
				var a = el('a','bfb_sidebar_header_link',{href:'#',innerHTML:'<img src="'+x_img+'">'},{'click':o.close_func});
				var nd = el('span','uiTextSubtitle uiHeaderActions rfloat');
				append(nd,a);
				insertFirst(dd,nd);
			}
		}
		if (PERFORMANCE) { trace_end('createSidebarSection'); }
		return d;
	}

	// When the page is first loaded, process the stuff that is there
	fixStories( findStoriesInContainer($('home_stream')), false, false );
	if (processProfiles) {
		fixStories( findStoriesInContainer($('profile_minifeed')), true, false );
	}
	if (processGroups) {
		fixStories( findStoriesInContainer($('pagelet_group_mall')), false, true );
	}
	
	// When the streams are unloaded, reset counters
	onUnload(['home_stream','profile_minifeed','pagelet_group_mall'],function() {
		post_array = {};
		post_hash = {};
		post_counter = 0;
	},true);

	// RIGHT COLUMN CONTENT
	// ====================
	// Put a "close" link on all side panels and hide them if already closed
	var current_hidden = options.get('right_panels_hidden');
	var hidden_sidepanels = split(current_hidden,';');
	onSelectorLoad('#rightCol .uiSideHeader h4, #pagelet_ego_pane .uiSideHeader h4, #MessagingNetegoSidebar .uiSideHeader h4, .UIStandardFrame_SidebarAds .uiSideHeader h4',function(o) {
		var sidebar_title = trim(o.innerHTML.replace(/(You\s*and\s*).*/gi,"$1..."));
		sidebar_title = sidebar_title.replace(/<.*/g,'');
		sidebar_title = sidebar_title.replace(/\s*\(\d+\)/g,'');
		var container = getParentByClass(o,'uiSideHeader');
		var header_top = getParentByClass(o,'uiHeaderTop');
		if (container) { 
			var mbl = getParentByClass('mbl'); 
			if (mbl) { container=mbl; }
			else {
				var mbm = getParentByClass('mbm'); 
				if (mbm) { container = mbm; }
				else { container = container.parentNode; }
			}
		}
		if (container && hidden_sidepanels.indexOf(sidebar_title)>-1) {
			hide(container);
		}
		else if (container) {
			if (header_top) {
				var existing_close = QS(header_top,'.bfb_sidebar_close');
				if (existing_close) { 
					// If there is a close icon already, remove it and add a new one
					removeChild(existing_close.parentNode);
				}
				var a = el('a','bfb_sidebar_header_link bfb_sidebar_close',{href:'#',title:'Click to hide this panel',innerHTML:'<img src="'+x_img+'">'},{click:function(){
					if(confirm('Are you sure you want to hide the panel labeled \''+sidebar_title+'\'?\n(You can choose to show it again in Options)')) {
						hidden_sidepanels.push(sidebar_title);
						options.set('right_panels_hidden',hidden_sidepanels.join(';'),true,function() {
							hide(container);
						});
					}
				}});
				var nd = el('div','uiTextSubtitle uiHeaderActions rfloat');
				append(nd,a);
				insertFirst(header_top,nd);
				
				// Add an 'expand' msg
				insertFirst(header_top,el('span','bfb_sidebar_header_expand rfloat',null,null,'(click to expand)',{'display':'none'}));
			}
		}
	});	
	
	onSelectorLoad('#rightCol',function(o) {
		var feed_right_column = o;
		
		// TODO!!!
		QS(feed_right_column,'.home_right_column',function(oo) {
			feed_right_column = oo;
		});
		if ($('pagelet_chbox')!=null) { feed_right_column=$('pagelet_chbox').parentNode; }
		else if ($('pagelet_adbox')!=null) { feed_right_column=$('pagelet_adbox').parentNode; }
	
		// If the "fixed" right panel exists, don't add panels
		if (QS(feed_right_column,'.fixedAux')) { return; }
	
		if (options && options.get('pagelet_toggle')) {
			$tagname(o,"h4",function() { this.title="Click to expand/collapse this pagelet"; });
			
			// Handle clicks on pagelet titles
			bind(o,'click',function(e) {
				var e = target(e);
				if (e.tagName=="H4" || hasClass(e,'bfb_sidebar_header_expand')) {
					var pagelet = e;
					while (pagelet=pagelet.parentNode) {
						if (pagelet.id=="pagelet_right_sidebar" || pagelet.id=="rightCol") {
							pagelet = null;
							break;
						}
						if(pagelet.id && (pagelet.id.indexOf("pagelet_")==0 || pagelet.id=="ego_pane")) {
							break;
						}
					}
					if (pagelet && pagelet.id) {
						toggleClass(pagelet,"bfb_pagelet_closed");
						options.set("pagelet_collapsed."+pagelet.id,hasClass(pagelet,"bfb_pagelet_closed"));
					}
				}
				// Allow collapsing of Notifications if put into right col
				if (e.tagName=="H3") {
					var pagelet = e.parentNode.parentNode.parentNode.parentNode;
					if ("fbNotificationsFlyout"==pagelet.id) {
						toggleClass(pagelet,"bfb_pagelet_closed");
						options.set("pagelet_collapsed."+pagelet.id,hasClass(pagelet,"bfb_pagelet_closed"));
					}
				}
			});
			// Collapse pagelets by default
			var id,pagelets = options.get('pagelet_collapsed');
			if (pagelets) {
				for (id in pagelets) {
					if (pagelets[id]) { 
						var e=$(id);
						if (e) {
							addClass(e,"bfb_pagelet_closed");
						}
					}
				}
			}
		}
		
		// Friend Tracker
		// --------------
		(function() {
			try {
				if (options && options.get('show_friend_tracker')) {
					trace("Adding Friend Tracker");
					var clear = function() {
						options.set('friend_tracker.unfriended',{});
						loadContent();
					}
					var loadContent = function(force) {
						var t = time();
						html( $('better_fb_friend_tracker_pagelet'), "Loading..." );
						get_remote_content('typeahead', function(result) {
							var friends = options.get('friend_tracker') || {'friends':{},'unfriended':{}};
							if (typeof friends.friends=="undefined") { friends.friends={}; }
							if (typeof friends.unfriended=="undefined") { friends.unfriended={}; }
							var old_friends = friends.friends;
							var unfriended = friends.unfriended;
							var count = 0;
							var friend_list = parse(result.substring(9),"Friend Tracker");
							if (!friend_list.payload || !friend_list.payload.entries) { trace("Friend tracker returned invalid data!"); return false; }
							friend_list = friend_list.payload.entries;
							trace("Friend list length="+friend_list.length);
							if (friend_list && friend_list.length>5) {
								var current_friends = {};
								for (i=0;i<friend_list.length;i++) {
									if (friend_list[i].ty=="u") { // only users
										count++;
										var id = friend_list[i].i;
										var name = friend_list[i].t;
										var f = {'name':name,'added':t};
										// User wasn't my friend before
										if (typeof old_friends[id]=="undefined") {
											// Add them into the list of my friends!
											old_friends[id] = f;
										}
										// Maintain a list of all current friends
										current_friends[id] = f;
										// Forcefully delete any unfriends who are now friends
										delete unfriended[id];
									}
								}
								trace("Current # friends="+count);

								// Now loop through all my old_friends, to see if they no longer exist in current_friends
								var h = "";
								for (var id in old_friends) {
									if (typeof current_friends[id]=="undefined") {
										// They unfriended you! Bastards!
										unfriended[id] = old_friends[id];
										unfriended[id].deleted = t;
										unfriended[id].id = id;
										delete old_friends[id];
									}
								}
								var days = options.get('friend_tracker_duration') || 3;
								var duration = 1000*60*60*24*days;
								var unfriend_array = object_to_array( unfriended, 'deleted', true );
								for (var i=0; i<unfriend_array.length; i++) {
									var f = unfriend_array[i];
									var id = f.id;
									if (t-f.deleted > duration ) {
										delete unfriended[id];
									}
									else {
										h += '&nbsp;&nbsp;&nbsp;<a href="/profile.php?id='+id+'">'+f.name+'</a> <span class="'+timestampClass+'">'+ago(f.deleted,t)+'</span><br>';
									}
								}
								if (h) {
									h = "You are no longer friends with:<br>"+h;
									h += "<br>(Note: Occasionally Facebook will report incorrect data to this script, and the users above are actually still your friend. Please verify the data above by clicking on the friend's name.)";
								}
								else if (options.get('show_friend_tracker_no_activity_msg')) {
									h = "No activity (When you are unfriended, names will show up here)";
								}
								html( $('better_fb_friend_tracker_pagelet'), h );
								
								// Update total friend count
								html( $('better_fb_friend_tracker_pagelet_title_after'), " ("+(count-1)+")" );
								
								// Finally, save the details!
								options.set('friend_tracker',friends);
							}
						},null,force);
					}
					
					// Only insert if it doesn't already exist!
					if ($('better_fb_friend_tracker_pagelet')==null) {
						// A "Friend Tracker" sidebar will notify if anyone unfriended you
						insertAtPosition( feed_right_column, createSidebarSection({ title:'Friend Tracker',content:'Loading...',id:'better_fb_friend_tracker_pagelet',close_pref:'show_friend_tracker',links:[ {linktext:'Clear',linkonclick:clear }, {linktext:'Refresh',linkonclick:function(){loadContent(true);} } ] } ), 2 );
						onIdLoad('better_fb_friend_tracker_pagelet', function(){ setTimeout(loadContent,10); });
					}
				}
			} catch(e) { showerror("Friend Tracker Error",e.toString()); }
		})();

		// Friend Activity
		// -----------------
		(function() {
			// Only insert on home screen
			if (!QS(document,'body.home')) { return; }
			try {
				if (options && options.get('show_friend_activity') && document.querySelectorAll) {	
					trace("Adding Friend Activity");
					var last_seen = options.get('friend_activity_last_seen');
					var new_last_seen = last_seen;
					var debuginfo = debugmsg("Last Seen: "+last_seen);
					
					// Define the function that does the loading
					var loadContent = function(force) {
						var contentArea = $('better_fb_friends_pagelet');
						html( contentArea, "Loading..." );
						var iframe = document.createElement('iframe');
						iframe.className="bfb_iframe";
						var url = remote_content.friend_activity.url;
						iframe.src = url;
						iframe.addEventListener('load',function(e) {
							var d = e.target.contentDocument;
							var process = function(container) {
								var h = "";
								if (container==null) {
									h = "A Facebook error occured while loading content. Hopefully they will fix this soon! (This is not a BFB error). Src: <a href=\""+url+"\">"+url+"</a>";
								}
								else {
									if (d && d.querySelectorAll) {
										// For each friend, get their name and what was updated
										var names = d.querySelectorAll(".friendsDashboard .objectListItem .UIImageBlock_Content a");
										var updates = d.querySelectorAll(".friendsDashboard .objectListItem .auxiliary span.highlight");
										var times = d.querySelectorAll(".friendsDashboard .objectListItem .auxiliary abbr");
										var pics = d.querySelectorAll(".friendsDashboard .objectListItem .img");
										var show_pics = options.get('friend_activity_show_pics');
										var show = true;
										var hide_text = options.get('friend_activity_hide_text');
										for (var j=0; j<names.length; j++) {
											var unique = trim(names[j].innerHTML)+"/"+trim(updates[j].innerHTML);
											if (j==0) {
												// Record the most recent one in case of "clear"
												new_last_seen = unique;
												debuginfo += debugmsg("New Last Seen:"+new_last_seen);
											}
											if (last_seen && last_seen==unique) {
												show = false;
											}
											var update = updates[j].innerHTML;
											var show_this = show;
											var debug_class = "";
											if ( hide_text && (new RegExp(hide_text,"i").test(update))) {
												show_this = false;
											}
											if (!show_this && DEBUG) {
												debug_class="debug_small";
												show_this = true;
											}
											if (show_this) {
												var pic = (show_pics)?'<img src="'+pics[j].src+'" class="bfb_friend_activity_img">':'';
												h += _template('<div class="bfb_clear %6%">%5%<h4 class="bfb_h4"><a href="%1%">%2%</a></h4>&nbsp;&nbsp;&nbsp;&nbsp;<span class="bfb_update">%3%</span> - <span class="'+timestampClass+'">%4%</span></div>', names[j].href, names[j].innerHTML, update, times[j].innerHTML, pic, debug_class);
											}
										}
									}
								}
								if (!h) {
									h = "No activity";
								}
								options.multiset( {'friend_activity_content':h,'friend_activity_last_update':time() } );

								// Remove the iframe
								if (iframe && iframe.parentNode) { iframe.parentNode.removeChild(iframe); }

								html( contentArea, ((DEBUG)?debuginfo:"")+h );
							}
							onElementContent('pagelet_friends',process,d);
						},false);
						var pagelet = $('better_fb_friends_pagelet');
						if (pagelet) {
							append(pagelet,iframe);
						}
					}
					var clear = function() {
						last_seen = new_last_seen;
						options.multiset({'friend_activity_last_seen':new_last_seen,'friend_activity_last_update':0},true,loadContent);
						if (DEBUG) { debuginfo=""; }
					}
					
					// Only insert if it doesn't already exist!
					if ($('better_fb_friends_pagelet')==null) {
					
						insertAtPosition( feed_right_column, createSidebarSection({ title:'Friends Activity',content:'Loading...',id:'better_fb_friends_pagelet',close_pref:'show_friend_activity',links:[ {linktext:'Clear',linkonclick:clear },{linktext:'Refresh',linkonclick:loadContent} ] } ), 3 );
						// check to see if we need to load new content
						var interval = options.get('friend_activity_interval');
						var last = options.get('friend_activity_last_update');
						if (DEBUG) { debuginfo += debugmsg("Last update "+Math.ceil((time()-last)/60000)+" minutes ago"); }
						if (last==null || (time()-last > (interval*60*60*1000))) {
							loadContent();
						}
						else {
							// Just show previous content!
							var c = options.get('friend_activity_content');
							if (DEBUG) { debuginfo += debugmsg('Showing cached content'); }
							html( $('better_fb_friends_pagelet'), ((DEBUG)?debuginfo:"")+c );
						}
					}
				}
			} catch(e) { showerror("Friend Activity Error",e.toString()); }
		})();
		


		// =================================================
		// Show Ajax-Loaded Right Panels
		// =================================================
		function pagelet_box(col,pagelet_id,title,url,ttl,sidebar_options,use_cache,debug) {
			debug = debug || "";
			var display = function(content) {
				// Render any options
				if (options) {
					options.options.forEach(function(opt,i) {
						if (opt.name) {
							content = content.replace( new RegExp("%"+opt.name+"%","g"), options.renderOption(opt));
						}
					});
				}
				var sidebar_o = { 
					'title':title,
					'content':content,
					'id':pagelet_id
				};
				if (sidebar_options) {
					for (var o in sidebar_options) { sidebar_o[o] = sidebar_options[o]; }
				}
				var section = createSidebarSection(sidebar_o);
//				appendhtml(section,'<div class="bfb_debug">'+debug+'</div>');
				insertFirst( col, section );
				// Attach functionality to the inserted action buttons/links
				QSA(section,'.bfb_pagelet_action',function(o) {
					bind(o,'click',function(e) {
						var pref,o=target(e);
						var data = o.getAttribute('data');
						if (data) {
							data = data.replace(/([\{\,])\s*(.*?)\s*:/g,'$1"$2":');
							data = parse(data);
							if (data) {
								if (typeof data.setpref!="undefined") {
									for (pref in data.setpref) { 
										var val = data.setpref[pref];
										if (val==="true") { val=true; }
										if (val==="false") { val=false; }
										options.set(pref,val,false); 
									}
								}
								if (data.saveprefs) {
									QSA(section,'input',function(input) {
										if (input.type=="checkbox") {
											options.set(input.name,input.checked,false);
										}
										else if (input.type=='text') {
											options.set(input.name,input.value,false);
										}
									});
								}
								if (typeof data.setpref!="undefined" || data.saveprefs) {
									options.save();
								}
								if (data.message) {
									alert(data.message);
								}
								if (data.close) {
									removeChild( $('pagelet_'+pagelet_id) );
								}
							}
						}
						
					});
				});
			}

			// Check for cached content
			var content_key = userid+'/cache/'+pagelet_id;
			var ttl_key = userid+'/cache_ttl/'+pagelet_id;
			getValue([content_key,ttl_key],[null,null],function(vals) {
				debug += "<br>userid="+userid;
				debug += "<br>pagelet_id="+pagelet_id;
				debug += "<br>use_cache="+use_cache;
				debug += "<br>time="+time();
				debug += "<br>stored ttl="+vals[ttl_key];
				if (use_cache && vals[ttl_key] && time()<vals[ttl_key]) {
					debug += "<br>CACHE USED";
					if (vals[content_key]) {
						display(vals[content_key]);
					}
				}
				else {
					ajax({'method':'GET','headers':{},'url':url,'onload':function(res) { 
						if (res && typeof res.responseText!="undefined") {
							debug += "<br>Ajax response received";
							var s = trim(res.responseText);
							setValue(content_key,s);
							setValue(ttl_key, "" + (time()+(ttl*60*1000)));
							if (s) {
								display(s);
							}
						}
					}});
				
				}
			});
		}

		// Insert a "Donate" box on the right every so often
		// -------------------------------------------------
		var donate_check_time = options.get('donate_check_time');
		var show_donate = true;
		if (donate_check_time==0) {
			donate_check_time = time() + 1000*60*60*24*7; // 1 week
			options.set('donate_check_time',donate_check_time);
			show_donate = false;
		}
		if (!options.get('no_donate') && !options.get('donated') && show_donate && (donate_check_time>0) && (time() > donate_check_time)) {
			pagelet_box(feed_right_column,'bfb_donate_pagelet','Support Better Facebook!','http://BetterFacebook.net/pagelet_donate.php?donate_check_time='+time(),1);
		}
		
		// Check for new BFB Messages
		// --------------------------
		if (options.get('check_for_messages')) {
			var t = time();
			var message_check_interval = options.get('message_check_interval');
			var show_message = options.get('show_message');
			var min_since_last_check = (t-options.get('last_message_check'))/ (1000*60);
			var use_cache = true;
			if (options.get('last_message_check')==0) {
				// Initial install, wait 1 day
				options.set('last_message_check',time()+(1000*60*60*24), false);
				options.set('show_message',false,false);
				options.save();
				show_message = false;
			}
			else if (show_message || (min_since_last_check > message_check_interval)) {
				var last_message_id = options.get('last_message_id');
				if (min_since_last_check > message_check_interval) {
					options.set('last_message_check',time(),false);
					options.set('show_message',true,false);
					options.save();
					use_cache = false;
				}
				pagelet_box(feed_right_column,'bfb_message_pagelet','Better Facebook Message','http://BetterFacebook.net/pagelet_message.php?last_message_check='+t+'&last_message_id='+last_message_id, (message_check_interval-.01), null, use_cache );
			}
		}
	
		// Tips of the Day
		// ---------------
		if (options.get('tips_of_the_day')) {
			var t = time();
			var tip_check_interval = 60*24;
			var show_current_tip = options.get('show_current_tip');
			var min_since_last_check = (t-options.get('last_tip_check'))/ (1000*60);
			var use_cache = true;
			var debug = "<br>show_current_tip="+show_current_tip;
			debug += "<br>tip_check_interval="+tip_check_interval;
			debug += "<br>min_since_last_check="+min_since_last_check;
			if (show_current_tip || (min_since_last_check > tip_check_interval)) {
				var last_tip_id = options.get('last_tip_id');
				debug += "<br>last_tip_id="+last_tip_id;
				if (min_since_last_check > tip_check_interval) {
					options.set('last_tip_check',time(),false);
					options.set('show_current_tip',true,false);
					options.save();
					use_cache = false;
				}
				var close_options = {'close_pref':'tips_of_the_day', 'close_msg':'Are you sure you want to close and no longer see any Better Facebook Tips of the Day? If you only want to hide this tip, click the Close button instead!'};
				pagelet_box(feed_right_column,'bfb_tip_pagelet','Better Facebook Tip of the Day','http://BetterFacebook.net/pagelet_tip.php?last_tip_id='+last_tip_id, (tip_check_interval-1), close_options, use_cache, debug );
			}
		}
		
		/*UPDATECHECK*/
		// For update checking
		if (options.get('check_for_updates')) {
			var t = time();
			var update_check_interval = options.get('update_check_interval');
			var show_update = options.get('show_update');
			var hrs_since_last_check = (t-options.get('last_update_check'))/ (1000*60*60);
			var use_cache = true;
			var debug = "<br>show_update="+show_update;
			debug += "<br>update_check_interval="+update_check_interval;
			debug += "<br>hrs_since_last_check="+hrs_since_last_check;
			if (show_update || (hrs_since_last_check > update_check_interval)) {

				if (hrs_since_last_check > update_check_interval) {
					options.set('last_update_check',time(),false);
					options.set('show_update',true,false);
					options.save();
					use_cache = false;
				}
				var check_version = version;
				if (options.get('version_ack') > version) {
					check_version = options.get('version_ack');
				}
				var beta_check = options.get('check_for_beta_updates');

				var close_options = {'close_pref':'check_for_updates', 'close_msg':'Are you sure you want to close this message and NOT get notifications of updates? This is NOT recommended! You may end up using an old version of Better Facebook that stops working correctly as Facebook changes!'};
				pagelet_box(feed_right_column,'bfb_update_pagelet','Better Facebook Update Available!','http://BetterFacebook.net/pagelet_update.php?update_type='+SCRIPT_TYPE+'&version='+check_version+'&beta='+beta_check, ((update_check_interval*60)-1), null, use_cache, debug );
			}
		}
		/*/UPDATECHECK*/		
		
	});

	// LEFT COLUMN CONTENT
	// ===================
	// This content is dependent on the "type-ahead" content being loaded, so do that right away
	function attachLeftColumnContent() {
		trace("attachLeftColumnContent()");
		var connections, connection_templates;
		
		var createNavSection = function(nav,id,title,type,allowedit,sortprop,processfunc,imgclass) {
			if ($('bfb_nav_'+id)==null) {
				var open = options.get(id+'_default_open');
				if (typeof open=="undefined" || open==null) {
					open = true;
				}
				var position = +options.get(id+'_position') || 2;
				var max_height = options.get(id+'_max_height') || 5000;
				var h4 = el('h4',null,null,null,title);
				h4.id = "bfb_nav_title_"+id;
				bind(h4,'click',function() { toggle('bfb_nav_content_'+id,id+'_default_open'); });
				h4.style.cursor = "pointer";
				var d = el('div','clearfix uiHeader uiHeaderNav uiHeaderTopBorder',{innerHTML: _template('<div id="bfb_nav_%1%" class="lfloat"></div><div class="rfloat" id="bfb_nav_rfloat_%1%"></div><ul class="uiSideNav uiSideNavSection uiFutureSideNavSection bfb_uiSideNav" id="bfb_nav_content_%1%" style="max-height:%4%px;overflow-y:auto;overflow-x:hidden !important;%3%"></ul>',id,title,(open?"":"display:none;"),max_height ) });
				append(d.firstChild,h4);
				insertAtPosition(nav,d,position);
				if (allowedit) {
					var rfloat = $('bfb_nav_rfloat_'+id);
					if (rfloat) {
						var a_id = 'bfb_nav_edit_'+id;
						var a = el('a',null,{id:a_id,innerHTML:'edit'},{click:function(e){editNavSection(e,id,type,sortprop,processfunc,imgclass);}});
						append(rfloat,a);
					}
				}
				return $('bfb_nav_content_'+id);
			}
		};
		
		var getConnectionsByType = function(type,sorted,sortprop) {
			var list = [];
			sortprop = sortprop || "t";
			for (var i=0; i<connections.length; i++) {
				var c = connections[i];
				if (c && c.ty && c.ty==type) { list.push(c); }
			}
			if (sorted) {
				list = list.sort( function(a,b) { if (a&& typeof a[sortprop]!="undefined" &&a[sortprop].toLowerCase){a=a[sortprop].toLowerCase();} if (b&&b[sortprop]&&b[sortprop].toLowerCase){b=b[sortprop].toLowerCase();} return (a>b)?1:-1; } );
			}
			return list;
		};
		
		var imgClassCache = {};
		var createNavLink = function(title,url,imgsrc,imgclass,target,count,count_id) {
			var img='', hasimg=false;
			if (imgclass) {
				if (typeof imgClassCache[imgclass]!="undefined") {
					imgclass = imgClassCache[imgclass];
				}
				else if (document.querySelectorAll) {
					// imgclass will now be the id of an element on the page whose icon we will steal by matching class names
					var i = document.querySelectorAll('#'+imgclass+' span.imgWrap i');
					if (i && i.length) {
						imgClassCache[imgclass] = i[0].className;
						imgclass = i[0].className;
					}
				}
				img = '<span class="imgWrap"><i class="'+imgclass+'"></i></span>';
				hasimg = true;
			}
			else if (imgsrc) {
				img = '<span class="imgWrap"><img src="'+imgsrc+'" height=16 width=16></span>';
				hasimg = true;
			}
			count = (typeof count!="undefined")?'<span class="count blue-bubble-float-right uiSideNavCount"><span class="countValue fss" id="'+(count_id?count_id:'')+'">'+count+'</span><span class="maxCountIndicator"></span></span>':'';
			return _template('<a class="item %5%" title="%7%" href="%2%" target="%4%">%6%<div class="clearfix">%1%<span class="linkWrap">%3%</span></div></a>',img,url,title,target,hasimg?"":"noimg",count,htmlescape(title) );
		};
		
		var createNavListItem = function(title,url,imgsrc,imgclass,target,count,count_id) {
			return "<li class=\"sideNavItem\">"+createNavLink(title,url,imgsrc,imgclass,target,count,count_id)+"</li>";
		};
		
		var createConnectionSection = function(nav,type,id,title,allowedit,sortprop,processfunc,imgclass) {
			if (!connection_templates || !connection_templates[type]) { return; }
			trace("Creating "+title);
			var target = options.get(id+'_new_window')?"_blank":"";
			var template = connection_templates[type].default_url;
			var content = createNavSection(nav,id,title,type,allowedit,sortprop,processfunc,imgclass);
			if (content) {
				var count = populateConnectionSection(content,id,type,sortprop,processfunc,imgclass);
				var h4 = $('bfb_nav_title_'+id);
				if (h4) { h4.innerHTML += ' <span id="bfb_nav_count_'+id+'" class="countValue">('+count+')</span>'; }
			}
		};
		
		var populateConnectionSection = function(container,id,type,sortprop,processfunc,imgclass) {
			if (!connection_templates || !connection_templates[type]) { return; }
			var h = "";
			var target = options.get(id+'_new_window')?"_blank":"";
			var template = connection_templates[type].default_url;
			var items = getConnectionsByType(type,true,sortprop);
			var hidden_connections = options.get('hidden_connections') || {};
			var count = 0;
			if (processfunc) {
				ret = processfunc(items);
				h += ret.html;
				count = ret.count;
			}
			else {
				for (var j=0; j<items.length; j++) {
					var item = items[j], url = template.replace(/%#?/,item.i);
					if (!hidden_connections || !hidden_connections[type] || !hidden_connections[type][item.i]) {
						if (item.t) {
							count++;
							h += createNavListItem(item.t,url,item.it,imgclass,target);
						}
					}
				}
			}
			html( container, h );
			return count;
		};
		
		var editNavSection = function(e,id,type,sortprop,processfunc,imgclass) {
			var edit_link = $('bfb_nav_edit_'+id);
			var content = $('bfb_nav_content_'+id);
			var hidden_connections = options.get('hidden_connections') || {};
			if (typeof hidden_connections[type]=="undefined") {
				hidden_connections[type] = {};
			}
			
			if (edit_link.innerHTML == 'edit') {
				html( edit_link, 'save' );
				edit_link.style.backgroundColor = 'yellow';
				
				html( content, "" );
				var items = getConnectionsByType(type,true,sortprop);
				for (var j=0; j<items.length; j++) {
					var item = items[j];
					if (item.t) {
						var hidden = !!hidden_connections[type][item.i];
						var input = el('input',null,{type:'checkbox',value:item.i,'checked':!hidden},{click:function(){
							hidden_connections[type][this.value] = !this.checked;
							options.set('hidden_connections',hidden_connections);
						}});
						var div = el('div',null,{innerHTML:item.t});
						insertFirst(div,input);
						append(content,div);
					}
				}
			}
			else if (edit_link.innerHTML == 'save') {
				html( edit_link, 'edit' );
				edit_link.style.backgroundColor = '';
				options.save();
				var count = populateConnectionSection(content,id,type,sortprop,processfunc,imgclass);
				var count_span = $('bfb_nav_count_'+id);
				if (count_span) {
					html( count_span, "("+count+")" );
				}
			}
			
		};

		// Only insert left nav sections on the home screen
		if (!QS(document,'body.home')) { return; }
		
		// Insert some new navigation links
		onIdLoad('leftCol',function(nav) {
			trace("Inserting side navigation items");
			try {
				var container = QS(nav,'.uiSideNav');
				if (container) {
					if (options.get('show_nav_all_connections')) {
						append(container, el('li','sideNavItem stat_elem',null,null,createNavLink('All Connections','/friends/?filter=ac',null,'navItem_ff','')) );
					}
					if (options.get('show_nav_edit_friends')) {
						append(container, el('li','sideNavItem stat_elem',null,null,createNavLink('Edit Friend Lists','/friends/?filter=afp',null,'navItem_ff','')) );
					}
					if (options.get('show_nav_write_a_note')) {
						append(container, el('li','sideNavItem stat_elem',null,null,createNavLink('Write A Note','/editnote.php?new',null,'navItem_2347471856','_blank')) );
					}
					if (options.get('show_nav_pages_i_admin')) {
						append(container, el('li','sideNavItem stat_elem',null,null,createNavLink('Pages I Admin','/pages/manage/',null,'navItem_app_2309869772','')) );
					}
					if (options.get('show_nav_unblock_applications')) {
						append(container, el('li','sideNavItem stat_elem',null,null,createNavLink('Unblock Applications','/settings/?tab=privacy&section=applications&field=blocked_apps',null,'navItem_apps','')) );
					}
				}
			}
			catch (e) { showexception(e); }
		});
		
		get_remote_content('typeahead',function(response) {
			try {
				if (response) {
					var json = parse(response.substring(9),"Typeahead content");
					if (json.payload) {
						connections = json.payload.entries;
						connection_templates = json.payload.templates;
					}
					else { 
						trace("Payload not found in connections!"); 
						connections = null;
						return false;
					}
					if (connections) {
						if (connections.length==0) {
							trace("ERROR: 3rd Party cookies probably not allowed!");
						}
						trace("Making sure left column exists before continuing...");
						onIdLoad('leftCol',function(nav) {
							trace("leftCol loaded");
							// The new left nav sections need to be inserted in the ascending order of their positions
							var sections = [];
							if (options.get('show_my_pages')) { sections[+options.get('my_pages_position')||99] = function() { createConnectionSection(nav,'p','my_pages','My Pages',true); }; }
							if (options.get('show_my_events')) { sections[+options.get('my_events_position')||99] = function() { createConnectionSection(nav,'e','my_events','My Events',true,null,null,'navItem_events'); };}
							if (options.get('show_my_groups')) { sections[+options.get('my_groups_position')||99] = function() { createConnectionSection(nav,'g','my_groups','My Groups',true,null,null,'navItem_2361831622'); };}
							if (options.get('show_my_apps')) { sections[+options.get('my_apps_position')||99] = function() { createConnectionSection(nav,'a','my_apps','My Apps',true,null,null,'navItem_apps'); };}
							// Now run through the array of functions created to run them in order
							for (var i=0; i<sections.length; i++) {
								if (sections[i]) { sections[i](); }
							}
						});
					}
				}
			} catch (e) { showexception(e); }
		});
	}
	try { attachLeftColumnContent(); } catch(e) { showexception(e); }

	// ========================================================
	// Version/Update/Wizard Checks
	// ========================================================
	function show_wizard(msg,data) {
		// Data should hold an array of wizard steps to show the user
		if (data.length>0) { // Intro step + "done" step are required
			(function() {
				var total_steps = data.length;
				var current_step = 1;
				var current_dialog = null;
				var show_step = function(step_number) {
					var step_data = data[step_number-1];
					var content = step_data.content;
					if (options) {
						options.options.forEach(function(opt,i) {
							if (opt.name) {
								content = content.replace( new RegExp("%"+opt.name+"%","g"), options.renderOption(opt));
							}
						});
					}
					var save_wizard_prefs = function() {
						var inputs = current_dialog.querySelectorAll('input');
						for (var i=0; i<inputs.length; i++) {
							var e = inputs[i];
							if (e.name) {
								if (e.type=="checkbox") { options.set(e.name,e.checked,false); }
								else if (e.type=='text') { options.set(e.name,e.value,false); }
								}
						}
					}
					var next_button = function() {
						save_wizard_prefs();
						options.save();
						removeChild(getParentByClass(this,'bfb_dialog'));
						show_step(++current_step); 
					}
					var back_button = function() {
						save_wizard_prefs();
						options.save();
						removeChild(getParentByClass(this,'bfb_dialog'));
						show_step(--current_step); 
					}
					var done_button = function() {
						save_wizard_prefs();
						options.set('version',version,false);
						options.save(function() {
							try { window.location.reload(true); } catch(e){}
						});
					}
					var cancel_button = function() {
						if (confirm('Cancel Wizard?\n(You can run this again using the link in Options)')) {
							removeChild(getParentByClass(this,'bfb_dialog'));
							options.set('version',version);
						}
					}
					var footer = el('div');
					if (current_step>1) { append(footer,button( '<-- Back',back_button,'better_fb_close')); }
					append(footer,button( 'Cancel',cancel_button,'better_fb_close'));
					if (current_step<total_steps) { append(footer,button( 'Next -->',next_button,'better_fb_close')); }
					else { append(footer,button( 'Done',done_button,'better_fb_close')); }
					current_dialog = show_dialog(content,"Better Facebook "+((installed_version>0 && installed_version<version)?"Update":"Setup")+" Wizard ("+(step_number)+" of "+(total_steps)+")",null,null,footer);
				};
				show_step(current_step);
			})();
		}
		else {
			options.set('version',version);
		}
	}
	guided_setup_action = function() { rpc("wizard",{current_version:0,upgrade:false},show_wizard); }
	var installed_version = options.get("version");
	if (installed_version==0) {
		rpc("wizard",{current_version:0,upgrade:false},show_wizard);
	}
	else if (options.get('show_version_changes') && installed_version<version) {
		// Display a message if the user has upgraded to the latest version
		rpc("wizard",{current_version:installed_version,new_version:version,upgrade:true},show_wizard);
	}

	function better_fb_options(tab_id) {
		options.displayOptions(tab_id);
	}

	// ==================================================================
	// Fix the "Home" links so they go to /
	// ==================================================================
	if (options.get('fix_logo2')) { 
		document.addEventListener('click', function(e){ 
			var t = target(e);
			if ( (t.parentNode && "pageLogo"==t.parentNode.id) || (t.accessKey=="1") || (t.parentNode && t.parentNode.parentNode && "navItem_nf"==t.parentNode.parentNode.id) ) { 
				if (typeof e.button=="undefined" || e.button==0) {
					e.stopPropagation(); e.preventDefault(); 
					var url = options.get('home_url');
					if (url=="/" && window_href.indexOf("apps.")>-1) {
						url = protocol+"//www.facebook.com";
					}
					window.location.href=url; 
				}
			} 
		}, true);
	}

	// ==================================================================
	// Auto-expand Apps
	// ==================================================================
	if (options.get('expand_nav_apps')) {
		bind(window,'load',function() {
			onIdLoad("bookmarks_menu",function(bm) {
				if (bm.querySelector) {
					setTimeout( function(){clickLink(bm.querySelector(".navMoreLess .navMoreText"));}, 1000);
				}
			});
		});
	}

	// ==================================================================
	// Show some help if on the BFB Page
	// ==================================================================
	if (options.get('show_page_post_message')) {
		onIdLoad('profile_stream_composer',function(composer) {
			if ($('bfb_page_post_message')==null) {
				var retries = 10;
				var insert_message = function() {
					var page_id = QS(document,'input[name="user_id"],input[name="xhpc_targetid"],input[name="targetid"]','value');
					if (!page_id && --retries>0) { setTimeout(insert_message,500); return; }
					if (page_id && (page_id=="174424289341" || page_id=="119314224763738")) { // BFB, BFB Dev
						rpc('page_post_help',{page:page_id},function(message,data) {
							if (data.message && !($('bfb_page_post_message'))) {
								var insertPoint = QS(composer,'.showOnceInteracted');
								insertFirst( insertPoint, el('div','bfb_page_post_message',{id:'bfb_page_post_message'},null,data.message) );
								bind($('bfb_page_post_message_help'),'click',function() { show_help(); });
							}
						});
					}
				};
				insert_message();
			};
		});
	}

	// ==================================================================
	// REMOVE RECENT ACTIVITY
	// ==================================================================
	if (options.get('remove_recent_activity') || options.get('auto_remove_recent_activity')) {
		var show_message = options.get('show_remove_recent_activity_message');
		var duration = options.get('remove_recent_activity_message_duration');
		onSelectorLoad('.UIRecentActivity_Header, .uiStreamMinistoryGroup .header',function(o) {
			var auto = options.get('auto_remove_recent_activity');
			var handler = function() {
				var total_removed = 0;
				QSA(o.parentNode,'.uiCloseButton',function(cb) {
					var ajaxify = cb.getAttribute('ajaxify');
					var li = getParentByClass(cb,'uiUnifiedStory');
					var msg = QS(li,'.uiStreamMessage[data-ft]');
					// If there is meta-data associated with this sntry, check it
					if (msg) {
						var dataft = msg.getAttribute('data-ft');
						if (dataft) {
							dataft = JSON.parse(dataft);
							if (dataft && 47==dataft.sty && 174424289341==dataft.object_id) {
								trace("Found Recent Activity of liking BFB. Did not remove.");
								return;
							}
						}
					}
					// Figure out what kind of Recent Activity this is
					if (ajaxify) {
						var m = ajaxify.match(/story_type=(\d+)/i);
						if (m && m.length>0) {
							var sty = m[1];
							// Check to see if we should remove this type of story
							if (sty==20) { if (!options.get('remove_recent_activity_write_on_wall')) { return; } }
							else if (sty==107) { if (!options.get('remove_recent_activity_comment_on_status')) { return; } }
							else if (sty==46) { if (!options.get('remove_recent_activity_comment_on_photo')) { return; } }
							else if (sty==47) { if (!options.get('remove_recent_activity_like_page')) { return; } }
							else if (sty==32) { if (!options.get('remove_recent_activity_comment_on_link')) { return; } }
							else if (sty==21) { if (!options.get('remove_recent_activity_added_friend')) { return; } }
							else if (sty==3) { if (!options.get('remove_recent_activity_relationship_change')) { return; } }
							else { if (!options.get('remove_recent_activity_added_other')) { return; } }
						}
					}
					if (ajaxify && !QS(li,".reportHide") && (ajaxify.indexOf("remove_content")>0 || ajaxify.indexOf("action_key=remove_content")>0)) {
						var data = {
							'__a':1,
							'fb_dtsg':$Env('fb_dtsg'),
							'ministory_key':url_param(ajaxify,'ministory_key'),
							'post_form_id':$Env('post_form_id'),
							'post_form_id_source':'AsyncRequest',
							'profile_fbid':url_param(ajaxify,'profile_fbid'),
							'story_type':url_param(ajaxify,'story_type')
						};
						li.style.opacity=.5;
						var remove_url = url_prefix+'/ajax/minifeed.php';
						trace("Removing recent activity: "+remove_url);
						ajax({'method':'POST',headers:{'Cache-Control':'no-cache'},'url':remove_url,'data':encode_url_params(data),'onload':function(res) {
							var story_text = QS(li,'.ministoryMessage,.UIRecentActivity_Body','innerHTML');
							if (res && res.responseText && res.responseText.indexOf('"success":1')>0) {
								if (show_message) {
									quickmessage("Recent Activity removed: "+story_text,duration);
								}
								var body = QS(li,'.uiStreamMessage, .UIRecentActivity_Body');
								if (body && !options.get('erase_after_recent_activity_remove')) {
									li.style.opacity=1;
									li.style.textDecoration="line-through";
									body.style.textDecoration="line-through";
								}
								else {
									removeChild(li);
								}
							}
							else {
								if (!res) { trace("Recent Activity removal error: No response!"); }
								if (res && !res.responseText) { trace("Recent Activity removal error: No responseText!"); }
								li.style.backgroundColor='red';
								li.style.opacity=1;
								var remove_url_with_params = remove_url+'?'+encode_url_params(data);
								var cookies_msg = "";
								if (res.responseText && res.responseText.toLowerCase() && res.responseText.toLowerCase().indexOf("not logged in")>-1) {
									cookies_msg = "<br><div style=\"border:1px solid white;\"><b>This may be caused by 3rd party cookies being disabled in your browser! Please enable to let this feature work!<br>See <a href=\"http://betterfacebook.net/faq.php#3rdpartycookies\">this FAQ entry</a></b></div><br>";
								}
								quickmessage("Error removing Recent Activity: "+story_text+cookies_msg+"<br><div style=\"font-size:10px;background-color:#eee;font-family:arial;max-height:100px;overflow:auto;color:black;\">(data-ft:"+msg.getAttribute('data-ft')+")<br>The request sent was:<br><a href=\""+remove_url_with_params+"\">"+remove_url_with_params+"</a><br>The response from the server was:<br>"+res.status+":"+htmlescape(res.responseText)+"</div>",20,{backgroundColor:'#cc3333',color:'white'});
							}
						}});
						total_removed++;
					}
					else {
						if (!ajaxify) { trace("Recent Activity removal error: ajaxify attribute on X"); }
						if (QS(li,".reportHide")) { trace("Recent Activity removal error: reportHide element found under X"); }
						if (ajaxify.indexOf("remove_content%5D=1")<0) { trace("Recent Activity removal error: ajaxify attribute does not have remove_content section:"+ajaxify); }
						trace(li.innerHTML);
					}
				});
			}
			if (auto) { setTimeout( function() { handler(o); }, 10); }
			else if (QS(o.parentNode,'.uiCloseButton')) {
				append(o,el('a',null,null,{click:handler},' - remove all activity'));
			}
		},true);
	}

	// ==================================================================
	// Change CHAT images to NAME
	// ==================================================================
	if (options.get('chat_images_to_names')) {
		watchDOMNodeInserted('.fbChatMessageGroup .img',function(img) {
			var name=img.title;
			if (name) {
				img.style.display='none';
				img.parentNode.style.cssFloat = 'none';
				insertAfter(el('div','bfb_chat_name',null,null,name),img);
			}
		});
		onSelectorLoad('.uiFacepileItem',function(fp) {
			if (getParentByClass(fp,'fbFriendsOnlineFacepile')==null) { return; }
			QSA(fp,'a',function(friend) {
				var name = QS(friend,'span.uiTooltipText','innerHTML');
				if (name) {
					html(friend,name);
					friend.style.display="block";
					friend.parentNode.style.cssFloat = 'none';
					if (hasClass(fp,'chatIdle')) {
						friend.style.fontStyle="italic";
						friend.style.color="#627AAD";
					}
				}
			});
		});
	}

	// ========================================================
	// Image Hover Previews
	// ========================================================
	if (options.get('show_image_previews')) {
		var image_preview = null;
		var img_image_preview = null;
		var image_preview_loading = null;
		var image_preview_link = null;
		var image_preview_target = null;
		var image_preview_caption = null;
		var image_preview_delay = +(options.get('image_preview_delay')||0) * 1000;
		var image_preview_click = function(){ 
			if (image_preview_link) {
				try{ window.location.href=image_preview_link; }
				catch(e){}
			}
		};
		var last_preview_src = null;
		var capture = true;
		bind(document,'mouseover',function(e) {
			image_preview_target = target(e);
			var delayed_image_preview_target = image_preview_target;
			var tn = image_preview_target.tagName;
			var src = null;
			if (tn && (tn=="IMG" || tn=="I")) {
				var src=null;
				var preview_src = null;
				if (tn=="IMG") {
					src = image_preview_target.src;
				}
				else if (tn=="I" && image_preview_target.style && image_preview_target.style.backgroundImage) {
					src = image_preview_target.style.backgroundImage.replace(/^\s*url\s*\(\s*['"]?/,'').replace(/(\.jpg)['"]?.*$/,'$1');
				}
				// See if the parent node is a link to go to the actual pic
				if (/s320x320/.test(src)) {
					preview_src = src.replace(/s320x320/,"s720x720");
				}
				else if (/\d+\/[aqts][\d_]+\.jpg/.test(src)) {
					preview_src = src.replace(/(\d+)\/[asqt]([\d_]+\.jpg)/,"$1/n$2");
				}
				else if (/\d+_([asqt])\.jpg/.test(src)) {
					preview_src = src.replace(/(\d+)_([astq])\.jpg/,"$1_n.jpg");
				}
				else if (/safe_image.php/.test(src)) {
					preview_src = url_param(src,"url");
				}
				else if (/app_full_proxy.php/.test(src)) {
					preview_src = url_param(src,"src");
				}
				if (preview_src) {
					setTimeout(function() {
						if (delayed_image_preview_target!=image_preview_target) { return; }
						var pa = getParentByTag(image_preview_target,"a");
						if (pa && pa.href && pa.href!="#") {
							image_preview_link = pa.href;
							var image_preview_caption_text = pa.title || "";
						}
						else {
							image_preview_link = null;
						}
						if (!image_preview) {
							image_preview = el('div','bfb_image_preview');
							image_preview_loading = el('div','bfb_image_preview_msg',null,null,'Loading preview...');
							append(image_preview,image_preview_loading);
							img_image_preview = el('img','bfb_image_preview_img bfb_window_height100',{'src':preview_src});
							img_image_preview.style.display="none";
							bind(img_image_preview,'load',function(){image_preview_loading.style.display="none";img_image_preview.style.display="block";});
							bind(img_image_preview,'click',image_preview_click);
							append(image_preview,img_image_preview);
							append(document.body,image_preview);
							last_preview_src = preview_src;
						}
						else {
							image_preview.style.display="block";
							if (preview_src!=last_preview_src) {
								image_preview_loading.style.display="block";
								img_image_preview.style.display="none";
								img_image_preview.src = preview_src;
							}
							last_preview_src=preview_src;
						}
						if (image_preview_link) {
							image_preview.title="Click to go to Image";
							image_preview.style.cursor = "pointer";
						}
						else {
							image_preview.title="";
							image_preview.style.cursor = "";
						}
					},image_preview_delay);
				}
			}
			else if (image_preview_target!=image_preview && image_preview_target!=img_image_preview) {
				if (image_preview!=null) {
					image_preview.style.display="none";
				}
				image_preview_target = null;
			}
		},capture);
	}
	
	// ========================================================
	// Fix Comments
	// ========================================================
	if (options.get('fix_comments')) {
		onSelectorLoad('textarea.enter_submit',function(ta) {
			if (!parent(ta,'.tickerDialogContent') && !parent(ta,'.uiContextualDialog')) {
				removeClass(ta,'enter_submit');
			}
		},'both');
	}
	
	// ========================================================
	// Reply To Comments
	// ========================================================
	if (options.get('comment_reply')) {
		(function() {
			var float_textarea = options.get('comment_reply_float_textarea');
			var first_name_only = options.get('comment_reply_first_name_only');
			
			var restore_textarea = function() { if(!add_comment){return;} removeClass(add_comment,"bfb_floating_comment"); add_comment.style.left = add_comment.style.top = ""; add_comment=null; }
			var last_reply_text = null;
			var selected_text = null;
			var restore_ta = true;
			var comment = null, add_comment = null;
			bind(document,'keydown',function(e) { if(e.keyCode==27) { removeClass(comment,"bfb_reply_active_comment"); restore_textarea(); } })
			var do_reply = function(e) {
				var a = target(e), text;
				var new_comment = getParentByClass(a,'uiUfiComment');
				var replying_to_same_comment = (new_comment==comment);
				comment = new_comment;
				var post = parent(a,'.uiUnifiedStory,.mall_post,#photocomment');
				if (!post) { 
					post = parent(a,'form.commentable_item');
					if (!post) { return; }
				}
				QS(post,'.uiUfiAddComment',function(ac) {
					add_comment = ac;
					if (float_textarea) {
						var anchor_position = offset(a);
						var offsetparent_position = offset(post);
						addClass(ac,"bfb_floating_comment");
						var left = anchor_position.left - 50;
						var top = anchor_position.top + 12;
						if (current_style(post,'position')!="static") {
							left = left - offsetparent_position.left;
							top = top - offsetparent_position.top;
						}
						ac.style.left = left+"px";
						ac.style.top = top+"px";
					}
					var actor_name = QS(comment,'.actorName','innerHTML');
					if (first_name_only) {
						actor_name = actor_name.replace(/\s.*/,'');
					}
					text = replying_to_same_comment ? '' : '@'+actor_name+': ';
					var quoted = false;
					if (selected_text && selected_text.replace) {
						// "Quote" text
						quoted = true;
						selected_text = selected_text.replace(/([^\n]{45,45}.*?\s)/gm,"$1\n");
						selected_text = selected_text.replace(/^/gm,"> ");
						if (trim(selected_text).length>0) {
							text += (replying_to_same_comment?"":"\n")+selected_text+"\n\n";
						}
					}
					QS(ac,'textarea',function(ta) { 
						addClass(comment,"bfb_reply_active_comment bfb_reply_commented");
						ta.focus();
						var wait_for_focus = function() {
							if (hasClass(ta,'DOMControl_placeholder')) {
								setTimeout( wait_for_focus,100 );
								return;
							}
							if (!last_reply_text || text!=last_reply_text) {
								var prefix = "";
								if (ta.value=="") { 
									//if (quoted) { prefix = " \n"; }
								}
								else { prefix = "\n\n"; }
								ta.value = ta.value+prefix+text;
							}
							last_reply_text = text;
							setCaretToPos(ta,ta.value.length);
							press_key(ta,' ','keydown');
						}
						wait_for_focus();
						var comment_box = getParentByClass(ta,'commentBox');
						if (comment_box && !QS(ac,'.bfb_reply_note_first')) {
							insertAfter( el('div','bfb_reply_note bfb_reply_note_first',null,null,'<input type="checkbox" style="height:10px;width:10px;padding:0;" tabindex="-1" class="comment_reply_first_name_only" '+(first_name_only?'checked':'')+'>Reply with first names only'), comment_box );
							QS(ac,'.comment_reply_first_name_only',function(a) {
								bind(a,'click',function(){ 
									first_name_only=!first_name_only;
									if (first_name_only) {
										ta.value = ta.value.replace(/(\@\w+)(\s+[^:]+):/g,"$1:");
									}
									options.set('comment_reply_first_name_only',first_name_only);
								}); 
							});
						}
						if (float_textarea) {
							if (comment_box && !QS(ac,'.bfb_reply_note_esc')) {
								insertAfter( el('div','bfb_reply_note bfb_reply_note_esc',null,null,'(Press Esc to return comment box to its original location) <a class="bfb_stop_floating" style="text-decoration:underline;" tabindex="-1" href="#">Disable floating replies</a>'), comment_box );
								QS(ac,'.bfb_stop_floating',function(a) {
									bind(a,'click',function(){ 
										restore_ta=false; 
										if(confirm('Click OK to stop the reply comment boxes from floating up to the comment being replied to. Clicking Reply will move you down to the comment entry box instead.')){ 
											restore_textarea(); 
											options.set('comment_reply_float_textarea',false); 
										}
										restore_ta = true;
									}); 
								});
							}
							// When submitted, re-dock the reply
							bind(QS(ac,'.enter_submit_target'),'click', function() { restore_textarea(); } );
						}
					});
				});
			}
			onSelectorLoad('.commentActions',function(ca) { 
				if (!QS(ca,'.bfb_reply_link')) {
					ca.addEventListener('mousedown',function(){ try{ selected_text=window.getSelection(); if (selected_text && selected_text.getRangeAt) { selected_text = selected_text.getRangeAt(0); if(selected_text) { selected_text = selected_text.toString(); } } }catch(e){} },true);
					var reply = el('a','bfb_reply_link',null,{click:do_reply},'Reply');
					append(ca,reply);
				}
			},"both");
		})();
	}
	
	// ========================================================
	// Undo
	// ========================================================
	var undo_posts = [];
	function undo() {
		if (undo_posts.length==0) {
			alert("Nothing to undo!");
			return;
		}
		for (var i=0; i<undo_posts.length; i++) {
			var post = undo_posts[i];
			var fbid = post.fbid;
			var o = post.post;

			options.set('story_data.'+fbid,parse(post.post_data),false);
			removeClass(o,"bfb_read");
			removeClass(o,"bfb_new_comments");
			
			if (post.type=="mute") {
				removeClass(o,"bfb_muted");
			}
			addClass(o,"bfb_undid");
			(function(o2){
				setTimeout( function() { removeClass(o2,"bfb_undid"); }, 3000 );
			})(o);
		}
		undo_posts = [];
		options.save();
	}
	if (options.get('undo_ctrl_z')) {
		bind(document,'keydown',function(e) {
			var t = target(e);
			if (t.tagName && (t.tagName=="TEXTAREA" || t.tagName=="INPUT")) { return; }
			if (e.ctrlKey && e.keyCode==90) { undo(); }
		});
	}
	
	// ========================================================
	// Auto-expand all Questions comments
	// ========================================================
	if (options.get('auto_expand_questions_comments')) {
		onSelectorLoad('#fbQuestionRepliesPager a.uiMorePagerPrimary',function(a) {
			clickLink(a);
		});
	}

	// ========================================================
	// Anonymize Screens
	// ========================================================
	if (options.get('enable_anonymize')) {
		onIdLoad('pageNav',function(nav) {
			if (!$('bfb_anonymize_screen')) {
				var a = el('a',null,{href:'#',title:'Change the screen to anonymize all users (for screenshots, etc)',id:'bfb_anonymize_screen'},{
					click:function() { 
						var namehash = {};
						var namecount = 1;
						var grouphash = {};
						var groupcount = 1;
						var eventhash = {};
						var eventcount = 1;
						QSA(document,'.uiProfilePhoto,.profilePic,img.bfb_friend_activity_img,.UIImageBlock_MED_Image img,#navAccountPic img',function(i) {
							if (i.parentNode && i.parentNode.href && i.parentNode.href.indexOf("photo.php")>=0) { return; } // photo, not profile pic
							if (i.src && i.src.indexOf("external.ak.fbcdn")>=0) { return; } // External img
							i.src=protocol+"//profile.ak.fbcdn.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif";
						});
						QSA(document,'.actorName a,a.actorName,a.ego_title,span.blueName,a.passiveName,.fbxWelcomeBoxName,*[data-hovercard*="user"],a[href*="/profile.php"],#navAccountName',function(o) {
							if (QS(o,'img')){return;}
							var c = o.innerHTML;
							if (!namehash[c]) { namehash[c] = "FBUser #"+(namecount++); }
							html(o,'');
							append(o,document.createTextNode(namehash[c]));
						});
						// Loop through stored friends list to see if there are any links left on the page
						var friends = options.get('friend_tracker');
						if (friends) {
							var names = {};
							friends = friends.friends;
							if (friends) {
								for (var id in friends) { names[friends[id].name] = true; }
								QSA(document,'*',function(a) {
									if (names[a.innerHTML]) {
										var c = trim(a.innerHTML);
										if (!namehash[c]) { namehash[c] = "FBUser #"+(namecount++); }
										html(a,'');
										append(a,document.createTextNode(namehash[c]));
									}
								});
							}
						}
						QSA(document,'#groupSideNav .linkWrap, #bfb_nav_content_my_groups span:last-child',function(o) {
							var c = o.innerHTML;
							if (!grouphash[c]) { grouphash[c] = "Group #"+(groupcount++); }
							html(o,'');
							append(o,document.createTextNode(grouphash[c]));
						});
						QSA(document,'#bfb_nav_content_my_events span:last-child',function(o) {
							var c = o.innerHTML;
							if (!eventhash[c]) { eventhash[c] = "Event #"+(eventcount++); }
							html(o,'');
							append(o,document.createTextNode(eventhash[c]));
						});
						clickLink($('navAccountLink'),true);
						return false; 
					}
				},'Anonymize Screen');
				var li = el('li');
				append(li,a);
				var ul = QS(nav,'ul[role="navigation"]');
				if (ul) {
					sticky_note(li,'left','Better Facebook lets you "anonymize" your screen to share screenshots with privacy. To go back to normal, reload the page.','anonymize_screen',null,{width:'400px',top:0,marginRight:'-2px'},{backgroundColor:'#ffa'});
					insertAtPosition(ul,li,-1);
				}
			}
		});
	}
	
	// ========================================================
	// Make elements Hideable
	// ========================================================
	bind(window,'click',function() {
		QSA(document,'.bfb_show_menu',function(o) { removeClass(o,'bfb_show_menu'); });
	});
	function make_hideable(selector,friendly_name,pref,inverse) {
		onSelectorLoad(selector,function(o) {
			add_hideable(o,friendly_name,pref,inverse);
		});
	}
	function add_hideable(o,friendly_name,pref,inverse,frame_element,top,left) {
		if (pref && (!inverse && options.get(pref)) || (inverse && !options.get(pref)) ) { hide(o); return; }
		if (typeof hidden_elements[friendly_name]!="undefined") { hide(o); return; }
		if (typeof hidden_elements_x[friendly_name]!="undefined") { return; }
		addClass(o,'bfb_hideable');
		var position = current_style(o,'position');
		bind(o,'mouseover',function() { 
			if (position!="relative" && position!="absolute" && position!="fixed") {
				o.style.position="relative";
			}
		});
		bind(o,'mouseout',function() {
			o.style.position='';
		});
		var hide_x = el('div','bfb_hide_el',null,

		{'click':function(e){
			e.stopPropagation();
			e.preventDefault();
			var item = target(e);
			if (hasClass(item,'bfb_hide_section')) {
				removeClass(hide_x,'bfb_show_menu');
				if (confirm('Are you sure you want to hide "'+friendly_name+'"?\nTo show it again, go into Options->Hidden and enable it')) {
					if (pref) {
						options.set(pref,!inverse);
					}
					else {
						if (hidden_elements_string.length>0){ hidden_elements_string+= ","; }
						hidden_elements_string += friendly_name;
						options.set('hidden_elements',hidden_elements_string);
					}
					remove_frame(o);
					hide(o);
				}
			}
			else if (hasClass(item,'bfb_hide_x')) {
				removeClass(hide_x,'bfb_show_menu');
				if (hidden_elements_x_string.length>0){ hidden_elements_x_string+= ","; }
				hidden_elements_x_string += friendly_name;
				options.set('hidden_elements_x',hidden_elements_x_string);
				remove_frame(o);
				removeChild(hide_x);
			}
			else {
				toggleClass(hide_x,'bfb_show_menu');
			}
		},'mouseover':function(e) {
			add_frame((frame_element || o),top,left);
		},'mouseout':function(e) {
			remove_frame(o);
		}
		},'',{'position':'absolute','top':'0px','right':'0px','border':'1px solid black;','zIndex':999});
		
		var hide_menu = el('div','bfb_hide_menu',null,null,'<div class="bfb_item bfb_hide_section">Hide '+friendly_name+'</div><div class="bfb_item bfb_hide_x">Hide this "x"</div>');
		append(hide_x,hide_menu);
		
		append(o,hide_x);
	}
	function add_frame(o,top,left) {
		if (QS(o,'.bfb_frame')) { return; }
		var d = el('div','bfb_frame');
		d.style.width = (o.offsetWidth-4) + 'px';
		if (left) {
			d.style.left = left;
		}
		else {
			var padding_left = current_style(o,'padding-left');
			if (padding_left) {
				d.style.paddingLeft = "-" + padding_left;
			}
		}
		if (top) {
			d.style.top = top;
		}
		else {
			var padding_top = current_style(o,'padding-top');
			if (padding_top) {
				d.style.paddingTop = "-" + padding_top;
			}
		}
		d.style.height = (o.offsetHeight-4) + 'px';
		insertFirst(o,d);
	}
	function remove_frame(o) {
		removeChild(QS(o,'.bfb_frame'));
	}
	
	// Make some things hideable
	make_hideable('#pageNav a[href*="sk=ff"], #pageNav a[href*="/find-friends"]','Find Friends');

	// ========================================================
	// Undo link redirection
	// ========================================================
	if (options.get('prevent_link_redirection')) {
		window.addEventListener('mousedown',function(e){
			var a = parent(target(e),'a');
			if (a && a.tagName && a.tagName=="A" && a.removeAttribute) {
				a.removeAttribute('onmousedown');
			}
		},true);
	}

	// ========================================================
	// Tickers
	// ========================================================
	make_hideable('#pagelet_rhc_ticker .fbFeedTicker','Live Activity Ticker','hide_happening_now');
	make_hideable('#rightCol .fixedAux .canvasSidebar','Game Icon Sidebar','hide_game_sidebar');
	make_hideable('#rightCol .fixedAux .canvasTicker','Game Ticker','hide_game_ticker');
	
	// ========================================================
	// Chat
	// ========================================================
	subscribe('chat-options/initialized',function(a,chat_options){
		// Disable Sidebar
		if (options.get('chat_disable_sidebar')) {
			subscribe('sidebar/initialized',function(a,ChatSidebar){
				if (ChatSidebar && ChatSidebar.isViewportCapable && ChatSidebar.disable) {
					ChatSidebar.isViewportCapable = function(){return false;};
					ChatSidebar.disable();
				}
			});
		}

		// Force Offline
		if (options.get('chat_force_offline') && chat_options.sendVisibility) {
			chat_options.sendVisibility(false);
		}

		// Show all online users
		var order_by_online_status = options.get('chat_group_by_status');
		if (options.get('chat_show_all_online')) {
			subscribe('chat-display/loaded',function(a,display){
				var compact = options.get('chat_compact');
				onSelectorLoad('ul.fbChatOrderedList',function(list){ 
					list.style.display="none";
					var bfb_chat_list = null;
					var previous_status;
					var render_chat_item = function(id) {
						var uinfo = unsafeWindow.ChatUserInfos[id];
						var status = unsafeWindow.AvailableList.get(id);
						
						if (status==1) { status = 'idle'; }
						else if (status==3) { status='mobile'; }
						else { status='active'; }
						
						if (uinfo) {
							var style = '';
							if (order_by_online_status && previous_status!=null && status!=previous_status) {
								style = "border-top:1px solid #aaa;";
							}
							previous_status=status;
							var h = '<a style="'+style+'" class="clearfix" href="javascript:void(chatDisplay._focusTab('+id+'))" rel="ignore"><img class="pic" src="'+uinfo.thumbSrc+'"/><span class="name">'+uinfo.name+'</span><i class="status img sp_3xd8gf sx_94f6be"></i></a>';
							return el('li','item '+status,null,{click:function(){display._focusTab('+id+');}},h);
						}
						return null;
					};
					var update_chat_list = function() {
						if (!bfb_chat_list) {
							bfb_chat_list = el('ul','fbChatOrderedList bfb_chat_ordered_list'+(compact?' compact':''));
							append(list.parentNode,bfb_chat_list);
						}
						var ids = unsafeWindow.AvailableList.getAvailableIDs().sort( function(a,b) {
							try {
								var status_a = unsafeWindow.AvailableList.get(a);
								var status_b = unsafeWindow.AvailableList.get(b);
								if (!order_by_online_status || (status_a==status_b)) {
									// Sory by name
									return (unsafeWindow.ChatUserInfos[a].name < unsafeWindow.ChatUserInfos[b].name) ? -1: 1;
								}
								// Sort by status
								return (status_a > status_b) ? -1 : 1;
							}
							catch(e) { return 1; }
						} );
						html(bfb_chat_list,'');
						previous_status=null;
						for (var i=0; i<ids.length; i++) {
							var li = render_chat_item(ids[i]);
							if (li) { append(bfb_chat_list,li); }
						}
						resize_chat();
						// Update the count of users online
						var count = ids.length;
						var label = QS(document,'#fbDockChatBuddylistNub .fbNubButton .label');
						if (label) {
							var label_count = QS(label,'.count');
							if (!label_count) {
								label_count = el('span','count');
								append(label,label_count);
							}
							html(label_count,' (<strong>'+count+'</strong>)');
						}
					}
					var resize_chat = function() {
						var flyout = parent(bfb_chat_list,'.fbNubFlyout');
						var title = QS(flyout,'.fbNubFlyoutTitlebar');
						var body = QS(flyout,'.fbNubFlyoutBody');
						var footer = QS(flyout,'.fbNubFlyoutFooter');
						if (body && flyout && flyout.style && flyout.style.maxHeight && title && footer) {
							body.style.maxHeight = (parseInt(flyout.style.maxHeight) - (title.offsetHeight||0) - (footer.offsetHeight||0)) + 'px';
						}
						if (body) {
							body.style.minHeight="100px";
						}
					}
					bind(window,'resize',resize_chat);
					update_chat_list();
					subscribe(['buddylist/count-changed','buddlyist/availability-changed','buddylist/updated'], update_chat_list);

				},false);
			});
		}
		
		// Add an "Options" link to the chat title bar
		var title = QS(document,'#fbDockChatBuddylistNub .titlebarTextWrapper');
		if (title) {
			var a = el('a',null,null,{click:function(e){better_fb_options('bfb_t_chat');e.stopPropagation();}},'[options]',{'color':'white','cssFloat':'right','marginRight':'20px'});
			append(title,a);
		}
	});

	// ========================================================
	// Arbiter Logging
	// ========================================================
	if (false) {
		unsafeWindow.ArbiterMonitor = {
			record: function(type,i,c,a) {
				if ( unsafeWindow.console && type!='done' && !/^function_ext/.test(i) && !(/^bootload/.test(i)) && !(/^phase/.test(i)) ) {
					unsafeWindow.console.log('Arbiter Event:',type,i,c,a);
				}
			},
			customReport:function(){},initUE:function(){},getInternRef:function(){},
			pause:function(){}, 
			resume:function(){},
			initUA:function(){},
			getActFields:function(){}
		};
	}

	
	/*
	onIdLoad('DeleteConversation',function(o){
		$('MessagingShelf').appendChild(o);
	});
	onIdLoad('photoactions',function(o) {
		append(o,el('a',null,null,{click:function() {
			var src = $('myphoto').src;
			// Get the high-res if it exists?
			QS(document,'#photoactions a[href$=jpg]',function(j){ alert(j); src=j; });
addGlobalStyle('html:before { content:""; width:'+window.innerWidth+'px; height:'+window.innerHeight+'px; position:fixed; z-index:-1; top:0; bottom:0; left:0; right:0; background:url('+src+'); -moz-background-size:100%; background-repeat:repeat; opacity:0.3; }');
		}},'Set as Wallpaper'));
	});
*/
	
}); // End of load() function

})(); // End of wrapper anonymous function



