var clickHandlers = {};
var keyupHandlers = {};
var keydownHandlers = {};
var focusinHandlers = {};
var focusoutHandlers = {};
var changeHandlers = {};
var mouseoverHandlers = {};
var mouseoutHandlers = {};
var scrollHandlers = {};
var pasteHandlers = {};
var gSrollContainer = $(window);
var gOtimeOut = null;
var gTSinterval = null;
var gStream = null;
if (typeof gHolder == "undefined") {
	var gHolder = {}
}
var gHomePage = false;
var searchScope = new RegExp("(post|stream):");
if (typeof searchOrder == "undefined") {
	var searchOrder = [ 0 ]
}
if (typeof searchOptions == "undefined") {
	var searchOptions = [ [ "Search for %(term)s", {
		action : "/search"
	} ] ]
}
var gXHR = null;
var gContentContainer = null;
var gContentParams = null;
function d() {
	try {
		if (Favit && /favit\.com/.test(Favit.host)) {
			return
		}
		if (typeof console == "undefined") {
			window.console = {
				log : function() {
				},
				debug : function() {
				},
				info : function() {
				}
			}
		}
		if (typeof console != "undefined" && console.log) {
			for (i = 0, l = arguments.length; i < l; i++) {
				console.log(arguments[i])
			}
		} else {
			var A = "";
			for (i = 0, l = arguments.length; i < l; i++) {
				A += arguments[i] + "\n"
			}
		}
	} catch (e) {
	}
}
if (typeof window.d == "undefined") {
	window.d = function() {
	}
}
function isEmpty(ob) {
	for ( var i in ob) {
		if (ob.hasOwnProperty(i)) {
			return false
		}
	}
	return true
}
function updateLengthCounter(A, C) {
	var B = A[0].value.length;
	if (B <= 0) {
		C.html("")
	} else {
		C.html("" + B)
	}
}
var showInfoMessage = function(A, Z, Y) {
	var B = $("#sys_msg");
	if (B.length == 0) {
		B = $('<div id="sys_msg" class="notify"></div>');
		$("body").append(B)
	}
	B.html("<span></span>" + A).hide();
	B.data("text", A);
	if (!Z) {
		Z = 1500
	}
	if (Y) {
		gI = setInterval(function() {
			var B = $("#sys_msg");
			var T = B.data("text");
			T += ".";
			B.data("text", T);
			B.html("<span></span>" + T)
		}, 2000)
	}
	var C = function() {
		setTimeout(function() {
			B.slideUp(150)
		}, Z)
	};
	B.slideDown(100, C)
};
var notify = function() {
	if (Favit.user) {
		if (gOtimeOut) {
			clearTimeout(gOtimeOut)
		}
		gOtimeOut = setTimeout("notify()", 30000);
		$.post("/a/notify", {}, function(data, status) {
			var po = $("#b_load");
			if (data == null) {
				po.hide();
				return
			}
			po.html("");
			for ( var i = 0, l = data.length; i < l; i++) {
				po.append("<span>" + data[i] + "</span><br />")
			}
			po.show()
		}, "json")
	}
};
var favitCache = {
	cache : {},
	set : function(key, value) {
		this.cache[key] = value
	},
	get : function(key) {
		if (this.cache[key]) {
			return this.cache[key]
		}
	},
	is : function(key) {
		return this.cache[key] || false
	},
	remove : function(key) {
		if (this.cache[key]) {
			delete this.cache[key]
		}
	}
};
var delegate = function() {
	$("body")
			.live(
					"change click focus blur keyup paste",
					function(event) {
						var el = null;
						for ( var node = event.target; node; node = node.parentNode) {
							var jNode = $(node);
							var B = jNode.attr("href");
							var C = jNode.attr("rel");
							if (B
									&& event.type == "click"
									&& event.button == 0
									&& jNode
									&& jNode.length
									&& jNode[0].tagName == "A"
									&& (B.match(/signin\/(facebook|twitter)/g) || B
											.match(/subscribe\/reader/g))) {
								if (C) {
									$.cookie("extacclnkrdr", C)
								}
								if (B.match(/facebook/g)) {
									winName = "FacebookConnectWithOAuth";
									winOpts = "location=0,status=0,width=680,height=410";
									winPath = B + "?popup=1"
								}
								if (B.match(/twitter/g)) {
									winName = "TwitterConnectWithOAuth";
									winOpts = "location=0,status=0,width=800,height=420";
									winPath = B
								}
								if (B.match(/reader/g)) {
									winName = "GoogleReaderWithOAuth";
									winOpts = "location=0,status=0,width=720,height=440";
									winPath = B
								}
								winPath = "http://" + Favit.host + winPath;
								if($.browser.msie)
								{
									window.location.href = winPath;
								}else{
									$.oauthpopup( {
										windowName : winName,
										windowOptions : winOpts,
										path : winPath,
										callback : function() {
											window.location.reload()
										}
									})									
								}
								
								return false
							}
							if (!node.className) {
								continue
							}
							var el = node;
							if (el.className.match(/\s*no_l\s*/i)) {
								return true
							}
							if (el
									&& el.className != ""
									&& !el.className.match(/\s*net_list\s*/i)
									&& !el.className.match(/\s*full_thumb\s*/i)
									&& !el.className
											.match(/\s*scroll_pane\s*/i)
									&& el.className.match(/\s*l_([\w]+)\s*/i)) {
								var isInput = /^.*(input|textarea|password).*$/i
										.test(el.tagName);
								var nonCapture = /noncapture/
										.test(el.className);
								if (isInput && !nonCapture && !el.originalValue
										&& el.value) {
									el.originalValue = el.value
								}
								var fNses = el.className
										.match(/\bl_([\w]+)\b/ig);
								if (fNses) {
									for ( var _i = 0, _l = fNses.length; _i < _l; _i++) {
										var fN = fNses[_i].replace(/l_/, "");
										fN = $.trim(fN);
										var pS = el.getAttribute("params")
												|| {};
										try {
											if (pS.length) {
												pS = eval("(" + pS + ")")
											}
										} catch (e) {
											pS = {
												json_error : true
											}
										}
										var oE = event.srcElement
												|| (event.originalTarget || event.target);
										var eventHandler = event.type
												+ "Handlers";
										var prevent = false;
										if (window[eventHandler]
												&& window[eventHandler][fN]) {
											if (event.type == "click"
													&& event.button != 0) {
												return false
											}
											prevent = window[eventHandler][fN](
													$(el), pS, oE, event)
										}
									}
								}
								if (isInput) {
									switch (event.type) {
									case "focusin":
										if (el.value == el.originalValue) {
											el.value = "";
											$(el).css("color", "#333333")
										}
										break;
									case "focusout":
										if (el.value == "" && el.originalValue) {
											el.value = el.originalValue;
											$(el).css("color", "#999999")
										}
										break
									}
									return true
								}
								node = false;
								if (!prevent) {
									return false
								}
							}
						}
						return true
					})
};
(function($) {
	$(document).hotKeys(
			{
				j : function() {
					if ($("#read_pane").length == 0
							|| !gHolder.hasOwnProperty("post_id")
							|| gHolder.post_id == undefined) {
						var p = $("div.l_post:eq(0)");
						if (p.length) {
							postClick(p)
						}
					} else {
						nextClick()
					}
				},
				k : function() {
					if ($("#read_pane").length > 0) {
						prevClick()
					}
				},
				s : function() {
					if ($("#read_pane").length > 0) {
						quickSharePost($("a.l_qshare"))
					}
				},
				r : function() {
					if ($("#read_pane").length > 0) {
						resharePost($("a.l_reshare"))
					}
				},
				c : function() {
					if ($("#read_pane").length > 0) {
						var com = $("textarea.l_comment_area");
						expandCommentBox(com);
						var position = $(document).height();
						$(document).scrollTop(position);
						com.focus().val("")
					}
				},
				l : function() {
					if ($("#read_pane").length > 0) {
						read_later($("a.l_read_later"))
					}
				},
				f : function() {
					if ($("#read_pane").length > 0) {
						likePost($("a.l_like"))
					}
				},
				v : function() {
					var orig = $("div.post_content h1 a");
					if (orig.length > 0) {
						window.open(orig.attr("href"), "_blank"
								+ Math.floor(Math.random() * 101))
					}
				},
				b : function() {
					var orig = $("a.l_toaddedit");
					if (orig.length > 0) {
						clickHandlers.toaddedit(orig);
						$("input.ac_input").focus()
					}
				},
				n : function() {
					sharePost($("a.l_doshare"))
				},
				"/" : function() {
					var sf = $("#searchTxt");
					if (sf.length) {
						sf.val("").focus()
					}
					giveNavigateFocus(sf)
				},
				"?" : function() {
					C = {};
					fPopup.show( {
						view : "hotkeys",
						params : C
					})
				},
				"." : function() {
					var position = 0;
					$(document).scrollTop(position);
					var np = $("#new_posts");
					if (np.length && np.is(":visible")
							&& parseInt(np.find("span").html(), 10) > 0) {
						np.show();
						triggerLoadPosts(np)
					}
				},
				"h+h" : function() {
					window.location.href = "/"
				},
				"m+m" : function() {
					window.location.href = "/stream/inbox"
				},
				"d+d" : function() {
					window.location.href = "/stream/discussions"
				},
				"e+e" : function() {
					window.location.href = "/stream/read_later"
				},
				"p+p" : function() {
					if (Favit && Favit.hasOwnProperty("nickname")) {
						window.location.href = "/" + Favit.nickname
					}
				},
				"a+a" : function() {
					window.location.href = "/article"
				},
				space : function(e) {
					var position = $(document).scrollTop() + 150;
					$(document).scrollTop(position)
				},
				"shift+space" : function() {
					var position = $(document).scrollTop() - 150;
					$(document).scrollTop(position)
				},
				"shift+enter" : function(el) {
					if (el == null) {
						return false
					}
					var el = $(el);
					if (el.length) {
						switch (el.attr("id")) {
						case "comment_msg":
							publishComment($(".l_publish_comment"));
							break;
						case "shareArea":
							shareAction($(".l_share"));
							break
						}
					}
				},
				left : function() {
					$.evalHotKey("k")
				},
				right : function() {
					$.evalHotKey("j")
				}
			})
})(jQuery);
(function(A) {
	A.fn.extend( {
		autocomplete : function(B, C) {
			var D = typeof B == "string";
			C = A.extend( {}, A.Autocompleter.defaults, {
				url : D ? B : null,
				data : D ? null : B,
				delay : D ? A.Autocompleter.defaults.delay : 10,
				max : C && !C.scroll ? 10 : 150
			}, C);
			C.highlight = C.highlight || function(E) {
				return E
			};
			return this.each(function() {
				new A.Autocompleter(this, C)
			})
		},
		result : function(B) {
			return this.bind("result", B)
		},
		deletelast : function(B) {
			return this.bind("deletelast", B)
		},
		search : function(B) {
			return this.trigger("search", [ B ])
		},
		flushCache : function() {
			return this.trigger("flushCache")
		},
		setOptions : function(B) {
			return this.trigger("setOptions", [ B ])
		},
		unautocomplete : function() {
			return this.trigger("unautocomplete")
		}
	});
	A.Autocompleter = function(L, G) {
		var C = {
			UP : 38,
			DOWN : 40,
			DEL : 46,
			BACKSPACE : 8,
			TAB : 9,
			RETURN : 13,
			ESC : 27,
			COMMA : 188,
			PAGEUP : 33,
			PAGEDOWN : 34
		};
		var B = A(L).attr("autocomplete", "off").addClass(G.inputClass);
		var J;
		var P = "";
		var M = A.Autocompleter.Cache(G);
		var E = 0;
		var U;
		var W = {
			mouseDownOnSelect : false
		};
		var R = A.Autocompleter.Select(G, L, D, W);
		B.keydown(
				function(X) {
					E = 1;
					U = X.keyCode;
					switch (X.keyCode) {
					case C.UP:
						X.preventDefault();
						if (R.visible()) {
							R.prev()
						} else {
							T(0, true)
						}
						break;
					case C.DOWN:
						X.preventDefault();
						if (R.visible()) {
							R.next()
						} else {
							T(0, true)
						}
						break;
					case C.PAGEUP:
						X.preventDefault();
						if (R.visible()) {
							R.pageUp()
						} else {
							T(0, true)
						}
						break;
					case C.PAGEDOWN:
						X.preventDefault();
						if (R.visible()) {
							R.pageDown()
						} else {
							T(0, true)
						}
						break;
					case (G.multiple || G.fbMode)
							&& A.trim(G.multipleSeparator) == "," && C.COMMA:
					case C.TAB:
						if (G.requireExplicit) {
							X.preventDefault();
							R.next();
							break
						}
					case C.RETURN:
						if (D()) {
							if (!G.multiple) {
								B.blur()
							}
							X.preventDefault()
						}
						if (!G.requireExplicit) {
							B.val("")
						}
						break;
					case C.ESC:
						R.hide();
						break;
					case C.BACKSPACE:
						if (G.fbMode && !B.val()) {
							B.trigger("deletelast");
							break
						}
					default:
						clearTimeout(J);
						J = setTimeout(T, G.delay);
						break
					}
				}).keypress(function() {
			clearTimeout(J);
			J = setTimeout(T, G.delay)
		}).focus(function() {
			E++
		}).blur(function() {
			if (!G.requireExplicit) {
				setTimeout(function() {
					if (B.val()) {
						B.val("")
					}
				}, 10)
			}
			E = 0;
			if (!W.mouseDownOnSelect) {
				S()
			}
		}).click(function() {
			if (E++ > 1 && !R.visible()) {
				T(0, true)
			}
		}).bind("search", function() {
			var X = (arguments.length > 1) ? arguments[1] : null;
			function Y(c, b) {
				var Z;
				if (b && b.length) {
					for ( var a = 0; a < b.length; a++) {
						if (b[a].result.toLowerCase() == c.toLowerCase()) {
							Z = b[a];
							break
						}
					}
				}
				if (typeof X == "function") {
					X(Z)
				} else {
					B.trigger("result", Z && [ Z.data, Z.value ])
				}
			}
			A.each(H(B.val()), function(Z, a) {
				F(a, Y, Y)
			})
		}).bind("flushCache", function() {
			M.flush()
		}).bind("setOptions", function() {
			A.extend(G, arguments[1]);
			if ("data" in arguments[1]) {
				M.populate()
			}
		}).bind("unautocomplete", function() {
			R.unbind();
			B.unbind()
		});
		function D() {
			var Y = R.selected();
			var X;
			if (!Y) {
				if (!G.fbMode) {
					return false
				}
				var a = A.trim(B.val());
				if (a.indexOf("@") > 0) {
					Y = {
						value : a,
						data : [ a, null, true ],
						result : a
					}
				} else {
					return false
				}
			}
			X = Y.result;
			P = X;
			if (G.multiple) {
				var Z = H(B.val());
				if (Z.length > 1) {
					X = Z.slice(0, Z.length - 1).join(G.multipleSeparator)
							+ G.multipleSeparator + X
				}
				X += G.multipleSeparator
			}
			if (!G.requireExplicit) {
			}
			V();
			B.trigger("result", [ Y.data, Y.value ]);
			return true
		}
		function T(Z, Y) {
			if (U == C.DEL) {
				R.hide();
				return
			}
			var X = B.val();
			if (!Y && X == P) {
				return
			}
			P = X;
			X = I(X);
			if (X.length >= G.minChars) {
				B.addClass(G.loadingClass);
				if (!G.matchCase) {
					X = X.toLowerCase()
				}
				F(X, K, V)
			} else {
				N();
				R.hide()
			}
		}
		function H(Y) {
			if (!Y) {
				return [ "" ]
			}
			var Z = Y.split(A.trim(G.multipleSeparator));
			var X = [];
			A.each(Z, function(a, b) {
				if (A.trim(b)) {
					X[a] = A.trim(b)
				}
			});
			return X
		}
		function I(X) {
			if (!G.multiple) {
				return X
			}
			var Y = H(X);
			return Y[Y.length - 1]
		}
		function Q(X, Y) {
			if (G.autoFill && (I(B.val()).toLowerCase() == X.toLowerCase())
					&& U != 8) {
				B.val(B.val() + Y.substring(I(P).length));
				A.Autocompleter.Selection(L, P.length, P.length + Y.length)
			}
		}
		function S() {
			clearTimeout(J);
			J = setTimeout(V, 200)
		}
		function V() {
			R.hide();
			clearTimeout(J);
			N();
			if (G.mustMatch) {
				B.search(function(X) {
					if (!X) {
						B.val("")
					}
				})
			}
		}
		function K(Y, X) {
			if (X && X.length && E) {
				N();
				R.display(X, Y);
				Q(Y, X[0].value);
				R.show()
			} else {
				V()
			}
		}
		function F(Y, a, X) {
			if (!G.matchCase) {
				Y = Y.toLowerCase()
			}
			var Z = M.load(Y);
			if (Z && Z.length) {
				a(Y, Z)
			} else {
				if ((typeof G.url == "string") && (G.url.length > 0)) {
					var b = {};
					A.each(G.extraParams, function(c, d) {
						b[c] = typeof d == "function" ? d() : d
					});
					A.ajax( {
						mode : "abort",
						port : "autocomplete" + L.name,
						dataType : G.dataType,
						url : G.url,
						data : A.extend( {
							q : I(Y),
							limit : G.max
						}, b),
						success : function(d) {
							var c = G.parse && G.parse(d) || O(d);
							M.add(Y, c);
							a(Y, c)
						}
					})
				} else {
					X(Y)
				}
			}
		}
		function O(a) {
			var X = [];
			var Z = a.split("\n");
			for ( var Y = 0; Y < Z.length; Y++) {
				var b = A.trim(Z[Y]);
				if (b) {
					b = b.split("|");
					X[X.length] = {
						data : b,
						value : b[0],
						result : G.formatResult && G.formatResult(b, b[0])
								|| b[0]
					}
				}
			}
			return X
		}
		function N() {
			B.removeClass(G.loadingClass)
		}
	};
	A.Autocompleter.defaults = {
		inputClass : "ac_input",
		resultsClass : "ac_results",
		loadingClass : "ac_loading",
		minChars : 1,
		delay : 400,
		matchCase : false,
		matchSubset : true,
		matchContains : false,
		cacheLength : 50,
		max : 100,
		mustMatch : false,
		extraParams : {},
		selectFirst : true,
		formatItem : function(B) {
			return B[0]
		},
		autoFill : false,
		width : 0,
		multiple : false,
		multipleSeparator : ", ",
		highlight : function(C, B) {
			return C.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("
					+ B.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1")
					+ ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>")
		},
		scroll : true,
		scrollHeight : 180,
		attachTo : "body",
		requireExplicit : false,
		permaResults : function(B) {
			return []
		}
	};
	A.Autocompleter.Cache = function(C) {
		var F = {};
		var D = 0;
		function H(K, J) {
			if (!K) {
				return false
			}
			if (!C.matchCase) {
				K = K.toLowerCase()
			}
			var I = K.indexOf(J);
			if (I == -1) {
				return false
			}
			return I == 0
					|| (C.matchContains && (K[I - 1] == " " || K[I - 1] == "("))
		}
		function G(J, I) {
			if (D > C.cacheLength) {
				B()
			}
			if (!F[J]) {
				D++
			}
			F[J] = I
		}
		function E() {
			if (!C.data) {
				return false
			}
			var J = {}, I = 0;
			if (!C.url) {
				C.cacheLength = 1
			}
			J[""] = [];
			for ( var L = 0, K = C.data.length; L < K; L++) {
				var O = C.data[L];
				O = (typeof O == "string") ? [ O ] : O;
				var N = C.formatItem(O, L + 1, C.data.length);
				if (N === false || N === null || !N) {
					continue
				}
				var M = N.charAt(0).toLowerCase();
				if (!J[M]) {
					J[M] = []
				}
				var P = {
					value : N,
					data : O,
					result : C.formatResult && C.formatResult(O) || N
				};
				J[M].push(P);
				J[""].push(P);
				if (O[2]) {
					var Z = O[2].charAt(0).toLowerCase();
					if (!J[Z]) {
						J[Z] = []
					}
					J[Z].push(P)
				}
			}
			A.each(J, function(Q, R) {
				C.cacheLength++;
				G(Q, R)
			})
		}
		setTimeout(E, 25);
		function B() {
			F = {};
			D = 0
		}
		return {
			flush : B,
			add : G,
			populate : E,
			load : function(M) {
				if (!C.cacheLength || !D) {
					return null
				}
				var K = [];
				var I = C.permaResults(M);
				for ( var J = 0; J < I.length; J++) {
					var L = I[J];
					K.push( {
						data : [ L ],
						value : ""
					})
				}
				if (!C.url && C.matchContains) {
					var N = F[""];
					A.each(N, function(P, O) {
						if (H(O.data[2], M) || H(O.data[1], M)) {
							K.push(O)
						}
					});
					return K
				} else {
					if (F[M]) {
						return F[M]
					} else {
						if (C.matchSubset) {
							for ( var J = M.length - 1; J >= C.minChars; J--) {
								var N = F[M.substr(0, J)];
								if (N) {
									var K = [];
									A.each(N,
											function(P, O) {
												if (H(O.data[2], M)
														|| H(O.data[1], M)) {
													K[K.length] = O
												}
											});
									return K
								}
							}
						}
					}
				}
				return null
			}
		}
	};
	A.Autocompleter.Select = function(E, J, L, P) {
		var I = {
			ACTIVE : "ac_over"
		};
		var K, F = -1, R, M = "", S = true, C, O;
		function N() {
			if (!S) {
				return
			}
			C = A("<div/>").hide().addClass(E.resultsClass).css("position",
					"absolute").appendTo(E.attachTo);
			O = A("<ul>").appendTo(C).mouseover(function(T) {
				if (Q(T).nodeName && Q(T).nodeName.toUpperCase() == "LI") {
					F = A("li", O).removeClass(I.ACTIVE).index(Q(T));
					A(Q(T)).addClass(I.ACTIVE)
				}
			}).click(function(T) {
				A(Q(T)).addClass(I.ACTIVE);
				L();
				J.focus();
				return false
			}).mousedown(function() {
				P.mouseDownOnSelect = true
			}).mouseup(function() {
				P.mouseDownOnSelect = false
			});
			if (E.width > 0) {
				C.css("width", E.width)
			}
			S = false
		}
		function Q(U) {
			var T = U.target;
			while (T && T.tagName != "LI") {
				T = T.parentNode
			}
			if (!T) {
				return []
			}
			return T
		}
		function H(T) {
			K.slice(F, F + 1).removeClass();
			G(T);
			var V = K.slice(F, F + 1).addClass(I.ACTIVE);
			if (E.scroll) {
				var U = 0;
				K.slice(0, F).each(function() {
					U += this.offsetHeight
				});
				if ((U + V[0].offsetHeight - O.scrollTop()) > O[0].clientHeight) {
					O.scrollTop(U + V[0].offsetHeight - O.innerHeight())
				} else {
					if (U < O.scrollTop()) {
						O.scrollTop(U)
					}
				}
			}
		}
		function G(T) {
			F += T;
			if (F < 0) {
				F = K.size() - 1
			} else {
				if (F >= K.size()) {
					F = 0
				}
			}
		}
		function B(T) {
			return E.max && E.max < T ? E.max : T
		}
		function D() {
			O.empty();
			var U = B(R.length);
			for ( var V = 0; V < U; V++) {
				if (!R[V]) {
					continue
				}
				var W = E.formatItem(R[V].data, V + 1, U, R[V].value, M);
				if (W === false) {
					continue
				}
				var T = A("<li>").html(E.highlight(W, M, R[V].data)).addClass(
						V % 2 == 0 ? "ac_event" : "ac_odd").appendTo(O)[0];
				A.data(T, "ac_data", R[V])
			}
			K = O.find("li");
			if (E.selectFirst) {
				K.slice(0, 1).addClass(I.ACTIVE);
				F = 0
			}
		}
		return {
			display : function(U, T) {
				N();
				R = U;
				M = T;
				D()
			},
			next : function() {
				H(1)
			},
			prev : function() {
				H(-1)
			},
			pageUp : function() {
				if (F != 0 && F - 8 < 0) {
					H(-F)
				} else {
					H(-8)
				}
			},
			pageDown : function() {
				if (F != K.size() - 1 && F + 8 > K.size()) {
					H(K.size() - 1 - F)
				} else {
					H(8)
				}
			},
			hide : function() {
				C && C.hide();
				F = -1
			},
			visible : function() {
				return C && C.is(":visible")
			},
			current : function() {
				return this.visible()
						&& (K.filter("." + I.ACTIVE)[0] || E.selectFirst
								&& K[0])
			},
			show : function() {
				var V = A(J).offset();
				var Z = A(J).width() + parseInt(A(J).css("paddingLeft"))
						+ parseInt(A(J).css("paddingRight"));
				C.css( {
					width : Z + "px",
					top : V.top + J.offsetHeight,
					left : V.left
				}).show();
				if (E.scroll) {
					O.scrollTop(0);
					O.css( {
						maxHeight : gSrollContainer.height()
								- (V.top + J.offsetHeight + 10),
						overflow : "auto"
					});
					if (A.browser.msie
							&& typeof document.body.style.maxHeight === "undefined") {
						var T = 0;
						K.each(function() {
							T += this.offsetHeight
						});
						var U = T > E.scrollHeight;
						O.css("height", U ? E.scrollHeight : T);
						if (!U) {
							K.width(O.width() - parseInt(K.css("padding-left"))
									- parseInt(K.css("padding-right")))
						}
					}
				}
			},
			selected : function() {
				var T = K && K.filter("." + I.ACTIVE).removeClass(I.ACTIVE);
				return T && T.length && T.is(":visible")
						&& A.data(T[0], "ac_data")
			},
			unbind : function() {
				C && C.remove()
			}
		}
	};
	A.Autocompleter.Selection = function(D, E, C) {
		if (D.createTextRange) {
			var B = D.createTextRange();
			B.collapse(true);
			B.moveStart("character", E);
			B.moveEnd("character", C);
			B.select()
		} else {
			if (D.setSelectionRange) {
				D.setSelectionRange(E, C)
			} else {
				if (D.selectionStart) {
					D.selectionStart = E;
					D.selectionEnd = C
				}
			}
		}
		D.focus()
	}
})(jQuery);
jQuery.fn.autoCompleteToBox = function(B) {
	var A = this;
	$(".l_toinput", A).autocomplete(
			B || [],
			{
				fbMode : true,
				matchContains : true,
				width : 220,
				scrollHeight : 100,
				highlight : function(D, C, E) {
					if (typeof (E[0]) == "number") {
						return D
					}
					var B = E[3];
					if (B == null) {
						B = "/static/" + Favit.version
								+ "/images/nomugshot-small.png"
					}
					return '<img class="ac_picture" src="' + B + '"/>'
							+ $.Autocompleter.defaults.highlight(D, C)
				},
				formatItem : function(F, D, B, E, C) {
					if (typeof (F[0]) == "number") {
						return searchOptions[F[0]][0].replace("%(term)s",
								"<strong>" + htmlEscape(C) + "</strong>")
					}
					return (F[2] ? F[1] + " <u>" + htmlEscape(F[2]) + "</u>"
							: F[1])
				}
			}).result(
			function(G, I, F) {
				if (($(".l_tocard[sid=" + I[0] + "]", A).length == 0)
						&& ($(".l_tocard[eid=" + I[0] + "]", A).length == 0)) {
					var C = (I[6] == 1) ? " private" : " public";
					var E = I[1];
					var N = "eid";
					switch (I[6]) {
					case 2:
						N = "sid";
						break;
					case 3:
						N = "pid";
						break
					}
					var D = '<li class="l_tocard' + C + '" ' + N + '="' + I[0]
							+ '"><span>' + htmlEscape(E)
							+ '</span> <img class="l_toremove" src="'
							+ Favit.images
							+ 'to-delete.png" title="Delete"/></li>';
					var H = $(".addedit", A);
					if (H.length > 0) {
						H.before(D).val("")
					} else {
						$(".l_toinput", A).before(D)
					}
				}
				window.setTimeout(function() {
					$(".l_toinput", A).focus()
				})
			}).deletelast(function() {
		$(".l_tocard:last", A).remove();
		$(".l_toinput", A).focus()
	})
};
jQuery.fn.autoCompleteSearchBox = function(A) {
	this.autocomplete(
			A || [],
			{
				requireExplicit : true,
				selectFirst : true,
				matchContains : true,
				width : 231,
				delay : 50,
				permaResults : function(B) {
					if (B.match(searchScope)) {
						return [ 0 ]
					} else {
						return searchOrder
					}
				},
				highlight : function(D, C, E) {
					if (typeof (E[0]) == "number") {
						return D
					}
					var B = E[3];
					if (B == null) {
						B = "/static/" + Favit.version
								+ "/images/nomugshot-small.png"
					}
					return '<img class="ac_picture" src="' + B + '"/>'
							+ $.Autocompleter.defaults.highlight(D, C)
				},
				formatItem : function(F, D, B, E, C) {
					if (typeof (F[0]) == "number") {
						return searchOptions[F[0]][0].replace("%(term)s",
								"<strong>" + htmlEscape(C) + "</strong>")
					}
					return (F[2] ? F[1] + " <u>" + htmlEscape(F[2]) + "</u>"
							: F[1])
				}
			}).result(
			function(C, E, D) {
				var F = $("#searchform");
				if (E.length == 1) {
					for ( var B in searchOptions[E][1]) {
						if (B == "action") {
							F.attr("action", searchOptions[E][1][B])
						} else {
							F.append('<input type="hidden" name="' + B
									+ '" value="' + searchOptions[E][1][B]
									+ '"/>')
						}
					}
					var G = F.attr("action");
					if (G == "/search") {
						$("#searchform").submit()
					} else {
						window.location.hash = F.attr("action") + "?q="
								+ $("#searchTxt").val()
					}
				} else {
					$("#searchbox").val("");
					document.location.href = E[5]
				}
			})
};
var htmlCharMap = {
	"&" : "&amp;",
	"<" : "&lt;",
	">" : "&gt;",
	'"' : "&quot;"
};
function htmlCharEsc(A) {
	return htmlCharMap[A]
}
function htmlEscape(A) {
	return String(A).replace(/[&<>\"]/g, htmlCharEsc)
}
clickHandlers.donothing = function(A) {
	return true
};
clickHandlers.toremove = function(A) {
	var C = A.parents(".l_tocard");
	var D = true;
	var B = C.attr("eid");
	if (B && B.length && B == Favit.user) {
		$(".l_tservice").each(function() {
			$(this).attr("checked", false)
		})
	}
	var B = A.parents(".l_tolist");
	A.parents(".l_tocard").remove();
	B.find(".l_toinput").focus()
};
clickHandlers.streams_toggle = function(A) {
	var B = A.parents(".m_switch");
	B.find("a").removeClass("active");
	A.addClass("active");
	var C = $("#stream_holder");
	if (A.attr("rel") == "new") {
		C.children("li").hide();
		C.find("em.n").each(function(I, E) {
			$(E).parents("li").show()
		})
	} else {
		C.children("li").show()
	}
};
clickHandlers.stream_clear = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("#g_load").show();
	var B = A.parents(".m_switch");
	var C = $("#stream_holder");
	$.post("/a/stream_clear", {}, function(A) {
		$("#g_load").hide();
		if (A.success) {
			C.find("em").remove();
			var D = B.children("a.active");
			if (D.attr("rel") == "new") {
				C.children("li").hide()
			} else {
				C.children("li").show()
			}
		}
	}, "json")
};
clickHandlers.select_stream = function(A) {
	var B = $("#menu ul.nav li");
	B.removeClass("active");
	var C = A.parent();
	C.addClass("active");
	C.prepend('<span class="ld"></span>');
	$("#mega_top a.fn").removeClass("active")
};
var gHL = {};
gHL._hashchange_last = "";
gHL._onhashchange = function(A) {
	if (gHL._hashchange_last != location.hash) {
		gHL._hashchange_last = location.hash;
		route(location.hash).run(A)
	}
};
var populatePosts = function(A, Z) {
	clearInterval(window.feat_interval);
	if (typeof gHolder.stayopen == "undefined" || gHolder.stayopen == false) {
		closePost()
	}
	$("#m_loading").hide();
	$("#g_load").hide();
	gHolder.stayopen = false;
	if (!A) {
		return false
	}
	if (!A.error) {
		var X = $("#cust_header");
		X.remove();
		$("#custom_style").remove();
		Favit.streamer = false;
		if (A.customHeader) {
			$("body").prepend($(A.customHeader));
			Favit.streamer = true
		}
		var B = $("#list_posts");
		if (gContentContainer) {
			B = gContentContainer;
			gContentContainer = null
		} else {
			if (A.jc) {
				B = $("#content")
			} else {
				B = $("#list_posts")
			}
		}
		if (B.length == 0) {
			$("#content").children().remove();
			$("#content").append('<div id="list_posts"/>');
			B = $("#list_posts")
		}
		if (A.start == 0 || typeof A.start == "undefined") {
			B.html("");
			$(gSrollContainer).scrollTop(0);
			if (A.posts) {
				gPdata = A.posts
			} else {
				gPdata = []
			}
			if (A.feed) {
				$("#s" + A.feed).children(".ld").remove();
				if (!A.feed_support_unread) {
					$("#s" + A.feed).find("em").remove()
				}
				realtime.start("s" + A.feed)
			}
			if (A.query) {
				realtime.start(null, A.query)
			}
		} else {
			if (typeof gPdata != "undefined" && A.posts) {
				for (i in A.posts) {
					gPdata.push(A.posts[i])
				}
			}
		}
		if (A.data_key) {
			gHolder.dataLoading = true;
			var C = {
				hash : A.data_key
			};
			gXHR = $.get("/a/streamdata", C, function(D) {
				if (D.posts) {
					for (i in D.posts) {
						gPdata.push(D.posts[i])
					}
					gHolder.dataLoading = false;
					gPTime = D.time
				}
			}, "json")
		}
		if (A.request_uri) {
			grUrl = A.request_uri
		}
		if (A.start) {
			gStart = A.start || gStart
		}
		if (A.ptitle) {
			document.title = A.ptitle
		}
		$('link[type="application/rss+xml"]').remove();
		if (A.rss) {
			$("head")
					.append(
							$('<link rel="alternate" type="application/rss+xml" title="'
									+ A.rss.title
									+ '" href="'
									+ A.rss.link
									+ '" />'))
		}
		if (A.stream) {
			gStream = A.stream;
			var X = "";
			if (A.stream.display_name) {
				X = A.stream.display_name
			} else {
				X = A.stream.title
			}
			searchOptions = [ [ "Search for %(term)s", {
				action : "/search"
			} ], [ "Search " + X + " for %(term)s", {
				action : A.stream.stream_url
			} ] ];
			if (A.stream.stream_id) {
				M = $("div#menu");
				H = M.find("#s" + A.stream.stream_id);
				if (H && H.length && !H.hasClass("active")) {
					H.parent().children("li.active").removeClass("active");
					H.addClass("active")
				}
			}
		}
		gHolder.loading = !A.has_more;
		if (A.html) {
			B.append(A.html)
		}
		if (A.header) {
			$("#header").html(A.header)
		}
		if (A.streams_view) {
			boxedStreams()
		}
		if (A.stream && A.stream.featured_posts
				&& A.stream.featured_posts.length > 0) {
			FeaturedInit()
		}
	}
	$("#main_pane").css("height", "auto")
};
function getRequestAndCancelXHR() {
	var B = window.location.hash;
	B = B.substr(1);
	if (typeof gXHR != "undefined" && gXHR) {
		gXHR.abort();
		gXHR = null
	}
	gHolder.stayopen = false;
	$("#g_load").show();
	var C = {};
	if (gContentContainer) {
		C = gContentContainer
	} else {
		C = $("#content")
	}
	$("#main_pane").css("height", $("#main_pane").height());
	if (C.find("#m_loading").length == 0) {
		C.append('<span id="m_loading" class="m_loading">Loading...</span>')
	}
	C.find("#m_loading").show();
	return B
}
var displayContent = function() {
	if (Favit.refreshInTimeSpace) {
		clearTimeout(Favit.refreshInTimeSpace)
	}
	var B = getRequestAndCancelXHR();
	var C = {
		ar : "true"
	};
	if (gContentParams) {
		for (k in gContentParams) {
			C[k] = gContentParams[k]
		}
		gContentParams = null
	}
	gXHR = $.get(B, C, populatePosts, "json")
};
var initFavit = function() {
	gLoaded = true;
	route("stream/:user/:streamname/:ff").bind(function() {
		displayContent()
	});
	route("twitter/:nick/:tab").bind(function() {
		displayContent()
	});
	route("facebook/:fbid/:tab").bind(function() {
		displayContent()
	});
	route("feed/:tab/:filter").bind(function() {
		displayContent()
	});
	route("search/:tab/:filter").bind(function() {
		displayContent()
	});
	route(":user/:tab/:filter").bind(function() {
		displayContent()
	});
	$(":input").each(
			function(index) {
				if (!$(this).hasClass("noncapture") && !this.originalValue
						&& this.value) {
					this.originalValue = this.value
				}
			});
	gTSinterval = setInterval(function() {
		gHL._onhashchange()
	}, 100);
	setInterval(function() {
		updateTimes(10000)
	}, 10000);
	delegate();
	notify();
	$(gSrollContainer).scroll(scrollListener);
	window.setTimeout(function() {
		if (realtime.stopped) {
			realtime.start(null, null)
		}
	}, 1000);
	recalcAreas();
	gSrollContainer.resize(function() {
		recalcAreas()
	})
};
function updateTimes(I) {
	if (typeof Favit.TS == "undefined") {
		clearInterval(gTSinterval);
		return
	}
	Favit.TS = Favit.TS + Math.round(I / 1000);
	$("span.ft-ts").each(function(A) {
		var B = $(this).attr("time");
		if (B) {
			$(this).html(getTimeDiff(B) + " ago")
		}
	})
}
function shareSetupToBox(A, C) {
	if (!C) {
		C = ""
	}
	$("#share_tools").show();
	if (favitCache.is("share_contacts")) {
		A.find(".l_tolist").autoCompleteToBox(favitCache.get("share_contacts"));
		return true
	}
	$.get("/a/tocontacts", {
		context : "share"
	}, function(B) {
		A.find(".l_tolist").autoCompleteToBox(B.contacts);
		favitCache.set("share_contacts", B.contacts)
	}, "json")
}
function setupSearchBox(B) {
	if (window.gSetupSearch) {
		return
	}
	window.gSetupSearch = true;
	$(B).unbind("focus keydown", setupSearchBox);
	$("#search").addClass("pending");
	$.get("/a/tocontacts", {
		context : "search"
	}, function(A) {
		$(B).autoCompleteSearchBox(A.contacts);
		$("#search").removeClass("pending")
	}, "json")
}
var scrollListener = function() {
	if (gHolder.post_id) {
		return
	}
	var A = $(gSrollContainer).scrollTop();
	if (typeof gStart != "undefined") {
		var C = $("#container").height();
		if (A > 0) {
			if (A > ((C - gSrollContainer.height()) - 300)
					&& (typeof gHolder.loading == "undefined" || gHolder.loading == false)) {
				gHolder.loading = true;
				var P = parseInt(gStart) + 36;
				var S = {
					start : P
				};
				$("#g_load").show();
				gXHR = $.get(grUrl, S, populatePosts, "json")
			}
		}
	}
};
clickHandlers.streamchoice = function(A) {
	A.toggleClass("selected");
	if (A.hasClass("selected")) {
		sEntities[A.attr("id")] = true
	} else {
		delete sEntities[A.attr("id")]
	}
	streamChooserUpdateNum()
};
clickHandlers.streamshowall = function(A) {
	A.addClass("selected");
	$(".l_streamshowselected").removeClass("selected");
	streamChooserUpdate()
};
clickHandlers.streamshowselected = function(A) {
	A.addClass("selected");
	$(".l_streamshowall").removeClass("selected");
	streamChooserUpdate()
};
clickHandlers.expandcluster = function(A) {
	var B = A.parents(".entry");
	$.postJSON("/a/expandcluster", {
		entry_ids : A.attr("eids")
	}, function(C) {
		A.remove();
		B.after(C.html)
	}, A)
};
function streamChooserTriggerUpdate() {
	if (typeof triggerUpdate != "undefined") {
		window.clearTimeout(triggerUpdate)
	}
	triggerUpdate = window.setTimeout(streamChooserUpdate, 200)
}
function streamChooserUpdate() {
	var C = $(".streamchooser select");
	var B = null;
	if (C.length > 0) {
		B = C.get(0).value
	}
	var E = $(".l_streamshowselected").is(".selected");
	var D = $("#streamselectfilter").val();
	if (!D) {
		var F = E ? ".selected" : "";
		F += B ? ".sel-l-" + B : "";
		if (F) {
			var dom = $('<div class="choices l_entities_scroll"/>');
			for (i in sEntities) {
				var j = gEntitiesReverseIndex[i];
				var tag = favitUI_getEntityBlock(j);
				dom.append(tag)
			}
			$("div.choices").replaceWith(dom)
		} else {
			var dom = $('<div class="choices l_entities_scroll"/>');
			for (i = 0; i < 100; i++) {
				if (i < gEntities.length) {
					tag = favitUI_getEntityBlock(i);
					dom.append(tag)
				}
			}
			$("div.choices").replaceWith(dom)
		}
	} else {
		var A = D.toLowerCase().split(/\s+/);
		var C = 0;
		var found = {};
		for (I in A) {
			if (!A[I]) {
				continue
			}
			var startAt = A[I].charAt(0).toLowerCase();
			C++;
			for (K in gEntitiesIndex[startAt]) {
				if (K.startsWith(A[I])) {
					for (H in gEntitiesIndex[startAt][K]) {
						if (!found
								.hasOwnProperty(gEntitiesIndex[startAt][K][H])) {
							found[gEntitiesIndex[startAt][K][H]] = 0
						}
						found[gEntitiesIndex[startAt][K][H]]++
					}
				}
			}
		}
		var dom = $('<div class="choices l_entities_scroll"/>');
		var counter = 0;
		for (i in found) {
			if (found[i] >= C) {
				counter++;
				if (counter == 100) {
					break
				}
				var j = gEntitiesReverseIndex[i];
				var tag = favitUI_getEntityBlock(j);
				dom.append(tag)
			}
		}
		$("div.choices").replaceWith(dom)
	}
}
function streamChooserUpdateNum() {
	var count = 0;
	for (i in sEntities) {
		if (sEntities.hasOwnProperty(i)) {
			count++
		}
	}
	$(".l_streamshowselected").text(
			"Selected (%(num)d)".replace("%(num)d", count))
}
function streamChooserSubmit(B) {
	if (!B) {
		$.closeDialog()
	}
	var A = [];
	for (i in sEntities) {
		if (sEntities.hasOwnProperty(i)) {
			A.push(i)
		}
	}
	B(A, $("form#hidden").formToDict())
}
if (!String.prototype.startsWith) {
	String.prototype.startsWith = function(A) {
		return this.lastIndexOf(A, 0) != -1
	}
}
if (!String.prototype.endsWith) {
	String.prototype.endsWith = function(A) {
		return this.indexOf(A, this.length - A.length) != -1
	}
}
clickHandlers.ll = function(A) {
	window.location.hash = A.attr("href")
};
function tActive(A) {
	A.parent().children().removeClass("active");
	A.addClass("active")
}
clickHandlers.aa = tActive;
clickHandlers.ta = function(A) {
	A.parent().children().removeClass("tab_active");
	A.addClass("tab_active")
};
var closePost = function(A) {
	A = $("#read_pane").attr("rel");
	checkForVideo();
	$("#read_pane").remove();
	$("#main_pane").show();
	if ($("#cust_header").length >= 1) {
		$("#cust_header").css("margin-top", "39px")
	}
	if (A != "") {
		gSrollContainer.scrollTop(A)
	} else {
		var P = gHolder.post_id;
		var O = $("#p" + P).position();
		var R = gSrollContainer.scrollTop()
	}
	if (O && O.top > R && gSrollContainer) {
		gHolder.stayopen = true;
		gSrollContainer.scrollTop(O.top)
	}
	gHolder.post_id = null
};
clickHandlers.cpost = closePost;
var nextClick = function(A) {
	checkForVideo();
	if (typeof gHolder.post_id != "undefined") {
		if (typeof gPdata != "undefined") {
			for (i in gPdata) {
				var P = gPdata[i];
				if (P.post_id == gHolder.post_id) {
					if (i < gPdata.length - 1) {
						var I = parseInt(i) + 1;
						P = gPdata[I];
						postClick(P.post_id);
						$("#read_pane").attr("rel", "");
						return
					} else {
						if (gStart && grUrl) {
							gHolder.loading = true;
							gHolder.stayopen = true;
							var P = parseInt(gStart) + 36;
							var S = {
								start : P
							};
							gXHR = $.get(grUrl, S, populatePosts, "json")
						}
					}
				}
			}
		}
	}
};
var checkForVideo = function() {
	if (Favit.vn) {
		if (confirm("You are currenty playing video, do you want to open it in new window?")) {
			newWindowVideo(Favit.vn, Favit.vid)
		}
	}
	Favit.vn = null
};
var prevClick = function(A) {
	checkForVideo();
	if (typeof gHolder.post_id != "undefined") {
		if (typeof gPdata != "undefined") {
			for (i in gPdata) {
				var P = gPdata[i];
				if (P.post_id == gHolder.post_id) {
					if (i > 0) {
						$("#read_pane").attr("rel", "");
						var I = parseInt(i) - 1;
						P = gPdata[I];
						postClick(P.post_id);
						return
					}
				}
			}
		}
	}
};
clickHandlers.next = nextClick;
clickHandlers.prev = prevClick;
var profileBubble = function(A) {
	if (!A.attr("rel")) {
		return false
	}
	showRight("profile", A.attr("rel"))
};
clickHandlers.show_share = showShare;
clickHandlers.bubble_close = function(A, B, C, E) {
	if ($("a.l_bubble_close").length && $("div.bubble").length) {
		$("a.l_bubble_close").remove();
		$("div.bubble").remove()
	}
	return false
};
var postClick = function(A, X, Y) {
	if (typeof A == "string") {
		var D = A;
		A = $("#p" + D)
	} else {
		A = $(A);
		var D = A.attr("id");
		D = D.substr(1)
	}
	var P = getPostData(D);
	mark_read( {
		post_id : D,
		view_id : P.view_id
	});
	if (!P) {
		if (typeof gHolder.waitIteration == "undefined") {
			gHolder.waitIteration = 0
		}
		if (typeof gHolder.dataLoading != "undefined" && gHolder.dataLoading) {
			if (gHolder.waitIteration < 10) {
				$("#g_load").show();
				var Z = function() {
					postClick(A, X, Y)
				};
				setTimeout(Z, 500)
			}
		}
		return false
	}
	$("#g_load").hide();
	gHolder.post_id = P.post_id;
	if (Y && Y.tagName != undefined && Y.tagName == "A") {
		return true
	}
	if (Y) {
		var XX = $(Y).parents(".modal");
		if (XX.length > 0) {
			return true
		}
	}
	A.parent().find(".l_post").removeClass("active");
	A.addClass("active");
	var B = "";
	B += '<div class="sender">';
	B += '<div class="sub"><a href="" class="l_prev act"></a><a href="" class="l_next act"></a><a href="" class="l_cpost act"></a></div>';
	if (!P.dm && P.action_type == 4 && !P.changed_reshare) {
		var X = P.entity;
		P.entity = P.action_user;
		P.action_user = X;
		P.changed_reshare = true
	}
	for (i in P.shared_by) {
		for (k in P.liked_by) {
			if (P.liked_by[k]["entity_id"] == P.entity.entity_id
					|| P.liked_by[k]["entity_id"] == P.shared_by[i]["entity_id"]) {
				P.liked_by.splice(k, 1);
				P.count_likes -= 1
			}
		}
		if (P.shared_by[i]["entity_id"] == P.entity.entity_id) {
			P.shared_by.splice(i, 1);
			P.count_shares -= 1
		}
	}
	if (P.is_private) {
		B += '<div class="is_pr"></div>'
	}
	B += '<div class="p"></div><table class="s"><tr><td><a href="'
			+ P.entity.profile_url + '" class="l_pb" rel="'
			+ P.entity.entity_id + '"><img src="' + P.entity.avatar_url + '" '
			+ ((P.entity.avatar_is_icon) ? 'class="f"' : "")
			+ '></a></td><td><a href="' + P.entity.profile_url
			+ '" class="l_pb" rel="' + P.entity.entity_id + '">'
			+ P.entity.display_name.substring(0, 25) + "</a>shared via "
			+ P.service_name.substring(0, 20) + "</td></tr></table>";
	if (!P.dm && P.action_user) {
		var AC = "";
		switch (P.action_type) {
		case 2:
			AC = "commented";
			break;
		case 3:
			AC = "liked";
			break;
		case 4:
			AC = "reshared";
			break
		}
		B += '<table class="s"><tr><td><a href="' + P.action_user.profile_url
				+ '" class="l_pb" rel="' + P.action_user.entity_id
				+ '"><img src="' + P.action_user.avatar_url + '" rel="'
				+ P.action_user.entity_id + '"></a></td><td><a href="'
				+ P.action_user.profile_url + '" class="l_pb" rel="'
				+ P.action_user.entity_id + '">'
				+ P.action_user.display_name.substring(0, 25) + "</a>" + AC
				+ " " + P.action_time + " ago</td></tr></table>"
	}
	if (P.dm) {
		B += '<div class="to" title="Included in the private discussion"></div>';
		for (i in P.shared_with) {
			var S = P.shared_with[i];
			B += '<a href="' + S.profile_url + '" class="s d"><img src="'
					+ S.avatar_url + '"><em><strong>' + S.display_name
					+ "</strong></em></a>"
		}
	}
	B += "</div>";
	B += '<div class="read_cont">';
	B += '<div class="post_content">';
	var isPostFeatured = false;
	if (gStream && gStream.featured_posts) {
		for (i in gStream.featured_posts) {
			if (gStream.featured_posts[i] == P.post_id) {
				isPostFeatured = true;
				break
			}
		}
	}
	if (P.is_status_update) {
		var U = P.entity.avatar_url;
		if (P.entity.avatar_url_big) {
			U = P.entity.avatar_url_big
		}
		B += '<a href="' + P.entity.profile_url + '" class="l_pb sta" rel="'
				+ P.entity.entity_id + '"><img src="' + U + '"></a>';
		if (P.message_orig && P.message_orig.length > 220) {
			B += '<h1 class="s">' + P.message + "</h1>"
		} else {
			B += "<h1>" + P.message + "</h1>"
		}
		B += '<div class="ctrls">';
		B += '<div class="sub">';
		if (!P.dm) {
			B += '<div class="btn sel l_sm"><span class="opt"></span>';
			B += ' <div class="drop_down" style="display:none;">';
			B += '<div class="conn"></div>';
			if (P.is_shared) {
				B += '<a href="" class="l_hm l_qshare" rel="' + P.post_id + '"><span></span>Unshare post</a>'
			}
			if (gStream && gStream.can_edit) {
				B += '<a href="" class="l_hm l_qdelete" rel="' + P.post_id + '"><span class="msg" ></span>Remove from stream</a>';
				if (isPostFeatured) {
					B += '<a href="" class="l_hm l_remove_as_featured" rel="' + P.post_id + '"><span></span>Remove as featured</a>'
				} else {
					B += '<a href="" class="l_hm l_mark_as_featured" rel="' + P.post_id + '"><span></span>Mark as featured</a>'
				}
			}
			B += '<a href="' + P.perma_url + '" target="_blank" class="l_hm no_l"><span></span>Direct link</a>';
			B += "</div></div>"
		}
		B += "</div>";
		B += '<div class="i"><span></span><a href="' + P.perma_url
				+ '" target="_blank" title="Direct link">' + P.time
				+ "</a></div>";
		if (!P.dm) {
			B += '<a href="" class="act l_read_later" rel="' + P.post_id + '"><span></span><em>Mark for later</em><u>Marked for later</u></a>';
			B += '<a href="" class="act l_qshare" rel="' + P.post_id + '"><span></span><em>Share</em><u>Shared</u></a>';
			B += '<a href="" class="act l_like" rel="' + P.post_id + '"><span></span><em>Like</em><u>Liked</u></a>';
			B += '<a href="" class="act l_reshare" rel="' + P.post_id + '"><span></span>Reshare</a>'
		}
		B += "</div>"
	} else {
		B += '<h1 class="art"><a href="' + P.url + '" target="_blank">'
				+ P.title + "</a></h1>";
		B += '<div class="ctrls art">';
		B += '<div class="sub">';
		if (!P.dm) {
			B += '<div class="btn sel l_sm"><span class="opt"></span>';
			B += ' <div class="drop_down" style="display:none;">';
			B += '<div class="conn"></div>';
			if (P.is_shared) {
				B += '<a href="" class="l_hm l_qshare" rel="' + P.post_id + '"><span></span>Unshare post</a>'
			}
			if (gStream && gStream.can_edit) {
				B += '<a href="" class="l_hm l_qdelete" rel="' + P.post_id + '"><span class="msg" ></span>Remove from stream</a>';
				if (isPostFeatured) {
					B += '<a href="" class="l_hm l_remove_as_featured" rel="' + P.post_id + '"><span></span>Remove as featured</a>'
				} else {
					B += '<a href="" class="l_hm l_mark_as_featured" rel="' + P.post_id + '"><span></span>Mark as featured</a>'
				}
			}
			B += '<a href="' + P.perma_url + '" target="_blank" class="l_hm no_l"><span></span>Direct link</a>';
			B += "</div></div>"
		}
		B += "</div>";
		B += '<div class="i"><span></span><a href="' + P.perma_url
				+ '" target="_blank" title="Direct link">' + P.time
				+ "</a></div>";
		if (!P.dm) {
			B += '<a href="" class="act l_read_later" rel="' + P.post_id + '"><span></span><em>Mark for later</em><u>Marked for later</u></a>';
			B += '<a href="" class="act l_qshare" rel="' + P.post_id + '"><span></span><em>Share</em><u>Shared</u></a>';
			B += '<a href="" class="act l_like" rel="' + P.post_id + '"><span></span><em>Like</em><u>Liked</u></a>';
			B += '<a href="" class="act l_reshare" rel="' + P.post_id + '"><span></span>Reshare</a>'
		}
		B += "</div>";
		if (P.content) {
			B += "<p>" + P.content + "</p>"
		}
	}
	if (P.attachment && P.attachment.length > 0) {
		for (K in P.attachment) {
			var V = P.attachment[K];
			if (P.auto) {
				continue
			}
			if (V.type == "video") {
				B += '<div class="att_video">' + V.player + "</div>"
			}
			if (V.type == "image") {
				B += '<div class="att_photo"><img src="' + V.image_src + '"/></div>'
			}
		}
	}
	B += "</div>";
	if (P.geo) {
		B += '<div class="str_location">';
		B += '<img src="http://maps.google.com/maps/api/staticmap?zoom=15&size=175x100&maptype=roadmap&markers='
				+ P.geo.latitude + "," + P.geo.longitude + '&sensor=false">';
		B += "<h5>Streaming from here:</h5>";
		B += '<span style="display:inline"></span>';
		B += '<p><a href="" onclick="return false;">Launch interactive map &rarr;</a></p>';
		B += "</div>"
	}
	if (P.count_likes + P.count_shares > 0) {
		B += '<div class="like_count">';
		B += "<h4>Liked & Reshared by";
		if (P.count_likes && P.liked_by[0]) {
			B += ' <a href="' + P.liked_by[0]["profile_url"] + '">'
					+ P.liked_by[0]["display_name"] + "</a>"
		} else {
			if (P.count_shares && P.shared_by[0]) {
				B += ' <a href="' + P.shared_by[0]["profile_url"] + '">'
						+ P.shared_by[0]["display_name"] + "</a>"
			}
		}
		if (P.count_likes + P.count_shares > 1) {
			B += " and " + (P.count_likes + P.count_shares - 1) + " others"
		}
		B += "</h4>";
		M = 0;
		if (P.count_likes > 0) {
			for (K in P.liked_by) {
				B += '<a href="' + P.liked_by[K]["profile_url"]
						+ '" class="l_pb s" rel="' + P.liked_by[K]["entity_id"]
						+ '"><img src="' + P.liked_by[K]["avatar_url"]
						+ '"><span><u></u>' + P.liked_by[K]["display_name"]
						+ "</span></a>";
				M += 1;
				if (M >= 12) {
					break
				}
			}
		}
		if (P.count_shares > 0) {
			for (K in P.shared_by) {
				B += '<a href="' + P.shared_by[K]["profile_url"]
						+ '" class="l_pb" rel="' + P.shared_by[K]["entity_id"]
						+ '"> <img src="' + P.shared_by[K]["avatar_url"]
						+ '"></a>';
				M += 1;
				if (M >= 12) {
					break
				}
			}
		}
		B += "</div>"
	}
	B += '<div class="cont_switch">';
	B += '<a href="" class="stats l_post_stats" title="Item stats"></a><a href="" class="active l_all_comments">All comments</a> <a href="" class="l_my_comments">My network only</a>';
	B += "</div>";
	B += '<div class="i_list comm">';
	for (i in P.comments) {
		var C = P.comments[i];
		B += renderComment(C)
	}
	B += "</div>";
	B += "</div>";
	var C = $("#read_pane");
	var D = $("#main_pane");
	if (C.length == 0) {
		C = $('<div id="read_pane" rel="' + gSrollContainer.scrollTop() + '"></div>');
		$("#container").append(C)
	}
	C.html("");
	D.hide();
	C.show();
	C.append(B);
	if ($("#cust_header").length >= 1) {
		$("#cust_header").css("margin-top", "-101px")
	}
	$("#read_pane .like").removeClass("active");
	$("#read_pane .share").removeClass("active");
	if (P.is_liked) {
		$("#read_pane .l_like").addClass("active")
	}
	if (P.is_shared) {
		$("#read_pane .l_qshare").addClass("active")
	}
	if (P.is_read_later) {
		$("#read_pane .l_read_later").addClass("active")
	}
	if (P.geo) {
		C = new google.maps.Geocoder();
		var E = new google.maps.LatLng(P.geo.latitude, P.geo.longitude);
		var D = {
			zoom : 15,
			center : E,
			mapTypeControl : false,
			navigationControlOptions : {
				style : google.maps.NavigationControlStyle.SMALL
			},
			mapTypeId : google.maps.MapTypeId.ROADMAP
		};
		C.geocode( {
			latLng : E
		}, function(results, status) {
			$(".str_location span").html(results[0].formatted_address)
		})
	}
	if (Favit.user) {
		addComment(null, {
			post_id : P.post_id
		})
	} else {
		addCommentExplanation(null, {
			post_id : P.post_id
		})
	}
	var K = function(A) {
		if (A.keyCode == 27) {
			closePost();
			gSrollContainer.unbind("keyup")
		}
	};
	if (typeof gSrollContainer != "undefined" && gSrollContainer) {
		gSrollContainer.scrollTop(0)
	}
	gSrollContainer.unbind("keyup").bind("keyup", K)
};
var showAllComments = function(A) {
	tActive(A);
	$("#read_pane .i_list.comm .s").show()
};
var showMyNetworkComments = function(A) {
	tActive(A);
	$("#read_pane .i_list.comm .s").hide();
	$("#read_pane .i_list.comm .my, #comment_frm").show()
};
var showPostStats = function(A) {
	C = {
		post_id : gHolder.post_id
	};
	fPopup.show( {
		view : "stats",
		params : C
	})
};
clickHandlers.my_comments = showMyNetworkComments;
clickHandlers.all_comments = showAllComments;
clickHandlers.post_stats = showPostStats;
var renderComment = function(C) {
	if (C == null || !C || typeof C == "undefined"
			|| typeof C.entity == "undefined") {
		return ""
	}
	var D = "s";
	if (C.in_reply_to) {
		D += " r"
	}
	if ((typeof C.entity.is_following != "undefined" && C.entity.is_following)
			|| (C.entity.entity_id == Favit.user)) {
		D += " my"
	}
	B = "";
	var _comment = C.comment.replace(/(\r\n)|(\n)/g, "<br />");
	B += '<div class="' + D + '" id="c' + C.comment_id + '">';
	B += '<a href="' + C.entity.profile_url + '" class="a"><img src="'
			+ C.entity.avatar_url + '"></a>';
	B += '<div class="c">';
	B += '<div class="r"><div class="c_autor">';
	B += '<a href="' + C.entity.profile_url + '">' + C.entity.display_name
			+ "</a> @" + C.entity.nickname + " said...";
	B += "</div></div>";
	B += "<h2>" + _comment + "</h2>";
	B += '<div class="i">';
	B += '<div class="w">';
	B += '<a href="" class="l_add_comment"  params="{\'post_id\':\''
			+ C.post_id + "','irt':'" + C.comment_id + "','at':'"
			+ C.entity.nickname + "','dn':'" + C.entity.display_name
			+ '\'}"><span class="reply"></span>Reply @' + C.entity.nickname
			+ "</a>";
	B += "</div>";
	if (C.service_name) {
		B += '<div class="m">shared <a href="">' + C.time
				+ ' ago</a> via <a href="">' + C.service_name + "</a></div>"
	} else {
		B += '<div class="m">shared <a href="">' + C.time + " ago</a></div>"
	}
	B += "</div></div></div>";
	return B
};
clickHandlers.post = postClick;
var giveNavigateFocus = focusinHandlers.navigate = function(A) {
	setupSearchBox(A)
};
focusoutHandlers.comment_area = function(A) {
	var B = A.val();
	if ((A[0].originalValue && A[0].originalValue == B) || B.length == 0) {
		A.val(A[0].originalValue)
	}
};
var expandCommentBox = focusinHandlers.comment_area = function(A) {
	A.addClass("active");
	$("#comment_frm .c_ctrls").show()
};
clickHandlers.toaddedit = function(A) {
	var sharenow = $(A).parents("#share_now");
	if (!sharenow.length) {
		sharenow = $
	}
	sharenow.find(".l_tolist").addClass("active");
	if (A.hasClass("article")) {
		shareSetupToBox($("#hdr_article"), "article")
	} else {
		shareSetupToBox(sharenow)
	}
};
function checkField(A) {
	A = $(A);
	var B = $.trim(A.val());
	if (A.length > 0 && A[0] && A[0].originalValue && A[0].originalValue == B) {
		B = ""
	}
	if (B.length == 0) {
		A.focus()
	}
	return B.length > 0
}
clickHandlers.link = function(A) {
	var B = $("#link_picker");
	if (B.length == 0) {
		B = '<div class="media_select" id="link_picker">';
		B += '<h3 class="is_link"><a class="close l_close_spanel" href=""></a>Attach a link</h3>';
		B += '<div class="photo_preview is_other" id="link_preview">';
		B += '<div class="clear"></div>';
		B += "</div>";
		B += '<input type="text" size="65" class="l_image_url" id="link_url">';
		B += '<a class="btn small l_link_preview" href="">Attach</a> </div>';
		$("#share_tools").append(B)
	}
};
clickHandlers.premvoe = function(A) {
	A.parent().remove()
};
clickHandlers.tservice = function(A) {
	A.toggleClass("active");
	var sharenow = $(A).parents("#share_now");
	if (!sharenow.length) {
		sharenow = $
	}
	if (A.is(":checked")) {
		var P = false;
		sharenow.find(".l_tolist").find(".l_tocard").each(function() {
			if ($(this).attr("eid") && $(this).attr("eid") == Favit.user) {
				P = true
			}
		});
		if (!P) {
			sharenow
					.find(".l_tolist")
					.prepend(
							'<li class="l_tocard public" eid="' + Favit.user + '"><span>My profile</span><img class="l_toremove" src="/static/1.417/images/to-delete.png" title="Delete" /></li>')
		}
	}
};
clickHandlers.location = function(A) {
	var sharenow = $(A).parents("#share_now");
	if (navigator.geolocation) {
		if (A.hasClass("selected")) {
			sharenow.find("#longitude").remove();
			sharenow.find("#latitude").remove();
			sharenow.find("#geo_address").html("").hide();
			sharenow.find("#add_location").show()
		} else {
			var S = function(B) {
				var G = sharenow;
				if (G.length == 0) {
					G = $("#menu_article_share")
				}
				G
						.append('<input type="hidden" name="longitude" id="longitude" value="' + B.coords.longitude + '"/>');
				G
						.append('<input type="hidden" name="latitude" id="latitude" value="' + B.coords.latitude + '"/>');
				C = new google.maps.Geocoder();
				var E = new google.maps.LatLng(B.coords.latitude,
						B.coords.longitude);
				C
						.geocode(
								{
									latLng : E
								},
								function(results, status) {
									sharenow
											.find("#geo_address")
											.html(
													results[0].address_components[0]["long_name"]
															+ "<br>"
															+ results[0].address_components[1]["long_name"]
															+ ", "
															+ results[0].address_components[3]["long_name"]
															+ '<a href="#" class="l_location selected" title="Remove location">&nbsp;</a>')
								})
			};
			var E = function(B) {
				clickHandlers.location(A)
			};
			if (A.attr("rel") != "article") {
				sharenow.find("#geo_address").html("Getting you location...")
						.show();
				sharenow.find("#add_location").hide()
			}
			navigator.geolocation.getCurrentPosition(S, E)
		}
		A.toggleClass("selected")
	} else {
		sharenow.find("a.l_location").remove()
	}
	$("#slider .scroll_pane").jScrollPane()
};
clickHandlers.stream_share = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = $("#is_shared_chk").is(":checked") ? true : false;
	if (B) {
		var A = $("#str_nickname").val();
		A = $.trim(A);
		if (A.length == 0) {
			$("#str_nickname").focus().hide().fadeIn();
			return
		}
		var B = $("#stream_desc").val();
		B = $.trim(B);
		if (B.length == 0) {
			$("#stream_desc").focus().hide().fadeIn();
			return
		}
		var C = [];
		$(".cat_list input").each(function(i, el) {
			A = $(el);
			if (A.is(":checked")) {
				C[i] = A.val()
			}
		});
		if (C.length == 0) {
			alert("Please select at least one category");
			return
		}
	}
	$("#share_stream_frm :input").attr("disabled", false);
	$("#share_stream_frm").submit()
};
clickHandlers.stream_edit = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $("#new_stream_name");
	var title = A.val();
	if (title.length == 0 || A[0].originalValue == title
			|| A.css("color") == "red") {
		A.focus();
		return
	}
	var add_filters = $("#filter_stream").hasClass("active");
	var is_sharing = $("#sharing_stream").hasClass("active");
	var filters = [];
	if (add_filters) {
		A = $("#filter_area").val();
		if (A.length > 0) {
			filters = A.split(",")
		}
	}
	if (add_filters && filters.length == 0) {
		alert("Please type some filter keywords");
		$(".textboxlist-bit-editable-input").focus();
		return
	}
	var filter_area = 0;
	var FC = [ "filter_all", "filter_my_network", "filter_custom" ];
	for (K in FC) {
		if ($("#" + FC[K]).hasClass("active")) {
			filter_area = $("#" + FC[K]).attr("rel");
			break
		}
	}
	var selected = [];
	for (i in sEntities) {
		if (sEntities.hasOwnProperty(i)) {
			selected.push(i)
		}
	}
	if (selected.length == 0
			&& !is_sharing
			&& (!add_filters || (add_filters && $("#filter_custom").hasClass(
					"active")))) {
		alert("Please select at least one user or feed from your network");
		return
	}
	var B = $("#new_stream_nickname");
	var nickname = $.trim(B.val());
	var stream_order = $('input[name="stream_order"]:checked').val() || "";
	var share_twitter = $("#ext_acc_twitter2").is(":checked");
	var share_facebook = $("#ext_acc_facebook2").is(":checked");
	var B = {
		title : title,
		entities : selected,
		is_filtered : add_filters,
		is_sharing : is_sharing,
		filters : filters || [],
		filter_area : filter_area,
		order : stream_order,
		notify : {
			twitter : share_twitter,
			facebook : share_facebook
		}
	};
	var C = $("#stream_id");
	if (C.length > 0) {
		B.stream_id = C.val()
	}
	$("#stream_loading").show();
	$.post("/managestream", B, function(D) {
		try {
			if (!D.error) {
				var G = D.edit_mode;
				window.location.href = D.stream_url
			}
		} catch (e) {
		}
		$("#stream_loading").hide()
	}, "json")
};
function setShareControls(A) {
	if (A) {
		$("#sharing_controllers").show();
		$("#sharing_controllers :input").removeAttr("disabled")
	} else {
		$("#sharing_controllers").hide();
		$("#sharing_controllers :input").attr("disabled", "disabled")
	}
}
function fseo_init() {
	var S = $('input[name="stream_access"]:checked').val();
	var X = [ 'public', 'moderated', 'private' ];
	for (i in X) {
		$('#subscribe_message_' + X[i]).attr('name',
				'subscribe_message_' + X[i]);
		$('#' + X[i] + '_message').hide();
	}
	$('#subscribe_message_' + S).attr('name', 'subscribe_message');
	$('#' + S + '_message').show();
}
clickHandlers.fseo = function(A, H, Y) {
	var cb = function() {
		var S = $('input[name="stream_access"]:checked').val();
		var X = [ "public", "moderated", "private" ];
		for (i in X) {
			$("#subscribe_message_" + X[i]).attr("name",
					"subscribe_message_" + X[i]);
			$("#" + X[i] + "_message").hide()
		}
		$("#subscribe_message_" + S).attr("name", "subscribe_message");
		$("#" + S + "_message").show()
	};
	if (Y) {
		Y = $(Y);
		if (Y[0].tagName == "INPUT") {
			if (Y.attr("name") == "is_shared") {
				setShareControls(Y.is(":checked"))
			}
			fseo_init();
			return true
		}
	}
	if (!A.is(".expl")) {
		A = A.parents(".expl")
	}
	$(".expl").addClass("gray");
	A.removeClass("gray");
	var C = A.find("input");
	var B = C.attr("checked");
	if (!C.is(":disabled")) {
		C.attr("checked", !B)
	}
	if (A.hasClass("sh_str")) {
		setShareControls(!B)
	}
	cb()
};
clickHandlers.show_welcome_cust = function(A) {
	$("#customize_message").show();
	$(A).hide()
};
clickHandlers.sel_s_cats = function(A, B, C) {
	var selected = $("div.cat_list input:checked").size();
	$("div.cat_list input").each(function(i, e) {
		if (!$(e).is(":checked")) {
			if (selected < 3) {
				$(e).removeAttr("disabled")
			} else {
				$(e).attr("disabled", "disabled")
			}
		}
	});
	return !(selected >= 4)
};
var getPostData = function(A) {
	if (typeof gPdata != "undefined" && gPdata) {
		for (i in gPdata) {
			var P = gPdata[i];
			if (P.post_id == A) {
				return P
			}
		}
	}
	return null
};
var setPostData = function(A, B) {
	if (typeof gPdata != "undefined" && gPdata) {
		for (i in gPdata) {
			var P = gPdata[i];
			if (P.post_id == A) {
				gPdata[i] = B;
				return true
			}
		}
	}
	return false
};
var isset = function(A) {
	return typeof A != "undefined"
};
var addComment = function(A, C, D) {
	var X = $("#comment_frm");
	X.remove();
	if (C.post_id) {
		var G = getPostData(C.post_id);
		C.view_id = G.view_id;
		C.vt = G.view_type;
		var F = false;
		var CL = "s add";
		if (C.irt) {
			CL = "s add r"
		}
		var B = '<div class="' + CL + '" id="comment_frm">';
		B += '<a href="' + Favit.u_avatar + '" class="a"><img src="'
				+ Favit.u_avatar + '"></a>';
		B += '<div class="c">';
		B += '<textarea class="l_comment_area" name="comment_msg" id="comment_msg" hotkeys="shift+enter">Write your comment...</textarea>';
		B += '<div class="c_ctrls" id="com_ctrls">';
		B += '<div class="sub"><a href="" class="btn w_text l_publish_comment"><span class="add"></span><strong class="is_c">Publish comment</strong><strong class="is_r">Post reply</strong></a><span class="is_r"><a href="" class="l_cancel_comment">Cancel</a></span></div>';
		if (isset(Favit.facebook) && G.spread_facebook) {
			B += '<label><input name="es[]" type="checkbox" value="9" ';
			if (isset(Favit.facebook_auto_stream)) {
				B += "checked"
			}
			B += "> Publish on Facebook</label>";
			F = true
		}
		if (isset(Favit.twitter) && G.spread_twitter) {
			B += '<label><input name="es[]" type="checkbox" value="6" ';
			if (isset(Favit.twitter_auto_stream)) {
				B += "checked"
			}
			B += "> Publish on Twitter</label>";
			F = true
		}
		B += "</div>";
		B += "</div>";
		B += "</div>";
		B = $(B);
		B.data("params", C);
		D = D || false;
		var G = !D ? $("#read_pane .comm") : $(".comm:eq(0)");
		if (C.irt) {
			G = $("#c" + C.irt);
			while (G.next().is(".r")) {
				G = G.next()
			}
			G.after(B)
		} else {
			G.append(B)
		}
		if (A == null) {
			B.show()
		} else {
			var S = function() {
				gSrollContainer.animate( {
					scrollTop : A.scrollTop()
				})
			};
			B.fadeIn("fast", S)
		}
	}
};
var addCommentExplanation = function(A, C) {
	var X = $("#comment_expl");
	X.remove();
	if (C.post_id) {
		var B = '<div id="comment_expl">';
		B += 'You have to be Favit user to add comments. <a href="/signup" class="l_not_logged_in">Sign up now</a>.';
		B += "</div>";
		B = $(B);
		var G = $("#read_pane .comm");
		G.append(B)
	}
};
var quickComment = function(A) {
	var B = getPostIdByElement(A);
	if (!B) {
		return
	}
	var rt = null;	
	if (A.parents('.i').length) {
		rt = A.parents('.i').attr('rel');
	}
	var G = getPostData(B);
	var C = {
		view_id : G.view_id,
		vt : G.view_type,
		irt: rt,
		service : G.service_id,
		param : B
	};
	fPopup.show( {
		view : "quick_comment_new",
		params : C
	})
};
clickHandlers.qcomment = quickComment;
var publishQuickComment = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	if (A.hasClass("done")) {
		return
	}
	var B = $(".qcomment textarea[name='comment_msg']");
	var C = $(".qcomment input[name='post_id']");
	var E = $(".qcomment input[name='irt']");
	if (checkField(B)) {
		A.addClass("done");
		var D = getPostData(C.val());
		if (D) {
			var X = [];
			$(".qcomment .l_tservice").each(function(I) {
				var A = $(this);
				if (A.is(":checked")) {
					X.push(A.val())
				}
			});
			var Y = E.val()

			var P = {
				post_id : D.post_id,
				comment : B.val(),
				view_id : D.view_id,
				vt : D.view_type,
				"es[]" : X,
				irt : Y
			};
			var CB = function(F) {
				$("#g_load").hide();
				$("#comment_frm .ld").hide();
				var P = getPostData(F.post_id);
				if (typeof P.comments == "undefined" || !P.comments) {
					P.comments = []
				}
				P.comments.push(F);
				var pCount = parseInt($("#p" + F.post_id + " .ccount").text());
				$("#p" + F.post_id + " .ccount").text(pCount + 1);
				$("#p" + F.post_id + " .ccount").removeClass("empty").animate( {
					"background-color" : "#639343"
				}, "fast").addClass("active");
				addComment(null, F);
				setPostData(F.post_id, P);
				fPopup.close()
			};
			$("#g_load").show();
			$.post("/a/post_comment", P, CB, "json")
		} else {
			alert("can not locate post")
		}
	}
};
clickHandlers.quickcomment = publishQuickComment;
var closeModal = function(A) {
	A.parents(".modal").fadeOut("fast", function() {
		$(this).remove()
	})
};
clickHandlers.close_modal = closeModal;
var publishComment = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var C = $("#comment_msg");
	$("#comment_frm .ld").show();
	C.attr("disabled", "disabled");
	var B = $("#comment_frm").data("params") || [];
	if (A.attr("rel")) {
		B.post_id = A.attr("rel")
	}
	var P = getPostData(B.post_id);
	if (!B.view_id) {
		B.view_id = P.view_id
	}
	if (!B.vt) {
		B.vt = P.view_type
	}
	if (checkField(C)) {
		if (A.hasClass("done")) {
			return
		}
		A.addClass("done");
		var X = [];
		d($("#com_ctrls input[name^=es]"));
		$("#com_ctrls input[name^=es]").each(function(I) {
			var A = $(this);
			if (A.is(":checked")) {
				X.push(A.val())
			}
		});
		Y = B.irt || "";
		var P = {
			post_id : B.post_id,
			comment : C.val(),
			view_id : B.view_id,
			vt : B.vt,
			"es[]" : X,
			irt : Y
		};
		if (gStream) {
			P.sid = gStream.stream_id
		}
		var D = function(F) {
			if (F && F.flood) {
				A.removeClass("done");
				C.removeAttr("disabled");
				alert(F.flood);
				return false;
			}
			$("#comment_frm .ld").hide();
			var M = renderComment(F);
			M = $(M);
			var G = $("#read_pane .comm");
			if (F.in_reply_to) {
				G = $("#c" + F.in_reply_to);
				while (G.next().is(".r")) {
					G = G.next()
				}
				G.after(M)
			} else {
				M.insertBefore($("#comment_frm"))
			}
			var P = getPostData(F.post_id);
			if (typeof P.comments == "undefined" || !P.comments) {
				P.comments = []
			}
			P.comments.push(F);
			var pCount = parseInt($("#p" + F.post_id + " .ccount").text());
			$("#p" + F.post_id + " .ccount").text(pCount + 1);
			$("#p" + F.post_id + " .ccount").removeClass("empty").animate( {
				"background-color" : "#639343"
			}, "fast").addClass("active");
			addComment(null, F);
			setPostData(F.post_id, P)
		};
		$.post("/a/post_comment", P, D, "json")
	}
};
function getPostIdByElement(A) {
	var P = gHolder.post_id;
	if (A.attr("rel")) {
		P = A.attr("rel")
	}
	if (!P) {
		var E = A.parents(".l_post");
		if (E.length == 1) {
			P = E.attr("id").substr(1)
		}
	}
	if (!P) {
		return null
	}
	return P
}
var likePost = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	A.toggleClass("active");
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (A.parents("#p" + P).length == 0) {
		var D = $("#p" + P).find("a.l_like");
		D.toggleClass("active")
	}
	var C = A.hasClass("active");
	var B = {};
	B.post_id = P;
	B.like = C;
	var G = getPostData(P);
	B.view_id = G.view_id;
	B.vt = G.view_type;
	if (gStream) {
		B.sid = gStream.stream_id
	}
	$.post("/a/like", B, function(D) {
		var I = getPostData(D.post_id);
		I.is_liked = C;
		setPostData(D.post_id, I);
		$("#p" + D.post_id + " .li").html(D.count_likes)
	}, "json")
};
var quickSharePost = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$(A).toggleClass("active");
	var C = $(A).hasClass("active");
	var B = {};
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (A.parents("#p" + P).length == 0) {
		var D = $("#p" + P).find("a.l_qshare");
		D.toggleClass("active")
	}
	B.qickshare = C;
	B.post_id = P;
	var G = getPostData(P);
	B.view_id = G.view_id;
	B.vt = G.view_type;
	B.is_status = G.is_status_update;
	$.post("/a/quickshare", B, function(D) {
		var I = getPostData(D.post_id);
		I.is_shared = C;
		setPostData(D.post_id, I)
	}, "json")
};
var resharePost = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = getPostIdByElement(A);
	if (!B) {
		return
	}
	var cb = function(R) {
		$("#share_now").append(
				'<input type="hidden" name="post_id" value="' + B + '"/>');
		var P = getPostData(B);
		var E = {};
		if (!P.is_status_update) {
			E.title = P.title;
			E.desc = P.short_content;
			E.url = P.url;
			E.preview_img = P.thumb_src || "";
			linkCallback(E, $("#share_now"))
		} else {
			if (P.attachment.length) {
				var E = P.attachment[0];
				if (E.type == "video" && typeof E.video_url != undefined) {
					$.get("/a/preview_link", {
						url : E.video_url
					}, function(R) {
						linkCallback(R, $("#share_now"))
					}, "json")
				} else {
					E.title = E.title || "";
					E.desc = E.desc || "";
					E.url = E.image_src || "";
					E.preview_img = E.image_src || null;
					linkCallback(E, $("#share_now"))
				}
			} else {
				var html = "";
				html += '<img class="a" src="' + P.entity.avatar_url + '">';
				html += '<p class="t">' + P.entity.display_name + " <span>@"
						+ P.entity.nickname + "</span></p>";
				html += "<p>" + P.message + "</p>";
				$("#share_now").find(".reply_item").html(html).show()
			}
		}
		Z = $("#share_now");
		Z.find("#attach").remove();
		if (R && R._asl) {
			clickHandlers.location($(".l_location:eq(0)"))
		}
	};
	fPopup.show( {
		view : "share",
		params : {
			cb : cb,
			act : 2
		}
	})
};
var sharePost = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var cb = function(R) {
		var B = new Array();
		if (R && R._asl) {
			clickHandlers.location($(".l_location:eq(0)"))
		}
		if (A.hasClass("dShare")) {
			B.stream_id = A.attr("rel");
			B.title = A.attr("title");
			B.can_write = true;
			if (A.hasClass("isPrivate")) {
				B.is_private = true
			}
		} else {
			if (gStream) {
				B = gStream
			}
		}
		if (B.stream_id && B.can_write) {
			Z = $("#popupBubble").find("#share_now");
			W = Z.find(".l_tocard:eq(0)");
			if (W.length) {
				var Y = W.clone();
				Y.removeAttr("eid").attr("sid", B.stream_id);
				if (B.is_private) {
					Y.removeClass("public").addClass("private")
				}
				Y.find("span:eq(0)").html(B.title);
				W.after(Y)
			}
			if (B.is_private) {
				W.remove()
			}
		}
	};
	fPopup.show( {
		view : "share",
		params : {
			cb : cb,
			act : 1
		}
	})
};
var quickResharePost = function(X) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var sharewith = [];
	var streams = [];
	var P = $("#post_id").val();
	$("#shareWith").find(".l_tocard").each(function(E, F) {
		var G = $(F).attr("eid");
		if (G) {
			sharewith.push(G)
		}
		var D = $(F).attr("sid");
		if (D) {
			streams.push(D)
		}
	});
	if (sharewith.length == 0 && streams.length == 0) {
		$("#shareWith").find(".l_toinput").select().focus();
		return false
	}
	var A = [];
	$("#share_now input[name=es[]]").each(function(C) {
		var B = $(this);
		if (B.attr("checked")) {
			A.push(B.attr("value"))
		}
	});
	var B = {
		post_id : P,
		sharewith : sharewith,
		streams : streams,
		es : A,
		qickshare : true
	};
	var G = getPostData(P);
	B.view_id = G.view_id;
	B.vt = G.view_type;
	$.post("/a/quickshare", B, function(D) {
		var I = getPostData(D.post_id);
		if (I) {
			I.is_shared = true;
			setPostData(D.post_id, I)
		}
		closeModal(X)
	}, "json")
};
clickHandlers.quickresharepost = quickResharePost;
var read_later = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$(A).toggleClass("active");
	var C = $(A).hasClass("active");
	var B = {};
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (A.parents("#p" + P).length == 0) {
		var D = $("#p" + P).find("a.l_read_later");
		D.toggleClass("active")
	}
	B.readlater = C;
	B.post_id = P;
	var G = getPostData(P);
	B.view_id = G.view_id;
	B.vt = G.view_type;
	$.post("/a/readlater", B, function(D) {
		var I = getPostData(D.post_id);
		I.is_read_later = C;
		setPostData(D.post_id, I)
	}, "json")
};
var mark_as_featured = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (gStream) {
		var B = {
			post_id : P,
			sid : gStream.stream_id
		};
		var G = getPostData(P);
		B.view_id = G.view_id;
		B.vt = G.view_type;
		$.post("/a/mark_featured_post", B, function(C) {
			if (C.stream) {
				gStream = C.stream;
				A.removeClass("l_mark_as_featured").addClass(
						"l_remove_as_featured").text("Remove as featured")
			}
		}, "json")
	}
};
var remove_as_featured = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (gStream) {
		var B = {
			post_id : P,
			sid : gStream.stream_id
		};
		$.post("/a/remove_featured_post", B, function(C) {
			if (C.stream) {
				gStream = C.stream;
				A.removeClass("l_remove_as_featured").addClass(
						"l_mark_as_featured").text("Mark as featured")
			}
		}, "json")
	}
};
var qdelete = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var P = getPostIdByElement(A);
	if (!P) {
		return
	}
	if (confirm("Are you sure you want to remove the selected post from the stream")
			&& gStream) {
		var B = {
			post_id : P,
			sid : gStream.stream_id
		};
		$.post("/a/delete_post", B, function(C) {
			if (C.ok) {
				$("#p" + P).children().fadeOut("slow");
				A.remove()
			}
		}, "json")
	}
};
clickHandlers.reshare = resharePost;
clickHandlers.doshare = sharePost;
clickHandlers.qshare = quickSharePost;
clickHandlers.like = likePost;
clickHandlers.read_later = read_later;
clickHandlers.qdelete = qdelete;
clickHandlers.mark_as_featured = mark_as_featured;
clickHandlers.remove_as_featured = remove_as_featured;
pasteHandlers.detect_link_paste = function(A) {
	setTimeout(
			function() {
				var sharenow = $(A).parents("#share_now");
				//var urlregex = new RegExp("^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$");
				// regexp copied from jquery's validation plugin
				if (/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test($(A).val())) {
					var el = sharenow.find($(A).attr("rel"));
					var val = null;
					if (A[0].tagName == "TEXTAREA") {
						el = sharenow.find("a.attach.link");
						val = A.val()
					}
					shareMedia(el, val)
				}
			}, 500)
};
focusinHandlers.expand_share_box = function(A, B, C, D) {
	var sharenow = $(A).parents("#share_now");
	sharenow.removeClass("disabled")
};
clickHandlers.collapse_share_box = function(A, B, C, D) {
	var sharenow = $;
	if ($(A).attr("id") == "share_now") {
		sharenow = $(A)
	} else {
		sharenow = $(A).parents("#share_now")
	}
	if (sharenow.parents(".bubble").length) {
		fPopup.close();
		return
	}
	sharenow.addClass("disabled");
	sharenow.find(".preview_article_share").html("").hide();
	sharenow.find(".preview_image_share").html("").hide();
	sharenow.find(".attach_link").hide();
	sharenow.find(".attach_photo").hide();
	sharenow.find(".context_switcher").removeClass("active");
	sharenow.find(".context_switcher.status").addClass("active");
	sharenow.find(".attach_link_field").val("http://");
	sharenow.find(".attach_photo_field").val("http://");
	sharenow.find(".is_geo").removeClass("selected").show();
	sharenow.find(".geo").html("").hide();
	var shareArea = sharenow.find("#shareArea");
	shareArea.val(shareArea[0].originalValue).removeClass("is_photo").show();
	sharenow.find(".share_btn").removeClass("active");
	sharenow.find(".l_tservice").each(function(i, e) {
		if ($(e).attr("rel") == "sync") {
			$(e).attr("checked", "checked")
		}
	});
	sharenow.find("#shr_upload_loading").hide();
	var acl = '<li eid="'
			+ Favit.user
			+ '" class="l_tocard public"><span><lang>My profile</lang></span><img title="Delete" class="l_toremove" src="'
			+ Favit.images
			+ 'to-delete.png"></li><li class="addedit" style="display:inline;"><a href="" class="l_toaddedit btn w_text"><span class="add"></span><lang>Select recipients</lang></a></li><input type="text" maxlength="50" class="l_toinput ac_input" style="display: none;" autocomplete="off"><div class="clear"></div>';
	sharenow.find("#toList").html(acl)
};
clickHandlers.share_now = function(A) {
	var sharenow = $(A).parents("#share_now");
	shareAction(sharenow, $(A))
};
clickHandlers.share_article = function(A) {
	var sharenow = $(A).parents("#main_pane");
	shareAction(sharenow, $(A))
};
clickHandlers.expand_share_box_status = function(A, B, C, D) {
	var sharenow = $(A).parents("#share_now");
	sharenow.find(".context_switcher").removeClass("active");
	$(A).addClass("active");
	sharenow.find(".attach_photo").hide();
	sharenow.find(".attach_link").hide();
	sharenow.find(".preview_article_share").html("").hide();
	sharenow.find(".preview_image_share").html("").hide();
	sharenow.find("#shareArea").removeClass("is_photo").show()
};
clickHandlers.expand_share_box_link = function(A, B, C, D) {
	var sharenow = $(A).parents("#share_now");
	sharenow.find(".context_switcher").removeClass("active");
	$(A).addClass("active");
	sharenow.find(".attach_photo").hide();
	sharenow.find(".attach_link").show();
	sharenow.find(".preview_article_share").html("").hide();
	sharenow.find(".preview_image_share").html("").hide();
	sharenow.find("#shareArea").hide()
};
clickHandlers.expand_share_box_photo = function(A, B, C, D) {
	var sharenow = $(A).parents("#share_now");
	sharenow.find(".context_switcher").removeClass("active");
	$(A).addClass("active");
	sharenow.find(".attach_photo").show();
	sharenow.find(".attach_link").hide();
	sharenow.find(".preview_article_share").html("").hide();
	sharenow.find(".preview_image_share").html("").hide();
	sharenow.find("#shareArea").hide();
	sharenow.find("#shr_upload_loading").hide()
};
var cancelComment = function() {
	var B = $("#comment_frm");
	var P = B.data("params") || [];
	B.remove();
	addComment(null, {
		post_id : P.post_id
	})
};
clickHandlers.add_comment = addComment;
clickHandlers.cancel_comment = cancelComment;
clickHandlers.publish_comment = publishComment;
clickHandlers.add_stream = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.getJSON("/a/render/add_stream", {}, function(B) {
		$("#container").append($(B.html));
		recalcAreas()
	})
};
clickHandlers.add_service = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel");
	if (B) {
		var C = {
			sid : B,
			mode : A.attr("mode")
		};
		fPopup.show( {
			view : "service_editor",
			params : C
		})
	}
};
clickHandlers.acc_service = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var R = [ "service_value" ];
	var P = {};
	var V = true;
	$("#frm_addservice :input").each(function(I) {
		var A = $(this);
		var B = A.attr("name");
		if (R.indexOf(B) != -1) {
			V = V & checkField(A)
		}
		P[B] = A.val()
	});
	B = A.attr("rel");
	if (B) {
		P[B] = true
	}
	var S = A;
	if (V) {
		$("#adsloading").show();
		$
				.post(
						"/a/service_editor",
						P,
						function(A) {
							$("#adsloading").hide();
							if (A.error && A.exists) {
								alert("The profile you entered is already in your account");
								return
							}
							if (A.service_id) {
								var B = $("a[rel=" + A.service_id + "]");
								if (A.del) {
									B.attr("mode", "add");
									B.html("<strong>Link account</strong>")
								} else {
									if (!A.stream) {
										B.attr("mode", "edit");
										B.html("<strong>Edit/Unlink</strong>")
									} else {
										var G = $(".added_services");
										var H = $('<div><a href="" title="Remove source" class="l_service_delete_feed" rel="'
												+ A.feed_id
												+ '"></a><img src="/static/images/serv_favs/'
												+ A.icon
												+ '" width="16" height="16" /> '
												+ A.service_name + " </div>");
										H.hide();
										G.append(H);
										H.fadeIn()
									}
								}
								fPopup.close()
							} else {
								alert("Invalid nickname or url");
								$(S).focus()
							}
						}, "json")
	}
};
clickHandlers.service_delete_feed = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	A = $(A);
	var B = A.attr("rel");
	var C = A;
	if (B) {
		var P = {
			"delete" : true,
			feed_id : B
		};
		$.post("/a/service_editor", P, function(A) {
			C.parent().fadeOut()
		}, "json")
	}
};
var displayBrowse = function(A, cat_id) {
	var G = {};
	G.sort = $("#browse_order a.active").attr("rel");
	C = $("#browse_container");
	D = $("#browse_search");
	if ((D[0].originalValue && D[0].originalValue == D.val())
			|| D.val() == "Search or navigate your network...") {
		G.q = ""
	} else {
		G.q = D.val()
	}
	var B = "/browse/" + A + "/search?q=" + G.q;
	if (cat_id) {
		B += "&cat_id=" + cat_id
	}
	window.location.hash = B
};
changeHandlers.browse_category = function(A) {
	displayBrowse($("#browse_search").attr("rel"), A.val())
};
clickHandlers.msubmenu = function(A) {
	$("#menu a").removeClass("active");
	$("#menu li").removeClass("active");
	A.addClass("active");
	var D = A.attr("href");
	if (D) {
		window.location.hash = D
	}
};
function followPopup(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $(A).attr("rel");
	if (A) {
		fPopup.show( {
			view : "follow_popup",
			params : {
				eid : A
			}
		})
	}
	return false
}
var popupClose = function(A) {
	fPopup.close()
};
function subscribePopup(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	fPopup.show( {
		view : "subscribe_popup"
	});
	return false
}
clickHandlers.subscribe_popup = subscribePopup;
var quickFollow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel");
	var Z = A.hasClass("silent");
	if (B) {
		var C = {
			eid : B,
			quick : true,
			silent : Z
		};
		var L = $('<div class="load_recomm"></div>');
		if (A.hasClass("has_recommendations")) {
			if (A.parents(".c").length) {
				A.parents(".c").addClass("selected").append(L)
			} else {
				if (A.parents("#header").children("div.profile").length) {
					A.parents("#header").children("div.profile").after(L)
				}
			}
		}
		if (A.hasClass("intro_people")) {
			var parents = A.parents(".s");
			if (parents.length) {
				var img = parents.find("a.a > img");
				if (img.length) {
					var first = $("div.net_list.intro > a.empty:eq(0)");
					if (first.length) {
						first.removeClass("empty");
						first.attr("rel", A.attr("rel"));
						first.html('<img src="' + img.attr("src") + '" />');
						$("#people_next_step").hide()
					}
					if ($("div.net_list.intro > a.empty:eq(0)").length == 0) {
						$("#people_next_step").show()
					}
				}
			}
		}
		$
				.post(
						"/a/follow",
						C,
						function(D) {
							if (D && D.success) {
								A.parent().addClass("active");
								if (D.streams) {
									var E = A.parents("#suppl_c");
									if (E.length > 0) {
										var F = $("#fspick");
										if (F.length > 0) {
											F.children().remove()
										}
										F = $('<div id="fspick"></div>');
										F
												.append("<h4>Select the streams in which you wish to add "
														+ D.entity.display_name
														+ " to</h4>");
										var G = $('<div class="strm_alloc"/>');
										for (H in D.streams) {
											G
													.append('<label><input type="checkbox" name="stream[]" value="'
															+ D.streams[H].title
															+ '">'
															+ D.streams[H].title
															+ "</label>")
										}
										G.append('<div class="clear"/>');
										F.append(G);
										F.hide();
										E.append(F);
										F
												.append('<div style="text-align:right;"><a href="" class="btn submit l_follow">Add feed to streams</a></div>');
										F.fadeIn("fast")
									}
								}
								if (D.entity && !A.hasClass("intro_people")) {
									showInfoMessage(
											"You are now following "
													+ D.entity.display_name
													+ ' - <a href="" class="l_follow_popup" rel="'
													+ D.entity.entity_id
													+ '">include in streams →</a>',
											2000)
								}
								if (D.html) {
									var H = $(D.html);
									L.replaceWith(H);
									H.fadeIn(75)
								} else {
									L.remove()
								}
							}
						}, "json")
	}
};
var hideParentWithClass = function(A, B, C) {
	A.parents("." + B).fadeOut("fast", C)
};
var quickUnfollow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	if (A.hasClass("intro_people")) {
		var el = $('div.net_list.intro a[rel="' + A.attr("rel") + '"]');
		el.addClass("empty");
		el.html(el.index() + 1);
		if ($("div.net_list.intro > a.empty:eq(0)").length) {
			$("#people_next_step").hide()
		}
	}
	var B = A.attr("rel");
	if (B) {
		var C = {
			eid : B
		};
		$.post("/a/unfollow", C, function(D) {
			A.parent().removeClass("active");
			$("#fspick").fadeOut("fast", function() {
				$(this).remove()
			});
			if (A.parents(".s").children("div.recomm").length) {
				A.parents(".s").children("div.recomm").remove()
			}
		}, "json")
	}
};
clickHandlers.qunfollow = quickUnfollow;
clickHandlers.qfollow = quickFollow;
var quickReadlater = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel").split("_._");
	var W = A.hasClass("selected");
	if (B) {
		var C = {
			post_id : B[0],
			readlater : !W,
			view_id : B[1],
			vt : B[2]
		};
		$.post("/a/readlater", C, function(D) {
			if (D) {
				A.toggleClass("selected")
			}
		}, "json")
	}
};
clickHandlers.qReadlater = quickReadlater;
var quickBktShare = function(Z) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	Z.toggleClass("active");
	var A = $("#share_content");
	var message = A.val();
	var E = $("#post_title");
	var I = $("#post_status");
	if (I.val() == 1 && message == "") {
		A.focus();
		return
	}
	var B = $("#toList");
	var sharewith = [];
	var streams = [];
	var pages = [];
	B.find(".l_tocard").each(function(E, F) {
		var G = $(F).attr("eid");
		if (G) {
			sharewith.push(G)
		}
		var D = $(F).attr("sid");
		if (D) {
			streams.push(D)
		}
		D = $(F).attr("pid");
		if (D) {
			streams.push(D)
		}
	});
	if (sharewith.length == 0 && streams.length == 0 && pages.length == 0) {
		B.find(".l_toinput").select().focus();
		return false
	}
	B = $("#post_url");
	var url = B.val();
	var title = "";
	if (title == "") {
		var E = $("#post_title");
		if (E.length) {
			title = E.html()
		}
	}
	var content = "";
	if (I.val() == 0) {
		content = message;
		message = ""
	}
	var medias = [];
	$("img[name='medias[]']").each(function(i, el) {
		medias[i] = $(el).attr("src")
	});
	var A = [];
	var Y = $("#facebook_sync");
	var U = $("#twitter_sync");
	if (Y.hasClass("active")) {
		A.push(9)
	}
	if (U.hasClass("active")) {
		A.push(6)
	}
	var params = {
		url : url,
		content : content,
		title : title,
		message : message,
		medias : medias,
		sharewith : sharewith,
		streams : streams,
		es : A,
		service_id : 3,
		pages : pages
	};
	$.post("/a/share", params, function(X) {
		if (X) {
			$("#share_tab").html(X.html)
		}
		Z.toggleClass("active")
	}, "json")
};
clickHandlers.qBShare = quickBktShare;
var stream_follow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel");
	var L = $('<div class="load_top_followers" style="display:none;"></div>');
	if (A.hasClass("has_top_followers")) {
		if (A.parents(".s").length) {
			A.parents(".s").append(L);
			L.slideDown(75)
		} else {
			if (A.parents("#header").children("div.profile").length) {
				A.parents("#header").children("div.profile").after(L);
				L.slideDown(75)
			}
		}
	}
	var C = {
		sid : B
	};
	var inPopup = false;
	if (A.parents("#boxedStreams").length) {
		inPopup = true;
		C.show_in_popup = 1
	}
	$.post("/a/follow_stream", C, function(D) {
		if (D.success) {
			if (A.hasClass("list_intro_streams")) {
				$.get("/a/streams_intro_menu", {}, function(D) {
					if (D && D.html) {
						$("#streams_list_menu").html(D.html);
						if (D.count > 2) {
							$("#streams_next_step").show()
						} else {
							$("#streams_next_step").hide()
						}
					}
				}, "json")
			}
			A.parent().addClass("active");
			if (D.html) {
				if (inPopup) {
					L.remove();
					fPopup.show( {
						json : D
					})
				}
				var H = $(D.html);
				L.replaceWith(H);
				H.fadeIn(250)
			} else {
				L.remove()
			}
		} else {
			alert("Error occured. Favit team is notified")
		}
	}, "json");
	return false
};
var stream_unfollow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel");
	var C = {
		sid : B
	};
	$.post("/a/unfollow_stream", C, function(D) {
		if (D.success) {
			A.parent().removeClass("active");
			if (A.hasClass("force")) {
				A.closest(".s").fadeOut(150)
			}
			if (A.hasClass("list_intro_streams")) {
				$.get("/a/streams_intro_menu", {}, function(D) {
					if (D && D.html) {
						$("#streams_list_menu").html(D.html);
						if (D.count > 2) {
							$("#streams_next_step").show()
						} else {
							$("#streams_next_step").hide()
						}
					}
				}, "json")
			}
		} else {
			alert("Error occured. Favit team is notified")
		}
	}, "json");
	return false
};
var unfollow = function(X) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $("form[name=unfollow_form] :input");
	var B = {};
	A.each(function() {
		var C = $(this);
		var D = C.attr("type");
		var E = C.val();
		switch (D) {
		case "checkbox":
		case "radio":
			if (!C.is(":checked")) {
				break
			}
		default:
			if (C[0].originalValue == E) {
				E = ""
			}
			if (this.name.indexOf("[]") > -1) {
				if (!B[this.name]) {
					B[this.name] = new Array()
				}
				B[this.name].push(E)
			} else {
				B[this.name] = E
			}
			break
		}
	});
	var F = $("form[name=unfollow_form]");
	$.post(F.attr("action"), B, function(A) {
		var X = B.eid;
		$("a[rel=" + X + "]").addClass("l_follow_popup")
				.removeClass("selected").removeClass("l_unfollow_popup");
		fPopup.close()
	}, "json")
};
var follow = function(el) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $("form[name=follow_form] :input");
	var B = {};
	A.each(function() {
		var C = $(this);
		var D = C.attr("type");
		var E = C.val();
		switch (D) {
		case "checkbox":
		case "radio":
			if (!C.is(":checked")) {
				break
			}
		default:
			if (C[0].originalValue == E) {
				E = ""
			}
			if (this.name.indexOf("[]") > -1) {
				if (!B[this.name]) {
					B[this.name] = new Array()
				}
				B[this.name].push(E)
			} else {
				B[this.name] = E
			}
			break
		}
	});
	var F = $("form[name=follow_form]");
	$.post(F.attr("action"), B, function(A) {
		hideRight();
		fPopup.close()
	}, "json")
};
var browseSearch = function(A) {
	displayBrowse(A.attr("rel"))
};
searchInStream = function(A) {
	window.location = $("div.ctrls").children("a.active").attr("href") + "?q="
			+ escape(A.val())
};
keyupHandlers.search_stream = function(A, X, Y, Z) {
	switch (Z.keyCode) {
	case 13:
		searchInStream(A);
		break
	}
};
clickHandlers.do_search_stream = function(A) {
	searchInStream(A.parent().children("input.find_field"))
};
var browse_search = function(A, X, Y, Z) {
	switch (Z.keyCode) {
	case 13:
		browseSearch(A);
		break
	}
	return true
};
var login_form = function(A, X, Y, Z) {
	var ret = [];
	switch (Z.keyCode) {
	case 13:
		var form = $(A).parents("form");
		form.find("input.l_login_form").each(function(i, e) {
			if ($(e).val() == "") {
				ret.push($(e))
			}
		});
		if (!ret.length) {
			form.find(".btn.form_action").click()
		}
		break
	}
	return true
};
var newStreamTxtFocusIn = function(A) {
	var B = $.trim(A.val());
	A.parent().find("input[name='new_stream_chk']").attr("checked", "checked");
	return false
};
var newStreamTxtFocusOut = function(A) {
	var B = $.trim(A.val());
	if (B.length == 0) {
		A.parent().find("input[name='new_stream_chk']").attr("checked", "")
	}
	return false
};
clickHandlers.browse_search_button = function(A, B, C, D) {
	var Z = A.parents("div:eq(0)").find("input.find_field:eq(0)");
	if (Z.length) {
		browseSearch(Z)
	}
};
focusinHandlers.new_stream = newStreamTxtFocusIn;
focusoutHandlers.new_stream = newStreamTxtFocusOut;
clickHandlers.follow_popup = followPopup;
clickHandlers.pb = profileBubble;
clickHandlers.follow = follow;
clickHandlers.unfollow = unfollow;
clickHandlers.popup_close = popupClose;
clickHandlers.stream_follow = stream_follow;
clickHandlers.stream_unfollow = stream_unfollow;
keyupHandlers.browse_search = browse_search;
keyupHandlers.login_form = login_form;
clickHandlers.external_follow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	A.addClass("active");
	$.post("/a/external_follow", {
		eid : A.attr("rel")
	}, function(D) {
		A.removeClass("active").addClass("selected");
		A.removeClass("l_external_follow").addClass("l_qunfollow")
	})
};
clickHandlers.browse_order = function(A) {
	$("#browse_order a").removeClass("active");
	A.addClass("active");
	cat_id = $("div.cat_switcher ul li a.active").attr("rel");
	browseSearch(A, cat_id)
};
clickHandlers.hide_entity = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.ajax( {
		url : "/a/hide_entity",
		data : "eid=" + A.attr("rel"),
		success : function() {
			A.parent().slideUp("fast", function() {
				$(this).remove()
			})
		}
	})
};
clickHandlers.promote_user = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	fPopup.show( {
		view : "featuredpopup",
		params : {
			entity_id : A.attr("rel")
		}
	})
};
clickHandlers.unpromote_user = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.ajax( {
		url : "/a/unpromote_user",
		data : "eid=" + A.attr("rel"),
		success : function() {
			showInfoMessage("You successfully removed user as promoted");
			A.removeClass("l_unpromote_user").addClass("l_promote_user").text(
					"Add as featured")
		}
	})
};
clickHandlers.promote_stream = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	fPopup.show( {
		view : "featuredpopup",
		params : {
			stream_id : A.attr("rel")
		}
	})
};
clickHandlers.recommend_user = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.post("/a/recommend_user", {
		eid : A.attr("rel")
	}, function(r) {
		if (r && r.success) {
			showInfoMessage(r.success);
			A.removeClass("l_recommend_user").addClass("l_unrecommend_user")
					.html('<span class="del"></span>Remove as recommended')
		}
		if (r && r.failure) {
			showInfoMessage(r.failure)
		}
	}, "json")
};
clickHandlers.unrecommend_user = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.post("/a/unrecommend_user", {
		eid : A.attr("rel")
	}, function(r) {
		if (r && r.success) {
			showInfoMessage(r.success);
			if (A.hasClass("single")) {
				A.parents("div.c").fadeOut("normal", function() {
					$(this).remove()
				})
			} else {
				A.removeClass("l_unrecommend_user")
						.addClass("l_recommend_user")
						.html('<span class="star"></span>Mark as recommended')
			}
		}
		if (r && r.failure) {
			showInfoMessage(r.failure)
		}
	}, "json")
};
clickHandlers.recommend_stream = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$
			.post(
					"/a/recommend_stream",
					{
						sid : A.attr("rel")
					},
					function(r) {
						if (r && r.success) {
							showInfoMessage(r.success);
							A
									.removeClass("l_recommend_stream")
									.addClass("l_unrecommend_stream")
									.html(
											'<span class="del"></span>Remove from recommendations')
						}
						if (r && r.failure) {
							showInfoMessage(r.failure)
						}
					}, "json")
};
clickHandlers.unrecommend_stream = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.post("/a/unrecommend_stream", {
		sid : A.attr("rel")
	}, function(r) {
		if (r && r.success) {
			showInfoMessage(r.success);
			if (A.hasClass("single")) {
				A.parents("div.s").fadeOut("normal", function() {
					$(this).remove()
				})
			} else {
				A.removeClass("l_unrecommend_stream").addClass(
						"l_recommend_stream").html(
						'<span class="star"></span>Mark as recommended')
			}
		}
		if (r && r.failure) {
			showInfoMessage(r.failure)
		}
	}, "json")
};
clickHandlers.hide_stream = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.ajax( {
		url : "/a/hide_stream",
		data : "sid=" + A.attr("rel"),
		success : function() {
			A.parent().slideUp("fast", function() {
				$(this).remove()
			})
		}
	})
};
clickHandlers.category = function(A) {
	browseSearch(null, A.attr("rel"));
	return false
};
clickHandlers.feed_subscribe = function(A) {
	$('input[name="subscribe"]').val(A.attr("rel"));
	$("#subscribe_form").submit()
};
clickHandlers.submit = function(A) {
	id = A.attr("rel");
	if (id) {
		$("#" + id).submit()
	}
};
var scrollTop = function() {
	gSrollContainer.animate( {
		scrollTop : 0
	}, 500)
};
clickHandlers.scroll_top = scrollTop;
function unfollowPopup(B) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = B.attr("rel");
	if (A) {
		fPopup.show( {
			view : "unfollow_popup",
			params : {
				eid : A
			}
		})
	}
	return false
}
clickHandlers.unfollow_popup = unfollowPopup;
var toggleDropDown = function(A, C, D) {
	if (D.tagName == "A") {
		return true
	}
	var B = A.children(".drop_down");
	if (A.hasClass("active")) {
		B.hide()
	} else {
		B.show()
	}
	A.toggleClass("active")
};
clickHandlers.dropdown = toggleDropDown;
var addToStreamsPopup = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = {};
	B.sid = A.attr("sid");
	B.filter = A.attr("rel");
	fPopup.show( {
		view : "addtostream",
		params : B
	})
};
clickHandlers.add_to_streams = addToStreamsPopup;
var addToStreams = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var S = [];
	for (i in sEntities) {
		S.push(i)
	}
	if (S.length == 0) {
		alert("Please select at least one entity");
		return
	}
	var C = $("#stream_id").val();
	var B = {
		u : S,
		sid : C
	};
	if ($("#entities_type").length) {
		B.et = $("#entities_type").val()
	}
	$.post("/a/addtostream", B, function(C) {
		fPopup.close();
		if (C && C.html) {
			$("div.friends").replaceWith($(C.html))
		}
	}, "json")
};
clickHandlers.addtostream = addToStreams;
var invitePeoplePopup = function(A, C) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = {};
	if (C && C.length) {
		B.sid = C
	} else {
		B.sid = A.attr("rel")
	}
	fPopup.show( {
		view : "invite_popup",
		params : B
	})
};
clickHandlers.invite = invitePeoplePopup;
var invitePeople = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var S = [];
	for (i in sEntities) {
		S.push(i)
	}
	if (S.length == 0) {
		alert("Please select at least one follower");
		return
	}
	A.addClass("active");
	var C = $("#stream_id").val();
	var D = $("#stream_invite_user_text").val();
	var B = {
		u : S,
		sid : C,
		msg : D
	};
	$.post("/a/invite", B, function(C) {
		fPopup.close()
	}, "json")
};
clickHandlers.invitepeople = invitePeople;
clickHandlers.invite_user = function(A) {
	B = {
		u : A.attr("rel"),
		msg : A.parents("div.input_area").find("#invitation_text").val()
	};
	$.post("/a/invite", B, function(C) {
		$("#invite").fadeOut("fast", function() {
			$("#invite_more").fadeIn()
		});
		hideRight()
	})
};
var fPopup = {
	show : function(A) {
		if (A.view == undefined && A.json == undefined) {
			return
		}
		var self = this;
		var exist = $("#overlay");
		this.onClose = function() {
		};
		if (typeof A.params == "undefined") {
			A.params = {
				cb : function() {
				}
			}
		}
		if (typeof A.nokeys == "undefined") {
			gSrollContainer.keyup(self.keyListener)
		}
		if (exist.length == 0) {
			$("body").append($('<div id="overlay"></div>'))
		}
		$("#g_load").show();
		if (A.json == undefined) {
			$.getJSON("/a/render/" + A.view, A.params, function(C) {
				fPopup.response(C);
				setTimeout(A.params.cb, 200)
			})
		} else {
			this.response(A.json)
		}
		$("#container .lc").css("visibility", "hidden")
	},
	response : function(A) {
		$("#g_load").hide();
		$("#overlay").html(A.html);
		$("#overlay").ready(
				function() {
					$(this).children(":input").each(
							function(index) {
								if (!$(this).hasClass("noncapture")
										&& !this.originalValue && this.value) {
									this.originalValue = this.value
								}
							})
				})
	},
	keyListener : function(A) {
		if (A.keyCode == 27) {
			fPopup.close()
		}
	},
	close : function(A, B) {
		var self = this;
		self.onClose();
		gSrollContainer.unbind("keyup", self.keyListener);
		$("#overlay").remove()
	},
	onClose : function() {
	}
};
function onYouTubePlayerReady(P) {
	var A = document.getElementById(P);
	window["onYouTubePlayerStateChange" + P] = function(C) {
		var B = $(A);
		switch (C) {
		case 1:
			Favit.vn = P;
			Favit.vid = B.attr("videoid");
			break;
		default:
			Favit.vn = null
		}
	};
	A.addEventListener("onStateChange", "onYouTubePlayerStateChange" + P)
}
function newWindowVideo(A, Z) {
	var B = document.getElementById(A);
	if (B.getCurrentTime) {
		var X = B.getCurrentTime();
		B.stopVideo();
		Favit.vn = null;
		var C = (screen.width / 2) - (B.width / 2);
		var D = (screen.height / 2) - (B.height / 2);
		var X = "/render/video_player/?vid=" + escape(Z) + "&w=" + B.width
				+ "&h=" + B.height + "&s=" + X;
		var Z = "width="
				+ ((parseInt(B.width)) + 25)
				+ ", height="
				+ ((parseInt(B.height)) + 25)
				+ ", top="
				+ C
				+ ", left="
				+ D
				+ ", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no,resizeable=no";
		var E = window.open(X, A, Z)
	}
	return false
}
var realtime = {
	stopped : true,
	maxChannels : 40,
	entity : "",
	comments : [],
	posts : [],
	likes : [],
	hash : Math.floor(Math.random() * 1100000000),
	q : "",
	pids : [],
	time : "",
	start : function() {
		if (arguments.length > 0) {
			realtime.entity = arguments[0]
		}
		if (arguments.length > 1) {
			realtime.q = arguments[1]
		}
		realtime.poll();
		realtime.stopped = false
	},
	stop : function() {
		if (realtime.xhr) {
			realtime.xhr.abort();
			realtime.xhr = null
		}
		realtime.stopped = true
	},
	poll : function(delay) {
		clearTimeout(realtime.polling);
		if (!delay) {
			delay = 500
		}
		realtime.polling = setTimeout(realtime.refresh, delay)
	},
	refresh : function() {
		realtime.pids = [];
		if (realtime.entity) {
			realtime.pids.push( {
				channel : realtime.entity,
				subchannels : "data"
			})
		}
		var lc = 0;
		$(".list, .a_list").each(function(s, item) {
			if (lc < realtime.maxChannels) {
				var pid = $(item).attr("id");
				D = pid.substr(1);
				var P = getPostData(D);
				if (P) {
					lc++;
					realtime.pids.push( {
						channel : "p" + P.short_id,
						subchannels : "data"
					})
				}
			}
		});
		$("#menu ul").each(function() {
			$(this).children("li").each(function(s, item) {
				var pid = $(item).attr("id");
				D = pid.substr(1);
				realtime.pids.push( {
					channel : "s" + D,
					subchannels : "c"
				})
			})
		});
		$("#mega_top a.fn").each(function() {
			var pid = $(this).attr("id");
			D = pid.substr(1);
			realtime.pids.push( {
				channel : "s" + D,
				subchannels : "c"
			})
		});
		$("div#home_strm").children("div.s").each(function() {
			var pid = $(this).attr("id");
			realtime.pids.push( {
				channel : "s" + pid,
				subchannels : "c"
			})
		});
		if (realtime.pids.length == 0 && !realtime.q) {
			return
		}
		var r = "/live/pull/?";
		c = "c=";
		for (i in realtime.pids) {
			c += escape(realtime.pids[i].channel + ":"
					+ realtime.pids[i].subchannels + ";")
		}
		r += "&l=" + Favit.language;
		if (realtime.q && realtime.q.length > 0) {
			r += "&q=" + realtime.q
		}
		if (realtime.hash) {
			r += "&h=" + realtime.hash
		}
		if (realtime.xhr) {
			realtime.xhr.abort();
			realtime.xhr = null
		}
		if (realtime.time) {
			r += "&time=" + realtime.time
		}
		realtime.xhr = $.ajax( {
			url : r,
			data : c,
			dataType : "",
			type : "POST",
			success : function(data, textS, xhr) {
				realtime.success(data, textS, xhr)
			},
			error : realtime.error
		})
	},
	success : function(response, textS, xhr) {
		if (xhr.readyState == 4) {
			try {
				var A = eval("(" + response + ")")
			} catch (e) {
				realtime.error(realtime.xhr);
				return
			}
			if (A.time) {
				realtime.time = A.time
			}
			if (A.data && A.data.posts) {
				for (i in realtime.pids) {
					if (realtime.pids[i].subchannels.indexOf("data") !== -1) {
						realtimeAddPost(A.data.posts, A.data.html,
								realtime.pids[i].channel);
						break
					}
				}
			}
			if (A.data && A.data.comments) {
				realtimeAddComment(A.data.comments, A.data.html)
			}
			if (A.data && A.data.likes) {
				realtimeAddLike(A.data.likes, A.data.html)
			}
			if (A.channels && A.c) {
				realtimeUpdateStreams(A.channels, A.c)
			}
			realtime.poll()
		} else {
			realtime.error(realtime.xhr)
		}
	},
	error : function(xhr) {
		if (xhr.readyState != 4) {
			realtime.poll(10000)
		}
	},
	toggleState : function(l) {
		link = $(l);
		isOn = link.hasClass("on");
		Favit.debug(isOn);
		var params = {
			state : isOn
		};
		$.post("/a/realtime_state", params, function() {
		}, "json");
		link.html(isOn ? "<em></em>PAUSE" : "<em></em>PLAY");
		if (isOn) {
			link.removeClass("on");
			realtime.stop();
			if (Favit.rtc) {
				Favit.debug("staring realtine");
				realtime.start(Favit.rtc)
			}
		} else {
			Favit.realtime = false;
			link.addClass("on")
		}
		return false
	}
};
function updateCommentsCount(post_id, comment) {
	var pCount = parseInt($("#p" + post_id + " .ccount").text());
	if (comment && comment.count_comments > pCount) {
		$("#p" + post_id + " .ccount").text(comment.count_comments);
		$("#p" + post_id + " .ccount").removeClass("empty").animate( {
			"background-color" : "#639343"
		}, "fast").addClass("active")
	}
}
function realtimeAddPost(A, S) {
	if (typeof gPdata == "undefined") {
		return
	}
	for (i in A) {
		var P = A[i];
		if ($("#p" + P.post_id).length > 0) {
			updateCommentsCount(P.post_id, A.comment);
			continue
		}
		gPdata.unshift(P);
		var C = $("#new_posts");
		var pCount = parseInt(C.children("span").text());
		pCount++;
		C.children("span").text(pCount);
		setTimeout(function() {
			C.slideDown(75)
		}, 300)
	}
}
function updatePostContent(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var P = A.post_id;
	setPostData(P, A)
}
function realtimeUpdateStreams(A, t) {
	for (i in A) {
		var B = $("#" + A[i]);
		if (B.length > 0) {
			if (B.parents("#mega_top").length) {
				
				if(B.hasClass('home')){
					return // do not update home counter
				}
				var currentCount = 0;
				var countHolder = B.find("em");
				if (countHolder.length == 0) {
					B.prepend($("<em/>"))
				} else {
					currentCount = parseInt($(countHolder[0]).text())
				}
				currentCount += t.posts_count;
				B.find("em").text(currentCount)
			} else {
				var H = B.find("i > span");
				H.text(getTimeDiff(t.time) + " ago").removeClass("ft-ts")
						.addClass("ft-ts").attr("time", t.time);
				if (B.find("em.n").length == 0) {
					H.before($('<em class="n" />'))
				}
			}
		}
		if ($("#home_strm").length) {
			id = A[i].substr(1);
			var C = $("#" + id);
			var currentCount = 0;
			var countHolder = C.find("div.upt");
			if (countHolder.length == 0) {
				C.find("h2").after($('<div class="upt"/>'))
			} else {
				currentCount = parseInt($(countHolder[0]).text())
			}
			currentCount += t.posts_count;
			C.find("div.upt").text(currentCount + " new")
		}
	}
}
function realtimeAddComment(A, S) {
	var C = A.comment;
	var D = A.post;
	var E = D.post_id;
	if (gHolder.post_id == E) {
		if ($("#c" + C.comment_id).length > 0) {
			return
		}
		var M = renderComment(C);
		M = $(M);
		M.hide();
		var G = $("#read_pane .read_cont");
		if (G.length == 0) {
		}
		if (C.in_reply_to) {
			G = $("#c" + C.in_reply_to);
			while (G.next().is(".r")) {
				G = G.next()
			}
			G.after(M)
		} else {
			M.insertBefore($("#comment_frm"))
		}
		M.slideDown("fast");
		var P = getPostData(C.post_id);
		if (typeof P.comments == "undefined" || !P.comments) {
			P.comments = []
		}
		P.comments.push(C)
	}
	updatePostContent(D);
	updateCommentsCount(E, C)
}
function realtimeAddLike(A, S) {
	var D = A.post;
	var E = D.post_id;
	if (gHolder.post_id == E) {
		updatePostContent(A.post)
	} else {
		realtimeAddPost(A, S)
	}
}
function dismissInvitations(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var allInvitations = $("#content").find("a.l_close_invitation");
	var streamIds = [];
	for ( var i = 0, l = allInvitations.length; i < l; i++) {
		streamIds.push($(allInvitations[i]).attr("rel"))
	}
	if (streamIds) {
		$.post("/a/close_invitation", {
			i : streamIds
		}, function(r) {
			A.parents(".sub.msg").fadeOut("slow");
			if (r && r.ok) {
				$("#content").html(r.ok)
			}
		}, "json")
	}
}
clickHandlers.dismiss_invitations = dismissInvitations;
function sendMessage(A) {
	B = A.attr("eid");
	DN = A.attr("dname");
	var cb = function() {
		Z = $("#share_now");
		W = Z.find(".l_tocard:eq(0)");
		if (W.length) {
			W.attr("eid", B).removeClass("public").addClass("private");
			W.find("span:eq(0)").html(DN)
		}
		Z.find("label.ext_serv").remove()
	};
	fPopup.show( {
		view : "share",
		params : {
			cb : cb,
			act : 3
		}
	})
}
clickHandlers.send_message = sendMessage;
keyupHandlers.text_counter = function(A) {
	B = A.parent(".input_area").find("#char_count");
	if (!B) {
		return
	}
	C = A.val().length;
	if (typeof C !== typeof 1) {
		return false
	}
	D = B.attr("maxlength");
	if (D && typeof D === typeof 1) {
		return false
	}
	B.html(C)
};
var cancelAttachment = function(A) {
	$("#share_tools").children().remove();
	$("#slider .scroll_pane").jScrollPane()
};
clickHandlers.cancel_attachment = cancelAttachment;
var videoCallback = function(E) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("#share_now .att_media .media_ctrl").removeClass("active");
	if (E.error) {
		return
	}
	if (E.unsupported) {
		return
	}
	$("div.att_media .preview").remove();
	var X = '<div class="preview">';
	X += '<div class="thumb"><div class="v"></div><img src="' + E.preview_img + '"></div>';
	X += "<h2>" + E.title + "</h2>";
	X += "<p>" + E.desc + "</p>";
	X += '<div class="clear"></div>';
	X += '<input type="hidden" name="video[]" value="' + E.url + '">';
	X += '<input type="hidden" name="title" value="' + E.title + '">';
	X += '<input type="hidden" name="url" value="' + E.url + '">';
	X += '<input type="hidden" name="descr" value="' + E.desc + '">';
	X += "</div>";
	$("div.att_media").append(X);
	$("#slider .scroll_pane").jScrollPane()
};
var linkCallback = function(E, F) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var sharenow = F || $;
	sharenow.find(".att_media .media_ctrl").removeClass("active");
	if (E.error) {
		return
	}
	if (E._type == "photo") {
		var X = '<img src="' + E.preview_img + '">';
		X += '<input type="hidden" name="image[]" value="' + E.preview_img + '">';
		sharenow.find(".preview_image_share").html(X).show();
		sharenow.find("#shareArea").addClass("is_photo").show();
		sharenow.find(".context_switcher").removeClass("active");
		sharenow.find(".context_switcher.photo").addClass("active")
	} else {
		var X = (E._type == "video") ? '<div class="play"></div>' : "";
		X += E.preview_img ? '<img src="' + E.preview_img + '">' : "";
		X += "<h2>" + E.title + "</h2>";
		X += '<p class="s">' + E.url + "</p>";
		X += "<p>" + E.desc + "</p>";
		X += E.preview_img ? '<input type="hidden" name="image[]" value="' + E.preview_img + '">'
				: "";
		X += '<input type="hidden" name="title" value="' + E.title + '">';
		X += '<input type="hidden" name="url" value="' + E.url + '">';
		X += '<input type="hidden" name="descr" value="' + E.desc + '">';
		sharenow.find(".preview_article_share").html(X).show();
		sharenow.find("#shareArea").removeClass("is_photo").show();
		sharenow.find(".context_switcher").removeClass("active");
		sharenow.find(".context_switcher.link").addClass("active")
	}
	$("#slider .scroll_pane").jScrollPane()
};
var shareMedia = function(A, B) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var I = $(A).parent().find(".attach_link_field");
	if (!I.length) {
		I = $(A).parents(".attach_photo").find(".attach_photo_field")
	}
	if (!I.length) {
		return null
	}
	var Y = $.trim(B || I.val());
	if (Y.length == 0 || Y == "http://") {
		return false
	}
	$(A).addClass("active");
	var sharenow = $(A).parents("#share_now");
	if (A.hasClass("link")) {
		var D = {
			url : Y
		};
		$.get("/a/preview_link", D, function(R) {
			$(A).removeClass("active");
			linkCallback(R, sharenow);
			sharenow.find(".attach_link").hide();
			I.val("http://")
		}, "json");
		return
	} else {
		if (A.hasClass("photo")) {
			var D = {
				url : Y
			};
			$.get("/a/preview_photo", D, function(R) {
				$(A).removeClass("active");
				linkCallback(R, sharenow);
				sharenow.find(".attach_photo").hide();
				I.val("http://")
			}, "json");
			return
		}
	}
};
clickHandlers.share_media = function(A) {
	setTimeout(function() {
		shareMedia(A)
	}, 10)
};
keyupHandlers.detect_link = function(A) {
};
var shareAttachment = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("#attach .l_attachment").removeClass("active");
	A.addClass("active");
	var B = A.attr("rel");
	var G = $("#share_tools");
	G.children().remove();
	var C = $('<input type="text" class="l_share_media ' + B + '" value="">');
	var X = $('<a href="" class="btn prev_btn">Done</a>');
	X.click(function(E) {
		E.preventDefault();
		$(this).remove()
	});
	G.append(C);
	G.append('<a href="" class="media_ctrl l_cancel_attachment"></a>');
	G.append(X);
	switch (B) {
	case "link":
		C.val("Paste your URL here...");
		break;
	case "photo":
		G.prepend('<div id="shr_upload"><img id="uploadphoto"/></div>');
		C
				.val("Paste photo URL or click Upload to select it from your computer... ");
		var D = {
			flash_url : "/static/" + Favit.version
					+ "/js/swfupload/swfupload.swf",
			upload_url : "/a/upload",
			post_params : {},
			file_size_limit : "2 MB",
			file_types : "*.jpg;*.png;*.gif",
			file_types_description : "Image Files",
			file_upload_limit : 10,
			file_queue_limit : 0,
			custom_settings : {},
			debug : false,
			button_image_url : "/static/" + Favit.version
					+ "/images/uploaders/cust_stream.png",
			button_width : "96",
			button_height : "24",
			button_placeholder_id : "uploadphoto",
			button_text : "",
			file_dialog_complete_handler : function(numFilesSelected,
					numFilesQueued) {
				if (numFilesSelected > 0) {
					this.startUpload()
				}
			},
			upload_start_handler : function(file) {
			},
			upload_error_handler : function(file, errorCode, message) {
			},
			upload_success_handler : function(A, B) {
				$("#share_now .att_media .media_ctrl").removeClass("active");
				$("div.att_media .preview").remove();
				var X = '<div class="preview">';
				X += '<div class="thumb"><img src="' + B + '"></div>';
				X += '<div class="clear"></div>';
				X += '<input type="hidden" name="image[]" value="' + B + '">';
				X += "</div>";
				$("div.att_media").append(X)
			},
			upload_complete_handler : function(file) {
			}
		};
		try {
			swfu = new SWFUpload(D)
		} catch (e) {
			var gDfLoaded = function() {
				swfu = new SWFUpload(D)
			};
			S = document.createElement("script");
			S.src = "/static/" + Favit.version + "/js/swfupload/swfupload.js";
			S.type = "text/javascript";
			S.async = true;
			S.onreadystatechange = gDfLoaded;
			S.onload = gDfLoaded;
			document.body.appendChild(S)
		}
		break;
	case "video":
		break
	}
};
clickHandlers.attachment = shareAttachment;
var shareAction = clickHandlers.share = function(A, T) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var sharenow = A;
	var B = false;
	var A = sharenow.find("#shareArea");
	if (A.length) {
		var message = A.val();
		if (message == A[0].originalValue) {
			message = ""
		}
		if (message.length > 0) {
			B = true
		}
	}
	if (sharenow.find("input[name='title']").length) {
		B = true
	}
	var medias = [];
	sharenow.find("input[name='image[]']").each(function(i, el) {
		medias[i] = $(el).val()
	});
	if (medias.length > 0) {
		B = true
	}
	var E = sharenow.find("input[name='article_title']");
	if (E.length) {
		B = checkField(E)
	}
	var statusReshare = sharenow.find("div.reply_item");
	if (statusReshare.length) {
		B = true
	}
	if (!B) {
		E.focus();
		return
	}
	T.addClass("active");
	var B = $("#hdr_article");
	if (B.length == 0) {
		B = sharenow
	}
	var sharewith = [];
	var streams = [];
	var pages = [];
	B.find(".l_tocard").each(function(E, F) {
		var G = $(F).attr("eid");
		if (G) {
			sharewith.push(G)
		}
		var D = $(F).attr("sid");
		if (D) {
			streams.push(D)
		}
		D = $(F).attr("pid");
		if (D) {
			pages.push(D)
		}
	});
	if (sharewith.length == 0 && streams.length == 0) {
		B.find(".l_toinput").select().focus();
		alert("In order to share in a Facebook page, you have to include My profile or a stream as well");
		return false
	}
	B = sharenow.find("input[name='url']");
	var url = B.val();
	var E = sharenow.find("input[name='article_title']");
	var title = "";
	if (E.length) {
		title = E.val()
	}
	if (E.length && E[0].originalValue) {
		if (title == E[0].originalValue) {
			title = ""
		}
	}
	if (title == "") {
		var E = sharenow.find("input[name='title']");
		if (E.length) {
			title = E.val()
		}
	}
	var content = "";
	if (sharenow.find("#shareArea_parent").length > 0) {
		content = sharenow.find("#shareArea").html();
		message = ""
	} else {
		if (sharenow.find("input[name='descr']").length > 0) {
			content = sharenow.find("input[name='descr']").val()
		}
	}
	var A = [];
	sharenow.find(".l_tservice").each(function(C) {
		var B = $(this);
		if (B.is(":checked")) {
			if (B.hasClass("fb")) {
				A.push(9)
			}
			if (B.hasClass("tw")) {
				A.push(6)
			}
		}
	});
	var B = $("#tiny_mce_editor").val();
	var params = {
		url : url,
		content : content,
		title : title,
		message : message,
		medias : medias,
		sharewith : sharewith,
		streams : streams,
		es : A,
		article : B,
		pages : pages
	};
	var C = sharenow.find("#longitude");
	var D = sharenow.find("#latitude");
	if (C.length > 0 && D.length > 0) {
		params.geo_longitude = C.val();
		params.geo_latitude = D.val()
	}
	E = sharenow.find("input[name='post_id']");
	if (E.length > 0) {
		var P = E.val();
		var B = {
			post_id : P,
			sharewith : sharewith,
			streams : streams,
			message : message,
			es : A,
			qickshare : true,
			pages : pages
		};
		if (C.length > 0 && D.length > 0) {
			B.geo_longitude = C.val();
			B.geo_latitude = D.val()
		}
		var G = getPostData(P);
		B.view_id = G.view_id;
		B.vt = G.view_type;
		B.is_status = G.is_status_update;
		$.post("/a/quickshare", B, function(D) {
			var I = getPostData(D.post_id);
			if (I) {
				I.is_shared = true;
				setPostData(D.post_id, I)
			}
			if (D.relocate) {
				window.location.href = D.relocate
			}
			showInfoMessage("You successfully shared your post");
			clickHandlers.collapse_share_box(sharenow)
		}, "json")
	} else {
		$("#g_load").show();
		$.post("/a/share", params, function(X) {
			$("#g_load").hide();
			if (X.relocate) {
				window.location.href = X.relocate
			}
			if (!X) {
				return
			}
			showInfoMessage("You successfully shared your post");
			clickHandlers.collapse_share_box(sharenow)
		}, "json")
	}
};
var shareDeactivate = function() {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $("#mega_top");
	if (!A.is(".active")) {
		return
	}
	A.removeClass("active");
	if (typeof tinyMCE != "undefined" && tinyMCE) {
		tinyMCE.execCommand("mceRemoveControl", false, "shareArea")
	}
	$("#share").show().html($("#shareArea").val());
	$("#share_now").hide();
	$("#mega_top").css("height", "40px");
	$("#attach, #container").show();
	$("#art_title").hide().val("");
	$("#fullarticle_toolbar").hide()
};
clickHandlers.cancel_shr = shareDeactivate;
function resetShare() {
	if (!Favit.user) {
		return notLoggedIn()
	}
	shareDeactivate();
	var A = "What's on your mind? Start typing here...";
	$("#share").html(A);
	$("#shareArea").html(A)
}
clickHandlers.esa = function(A) {
	A.toggleClass("active")
};
function advancedShare() {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("#mega_top").height("100%");
	$("#attach, #container").hide();
	$("#art_title").show();
	$("#fullarticle_toolbar").show();
	$("#shareArea")
			.tinymce(
					{
						script_url : "/static/" + Favit.version
								+ "/js/tiny_mce/tiny_mce.js",
						theme : "advanced",
						theme_advanced_layout_manager : "SimpleLayout",
						plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
						theme_advanced_buttons1 : "bold,italic,strikethrough,|,justify,formatpicker,fontpicker,bullist,|,outdent,indent,blockquote,link,unlink,cleanup,|,forecolor,backcolor,|,media,image, code",
						theme_advanced_toolbar_location : "external",
						theme_advanced_toolbar_align : "left",
						relative_urls : 0,
						convert_urls : 0,
						template_external_list_url : "lists/template_list.js",
						external_link_list_url : "lists/link_list.js",
						external_image_list_url : "lists/image_list.js",
						media_external_list_url : "lists/media_list.js"
					})
}
clickHandlers.ashare = advancedShare;
function getTimeDiff(A) {
	if (typeof Favit.TS == "undefined") {
		return
	}
	var B = (Favit.TS - A);
	var C = false;
	if (B < 60) {
		C = B + " seconds"
	} else {
		if (B >= 60 && B < 3600) {
			var D = Math.floor(B / 60);
			C = D + " minute" + (D > 1 ? "s" : "")
		} else {
			if (B >= 3600 && B < 86400) {
				var D = Math.floor(B / 3600);
				C = D + " hour" + (D > 1 ? "s" : "")
			} else {
				if (B >= 86400 && B < 604800) {
					var D = Math.floor(B / 86400);
					C = D + " day" + (D > 1 ? "s" : "")
				} else {
					if (B >= 604800 && B < 18144000) {
						var D = Math.floor(B / 604800);
						C = D + " week" + (D > 1 ? "s" : "")
					} else {
						if (B >= 18144000) {
							var D = Math.floor(B / 2592000);
							C = D + " month" + (D > 1 ? "s" : "")
						}
					}
				}
			}
		}
	}
	return C
}
function showMenu(A) {
	if (A.hasClass("active")) {
		hideMenus();
		return
	}
	hideMenus();
	A.addClass("active");
	A.children(".drop_down").show()
}
function hideMenu(A) {
	A.parents(".l_sm").removeClass("active");
	A.parents(".drop_down").hide();
	if (A.hasClass("default")) {
		return true
	}
}
function hideMenus() {
	$(".l_sm, #header .l_st").removeClass("active");
	$(".drop_down").hide()
}
function toggleStripeMenu(A) {
	var B = $("#header .stripe .drop_down");
	if (A.hasClass("active")) {
		A.removeClass("active");
		B.hide()
	} else {
		A.addClass("active");
		B.show()
	}
}
clickHandlers.sm = showMenu;
clickHandlers.hm = hideMenu;
clickHandlers.tm = toggleStripeMenu;
clickHandlers.subfilter = function(A) {
	gContentContainer = $(".friends");
	gContentParams = {
		submenu : true
	}
};
var saveSearch = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var Q = A.attr("rel");
	var B = {
		q : Q
	};
	$.post("/a/save_search", B, function(C) {
		A.addClass("selected").removeClass("l_save_search").addClass(
				"l_unsave_search")
	}, "json")
};
clickHandlers.save_search = saveSearch;
var unsaveSearch = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	if (!Favit.user) {
		return notLoggedIn()
	}
	var Q = A.attr("rel");
	var B = {
		q : Q
	};
	$.post("/a/unsave_search", B, function(C) {
		A.removeClass("active").removeClass("l_unsave_search").addClass(
				"l_save_search")
	}, "json")
};
clickHandlers.unsave_search = saveSearch;
var homeNav = function(A) {
	var B = A.hasClass("next");
	var C = 0;
	var D = 0;
	$(".slide").each(function(I, E) {
		if ($(E).is(":visible")) {
			C = I
		}
		D = I
	});
	$(".slide").hide();
	var X = 0;
	if (B) {
		if (C < D) {
			X = C + 1
		}
	} else {
		if (C > 0) {
			X = C - 1
		} else {
			X = D
		}
	}
	$(".slide[rel=" + X + "]").fadeIn("slow")
};
var streamCreatorSwitch = function(A) {
	A = $(A);
	if (A.is(".active")) {
		return
	}
	var B = A.parent();
	B.children().removeClass("active");
	A.addClass("active");
	var D = $("#new_stream_custom_entities");
	var C = A.attr("id");
	switch (C) {
	case "sharing_stream":
		$("#dlist_stream").hide();
		$("#dfilter_stream").hide();
		$("#dsharing_stream").show();
		$("#menu .sugg_content").hide();
		$("#suggShare").show();
		break;
	case "list_stream":
		$("#dlist_stream").show();
		$("#dfilter_stream").hide();
		$("#dsharing_stream").hide();
		$("#isFilter_expl").hide();
		$("#isList_expl").show();
		$("#menu .sugg_content").hide();
		$("#suggList").show();
		break;
	case "filter_stream":
		$("#dlist_stream").hide();
		$("#dfilter_stream").show();
		$("#dsharing_stream").hide();
		$("#menu .sugg_content").hide();
		$("#suggFilter").show();
		break;
	case "personal_stream":
		$("#dpersonal_stream").show();
		$("#dshared_stream").hide();
		break;
	case "shared_stream":
		$("#dpersonal_stream").hide();
		$("#dshared_stream").show();
		$("div.stream_privacy").hide();
		break;
	case "filter_all":
		$("#allfavit_expl").show();
		$("#mynetwork_expl").hide();
		$("#custom_expl").hide();
		$("#dlist_stream").hide();
		break;
	case "filter_my_network":
		$("#allfavit_expl").hide();
		$("#mynetwork_expl").show();
		$("#custom_expl").hide();
		$("#dlist_stream").hide();
		break;
	case "filter_custom":
		$("#allfavit_expl").hide();
		$("#mynetwork_expl").hide();
		$("#dlist_stream").show();
		$("#isFilter_expl").show();
		$("#isList_expl").hide();
		break
	}
};
clickHandlers.tswitch = streamCreatorSwitch;
clickHandlers.home_nav = homeNav;
clickHandlers.remove_user_sugg = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = {
		eid : A.attr("rel")
	};
	$.post("/a/remove_user_sugg", B, function(C) {
		hideParentWithClass(A, "s")
	}, "json")
};
var ignoreFollowers = function(A) {
	var C = $("#newFollowers");
	if (!Favit.user) {
		return notLoggedIn()
	}
	$.post("/a/cancel_followers", {}, function(B) {
		C.animate( {
			opacity : "0"
		}, 100, function() {
			C.slideUp(150)
		})
	}, "json")
};
clickHandlers.no_followers = ignoreFollowers;
mark_read = function(O) {
	$.post("/a/read", O, function(B) {
		if (!B) {
			return
		}
		var P = O.post_id;
		$("#p" + P).removeClass("u");
		for (i in B) {
			var h = $("a#s" + i + " em");
			if (h.length) {
				h.text(B[i]);
				if (B[i] == "0") {
					h.remove()
				}
			} else {
				if (parseInt(B[i]) > 0) {
					$("a#s" + i).prepend("<em>" + B[i] + "</em>")
				}
			}
		}
	}, "json")
};
clickHandlers.mark_read_all = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	mark_read( {
		stream_id : A.attr("rel")
	})
};
clickHandlers.mark_read = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	mark_read( {
		post_id : A.attr("rel")
	})
};
clickHandlers.approve_user_follow = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$
			.post(
					"/a/approve_follow",
					{
						nid : A.attr("rel")
					},
					function(B) {
						A.parents("div.c").fadeOut(75, function() {
							$(this).remove()
						});
						showInfoMessage("You successfully allowed the user to follow your activity")
					});
	return false
};
clickHandlers.save_services = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var active_services = [];
	$("input[name^=sync]").each(function() {
		if ($(this).is(":checked")) {
			active_services.push($(this).attr("rel"))
		}
	});
	$.post("/a/save_services", {
		services : active_services
	})
};
clickHandlers.save_recommendations = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = $("#recommendations");
	var r_entities = [];
	var r_streams = [];
	B.find(".l_tocard").each(function(E, F) {
		var G = $(F).attr("eid");
		if (G) {
			r_entities.push(G)
		}
		var D = $(F).attr("sid");
		if (D) {
			r_streams.push(D)
		}
	});
	data = {
		streams : r_streams,
		entities : r_entities
	};
	$.post("/a/save_recommendations", data, function(C) {
		if (C && C.success) {
			showInfoMessage(C.success)
		}
		if (C && C.failure) {
			showInfoMessage(C.failure)
		}
		if (C && C.html) {
			$("div#recommended").hide().html(C.html).fadeIn("normal");
			$("#recommendations").find(".l_tocard").remove();
			boxedStreams()
		}
	}, "json")
};
clickHandlers.show_recommendations = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("div.nw_recommendation").hide();
	$('div.nw_recommendation[rel="' + A.attr("rel") + '"]').show();
	return false
};
focusinHandlers.frm_field = function(A) {
	A.parent().addClass("active")
};
focusoutHandlers.frm_field = function(A) {
	A.parent().removeClass("active");
	A.parent().children(".error").remove()
};
var gNTimeOut = null;
keyupHandlers.signup_nickname = function(A, X, Y, Z) {
	var B = A.val();
	B = $.trim(B);
	if (B.length == 0) {
		return
	}
	var C = Z.keyCode ? Z.keyCode : Z.which;
	if (gNTimeOut != null) {
		clearTimeout(gNTimeOut)
	}
	$(".reg_info span").html(B);
	gNTimeOut = setTimeout(
			function() {
				$
						.get(
								"/a/nick_avail",
								{
									nick : B
								},
								function(D) {
									if (D.avail == 0) {
										A.css( {
											color : "green"
										});
										A.parent().children(".error").remove()
									} else {
										A.css( {
											color : "red"
										});
										A.parent().children(".a").remove();
										var C = $('<span class="a error"></span>');
										switch (D.avail) {
										case 1:
											C.html("Nickname already exists");
											break;
										case 2:
											C
													.html("Invalid or too short username, enter at least 4 alphabetical chars");
											break
										}
										A.parent().append(C);
										C.show()
									}
								}, "json")
			}, 500)
};
var entities_scroll = function() {
	if ($(this).scrollTop() > (this.scrollHeight - $(this).height() - 400)) {
		var offset = $(this).data("offset");
		if (!offset) {
			offset = 0
		}
		offset += 100;
		$(this).data("offset", offset);
		for (i = offset; i < offset + 100; i++) {
			if (i < gEntities.length) {
				tag = favitUI_getEntityBlock(i);
				$(this).append(tag)
			} else {
				break
			}
		}
	}
};
clickHandlers.view_invitation = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	A.parent().children("a").removeClass("active");
	A.addClass("active");
	var B = A.attr("rel");
	var C = $("#home_invitations");
	C.children("div.s").hide();
	C.children("[rel=" + B + "]").fadeIn("slow")
};
clickHandlers.cancel_invitation = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var B = A.attr("rel");
	$.post("/a/close_invitation", {
		i : B
	}, function(C) {
		if (C.ok) {
			var D = A.parents(".s").eq(0);
			D.fadeOut("slow");
			$("div.net_list").children('a[rel="' + D.attr("rel") + '"]')
					.fadeOut("slow");
			if ($("#invitations_count").length) {
				var c = $("#invitations_count").text();
				c = parseInt(c);
				if (c > 0) {
					$("#invitations_count").text(c - 1)
				}
			}
		}
	}, "json")
};
var triggerLoadPosts = clickHandlers.load_posts = function(A) {
	A.addClass("active");
	var S = A.attr("rel");
	$.post("/a/load_posts", {
		stream_id : S,
		timestamp : gPTime
	},
			function(D) {
				var H = $(D.html);
				$("#PostsHolder").prepend(H);
				$("#new_posts").hide().removeClass("active").children("span")
						.text("0");
				H.slideDown(100);
				gPTime = D.time
				
				if (D.data_key) {
					gHolder.dataLoading = true;
					var C = {
						hash : D.data_key
					};
					gXHR = $.get("/a/streamdata", C, function(D) {
						if (D.posts) {
							for (i in D.posts) {
								gPdata.push(D.posts[i])
							}
							gHolder.dataLoading = false;
							gPTime = D.time
						}
					}, "json")
				}
			}, "json")
};
clickHandlers.load_messages = function(A) {
	A.addClass("active");
	var S = A.attr("rel");
	var T = $("div.msg_list").children("div.l_post").eq(0).find("a.ft-ts")
			.attr("time");
	$.post("/a/load_posts", {
		stream_id : S,
		timestamp : T
	}, function(D) {
		$("#new_posts").hide().remove();
		if (D && D.html) {
			var H = $(D.html);
			H.hide();
			$("div.msg_list").eq(0).before(H);
			H.slideDown()
		}
	}, "json")
};
function showShare(E, D, C) {
	return showRight("share", D, C)
}
var showRight = function(A, P, C, Z) {
	$("#g_load").show();
	var B = $("#slider");
	var Y = true;
	Z = Z || {};
	var X = function(A) {
		$("#g_load").hide();
		if (A.html) {
			B.append(A.html);
			$("#slider .slide").show();
			if (C) {
				C(A)
			}
		} else {
		}
		$("#slider .scroll_pane").jScrollPane();
		$("#slider").hover(function() {
			$("#slider .jScrollPaneTrack").fadeIn(150)
		}, function() {
			$("#slider .jScrollPaneTrack").fadeOut(150)
		});
		$(":input").each(
				function(index) {
					if (!$(this).hasClass("noncapture") && !this.originalValue
							&& this.value) {
						this.originalValue = this.value
					}
				})
	};
	if (B.length > 0) {
		if (B.data("nod") != P) {
			B.html("");
			B
					.append('<div class="stripe"><a href="" class="l_right_close"><span></span>close</a></div>');
			B.data("nod", P);
			$.get("/render/right/" + A + "/" + P, Z, X, "json")
		} else {
			Y = false;
			$("#g_load").hide()
		}
	} else {
		var B = $('<div id="slider"/>');
		B
				.append('<div class="stripe"><a href="" class="l_right_close"><span></span>close</a></div>');
		$("#container").append(B);
		B.data("nod", P);
		$.get("/render/right/" + A + "/" + P, Z, X, "json")
	}
	if (Y) {
		$("#menu_content").hide();
		if ($("#cust_header").length >= 1) {
			gSrollContainer.scrollTop(gSrollContainer.scrollTop() - 140);
			$("#cust_header").css("margin-top", "-101px")
		}
		$("#slider").animate( {
			marginLeft : "132px"
		}, 150, function() {
			$("#slider .slide").show()
		})
	}
};
var hideRight = function(A) {
	$("#slider .slide").hide();
	$("#menu_content").show();
	$("#slider").animate( {
		marginLeft : "-235px"
	}, 150, function() {
		if ($("#cust_header").length >= 1 && $("#read_pane").length == 0) {
			gSrollContainer.scrollTop(gSrollContainer.scrollTop() + 140);
			$("#cust_header").css("margin-top", "39px")
		}
		$(this).remove()
	})
};
clickHandlers.right_close = hideRight;
clickHandlers.quick_stream_create = function(A) {
	if (Favit.enough_network == false) {
		C = {};
		fPopup.show( {
			view : "low_network",
			params : C
		});
		return false
	}
	var form = $("#new_stream_name_form");
	if (form.length == 0) {
		form = $("#hcsfrm")
	}
	if (form.length) {
		form.submit()
	}
	return false
};
clickHandlers.refresh_stream_recomm = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var C = A.parents("div.menu_list:eq(0)");
	C.animate( {
		opacity : 0.5
	}, 100);
	$.post("/a/recommended_streams", {}, function(B) {
		if (B && B.html) {
			C.replaceWith(B.html)
		}
	}, "json");
	return false
};
clickHandlers.refresh_people_recomm = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var C = A.parents("div.menu_list:eq(0)");
	C.animate( {
		opacity : 0.5
	}, 100);
	$.post("/a/recommended_people", {}, function(B) {
		if (B && B.html) {
			C.replaceWith(B.html)
		}
	}, "json");
	return false
};
clickHandlers.resent_confirm_email = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	$("#g_load").show();
	$.post("/a/resent_confirmation", {}, function(B) {
		$("#g_load").hide();
		if (B.ok) {
			A.fadeOut();
			showInfoMessage("Email is sent")
		}
	}, "json")
};
clickHandlers.mark_featured = function() {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var M = "entity";
	var A = $("#recom_bubble input[name='entity_id']");
	var D = {};
	if (A.length > 0) {
		D.eid = A.val()
	} else {
		A = $("#recom_bubble input[name='stream_id']");
		D.sid = A.val()
	}
	var B = $("#recom_bubble select[name='category_id']").val();
	var C = [];
	$("#recom_bubble input[name='countries[]']").each(function(I, E) {
		if ($(E).is(":checked")) {
			C.push($(E).val())
		}
	});
	if (B.length == 0) {
		alert("Please select category");
		return
	}
	if (C.length == 0) {
		alert("Please select country");
		return
	}
	D.cat_id = B;
	D.countries = C;
	$.post("/a/promote_user", D, function(A) {
		fPopup.close()
	}, "json")
};
clickHandlers.remove_from_featured = function(A) {
	if (!Favit.user) {
		return notLoggedIn()
	}
	var A = $("#recom_bubble input[name='entity_id']");
	var D = {};
	if (A.length > 0) {
		D.eid = A.val()
	} else {
		A = $("#recom_bubble input[name='stream_id']");
		D.sid = A.val()
	}
	$.post("/a/unpromote_user", D, function(A) {
		fPopup.close()
	}, "json")
};
clickHandlers.chart_prev = function(A) {
	var C = $("#stat_sep");
	gStartTimestamp -= 6 * 60 * 60;
	var B = $.browser.msie ? window["graph-2"] : $('embed[name="graph-2"]')
			.get(0);
	B.reload(gDataFile + gStartTimestamp);
	$("a.l_chart_next").show();
	C.show();
	if (gStartTimestamp <= gPostTimestamp) {
		A.hide();
		C.hide()
	}
	return true
};
clickHandlers.chart_next = function(A) {
	var C = $("#stat_sep");
	gStartTimestamp += 6 * 60 * 60;
	var B = $.browser.msie ? window["graph-2"] : $('embed[name="graph-2"]')
			.get(0);
	B.reload(gDataFile + gStartTimestamp);
	if (gStartTimestamp >= gPostTimestamp) {
		$("a.l_chart_prev").show();
		C.show()
	}
	if (gNowTimestamp - gStartTimestamp <= 3600) {
		A.hide();
		C.hide()
	}
	return true
};
network_reach = function(dot) {
	var D = {
		offset : dot,
		pid : gHolder.post_id,
		start : gStartTimestamp
	};
	$.post("/a/expand_network_reach", D, function(A) {
		$("#actions_holder").html(A.html);
		if (A.html.length) {
			$("#actions_holder").slideDown("slow")
		} else {
			$("#actions_holder").slideUp("fast")
		}
	}, "json")
};
function notLoggedIn() {
	var C = {};
	showRight("signup", "signup", null, C);
	return false
}
function fastSignin() {
	var C = {};
	showRight("signin", "signin", null, C);
	return false
}
clickHandlers.not_logged_in = notLoggedIn;
function getAndDisplayLocation(A, B, X) {
	var C = new google.maps.Geocoder();
	var E = new google.maps.LatLng(A.latitude, A.longitude);
	var D = {
		zoom : 15,
		center : E,
		mapTypeControl : false,
		navigationControlOptions : {
			style : google.maps.NavigationControlStyle.SMALL
		},
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById(X), D);
	var marker = new google.maps.Marker( {
		position : E,
		animation : google.maps.Animation.DROP,
		map : map
	});
	C.geocode( {
		latLng : E
	}, function(X) {
		var streetLevel = X[0]["address_components"][0]["long_name"];
		var cityLevel = X[0]["address_components"][1]["long_name"];
		var countryLevel = X[0]["address_components"][3]["long_name"];
		$(B).html(
				(streetLevel ? streetLevel + "<br>" : "")
						+ (cityLevel ? cityLevel + ", " : "")
						+ (countryLevel || ""))
	})
}
clickHandlers.hide_intro_menu = function(A) {
	$("#intro_help_menu").fadeOut("fast", function() {
		$("div.tut_hid").fadeIn("fast")
	});
	$.post("/a/hide_intro_menu", null, function(B) {
		if (B.ok) {
		}
	}, "json")
};
keyupHandlers.intro_browse = function(A, X, Y, Z) {
	switch (Z.keyCode) {
	case 13:
		if (A.hasClass("browse_people")) {
			clickHandlers.requesting_listing(A, X, Y, Z)
		}
		if (A.hasClass("browse_streams")) {
			clickHandlers.requesting_listing(A, X, Y, Z)
		}
		break
	}
	return true
};
clickHandlers.allow_to_stream = function(A) {
	var B = {
		eid : A.attr("rel"),
		sid : A.attr("sid")
	};
	$.post("/a/stream_approve", B, function(C) {
		if (C.ok) {
			A.parents(".c").fadeOut("fast")
		}
	}, "json")
};
clickHandlers.block_from_stream = function(A) {
	var B = {
		eid : A.attr("rel"),
		sid : A.attr("sid")
	};
	$.post("/a/stream_block", B, function(C) {
		if (C.ok) {
			A.parents(".c").fadeOut("fast")
		}
	}, "json")
};
clickHandlers.stream_promote_moderator = function(A) {
	var B = {
		eid : A.attr("rel"),
		sid : A.attr("sid")
	};
	$.post("/a/stream_promote_moderator", B, function(C) {
		if (C.ok) {
			hideMenu(A);
			A.removeClass("l_stream_promote_moderator").addClass(
					"l_stream_remove_moderator").html(
					'<span class="invite"/>Remove as moderator');
			A.parents(".c").find("h2").append("<em>moderator</em>");
			showInfoMessage("You successfully promoted the user as moderator")
		}
	}, "json")
};
clickHandlers.stream_remove_moderator = function(A) {
	var B = {
		eid : A.attr("rel"),
		sid : A.attr("sid")
	};
	$.post("/a/stream_remove_moderator", B, function(C) {
		if (C.ok) {
			hideMenu(A);
			A.addClass("l_stream_promote_moderator").removeClass(
					"l_stream_remove_moderator").html(
					'<span class="invite"/>Promote as moderator');
			A.parents(".c").find("h2").find("em").remove();
			showInfoMessage("You successfully removed the user as moderator")
		}
	}, "json")
};
clickHandlers.switch_form = function() {
	$("#login").toggle();
	$("#recovery").toggle()
};
function recalcAreas() {
	var A = $("#menu_content");
	var B = $("#main_pane");
	if (A.height() > B.height()) {
		B.css("min-height", (A.height() + 10) + "px");
		$("#read_pane").css("min-height", (A.height() + 10) + "px")
	}
	if ($("#slider").length > 0) {
		$("#slider div.scroll_pane").jScrollPane()
	}
}
function boxedStreams() {
	$("div.list_strm .s").hover(function() {
		$(this).find("img.thumb").css( {
			width : "230px",
			marginTop : "-12px",
			marginLeft : "-22px"
		});
		var C = $(this).find("div.y");
		if (!C.hasClass("done")) {
			var A = $(this).find("img.thumb");
			var B = A.attr("src");
			C.append("<h2>" + $(this).find("h2").html() + "</h2>");
			D = C.find("a.bt");
			D.attr("href", $(this).find("a.t").attr("href"));
			D.append('<img src="' + B + '">')
		}
		$(this).css("z-index", "2");
		C.addClass("done").show()
	}, function() {
		$(this).find("div.y").hide();
		$(this).css("z-index", "0");
		$(this).find("img.thumb").animate( {
			width : "195px",
			marginTop : "0px",
			marginLeft : "0px"
		}, {
			duration : 100
		})
	})
}
function FeaturedInit() {
	var B = $("#FeaturedSwitch > div").size();
	var C = $("#featuredPosts");
	var D = $("#featuredPosts .arr");
	var E = 602;
	var F = $("#featuredPosts .container");
	if (B > 1) {
		C.find("div.next").show()
	}
	D.click(function() {
		clearInterval(window.feat_interval);
		if ($(this).hasClass("next")) {
			SwitchFeatured("next")
		} else {
			SwitchFeatured("prev")
		}
	});
	$("#FeaturedSwitch div").click(function() {
		var H = parseInt($(this).attr("rel"));
		SwitchFeatured(H);
		clearInterval(window.feat_interval)
	});
	window.feat_interval = setInterval(function() {
		SwitchFeatured("next")
	}, 5000)
}
function SwitchFeatured(X) {
	var A = $("#FeaturedSwitch");
	var B = $("#FeaturedSwitch > div").size();
	var C = $("#featuredPosts");
	var F = $("#featuredPosts .container");
	var E = 602;
	G = parseInt(C.attr("rel"));
	A.find("div").removeClass("active");
	if (X == "next") {
		if (C.attr("rel") < B - 1) {
			F.animate( {
				marginLeft : -E * (G + 1) + "px"
			}, 150);
			C.attr("rel", G + 1);
			C.find("div.prev").show();
			if (G + 1 >= B - 1) {
				C.find("div.next").hide()
			}
			A.find("div.f" + (G + 1)).addClass("active")
		} else {
			SwitchFeatured(0)
		}
	} else {
		if (X == "prev") {
			if (C.attr("rel") != 0) {
				F.animate( {
					marginLeft : -E * (G - 1) + "px"
				}, 150);
				C.attr("rel", G - 1);
				C.find("div.next").show();
				if (G - 1 <= 0) {
					C.find("div.prev").hide()
				}
				A.find("div.f" + (G - 1)).addClass("active")
			}
		} else {
			F.animate( {
				marginLeft : -E * (X) + "px"
			}, 150);
			A.find("div.f" + (X)).addClass("active");
			C.attr("rel", X);
			if (X >= B - 1) {
				C.find("div.next").hide()
			} else {
				C.find("div.next").show()
			}
			if (X <= 0) {
				C.find("div.prev").hide()
			} else {
				C.find("div.prev").show()
			}
		}
	}
	return false
}
clickHandlers.home_page_popup = function(A) {
	fPopup.show( {
		view : "home_page_popup"
	})
};
clickHandlers.recommendation_info = function(A) {
	fPopup.show( {
		view : "recommendation_info"
	})
};

/** modular templating */
function favitModule() {
	// create new 
	var module = {
		name:'', // module name for hash lookup
		id:'', // if of placeholder object
		css:[], // css files to be loaded
		js:[], // js files to be loaded
		onload:'', // js code to be executed when module loaded
		cached:false, // should cache the response
		options:{}, // hash table of params to be passed on request
		next:null, // names of next modules to be loaded (chained)
		endpoint:'', // url to call for data (ajax call)
		state: 0 // -1 = chained, 0 = waiting, 1 = execution, 2 = finished
	};
	
	return module;
};


var FavitModular = {
	modules: {}, // FavitModule instances
	addCss: function(cssFile) { // include css file if module requires it
		var $link = $(document.createElement('link'));
	    	$link.attr('rel', 'stylesheet').attr('type', 'text/css').attr('href', cssFile);
	    $('head').append($link);
	},
	addJs: function(jsFile) { // include js file if module requires it
		var $script = $(document.createElement('script'));
	    	$script.attr('type', 'text/javascript').attr('src', jsFile);
	    $('head').append($script);
	},
	evalJs: function(jsCode) {
		
	},
	addModule: function(module) {
		if (module && module.name && !this.modules[module.name]) {
			this.modules[module.name] = module;
		}
		
		return this;
	},
	run: function() {
		for (name in this.modules) {
			var module = this.modules[name];
			
			if (module.state == 0 && module.next != "undefined" && module.next !== null) {
				if (typeof module.next === typeof "string") {
					this.modules[module.next].state--; // chained, don't execute
				}
				if (typeof module.next === typeof []) {
					for (index in module.next) {
						this.modules[module.next[index]].state--; // chained, don't execute
					}
				}
			}
			
			if (module.state == 0) { // waiting for execution
				module.state = 1; // move to execution state
				
				// if cached, use cache
				// cache response if enabled
				if (module.cached == true && FavitCache.is(module.name)) {
					this.callback(FavitCache.get(module.name));
				} else {
					$.get('/a/'+(module.endpoint || 'modules'), {name: module.name, options:module.options}, this.callback, 'json');
				}
			}
			
			module = null;
		}
	},
	callback: function(R) {
		if (!R) return false;
		
		var gmodule = FavitModular.modules[R.name];
		
		// cache response if enabled
		if (gmodule.cached == true && !FavitCache.is(gmodule.name)) {
			FavitCache.set(gmodule.name, R);
		}
		
		if (gmodule.state == 1 && gmodule.next != "undefined" && gmodule.next !== null) {
			if (typeof gmodule.next === typeof "string") {
				FavitModular.modules[gmodule.next].state++; // unchain
			}
			if (typeof gmodule.next === typeof []) {
				for (index in gmodule.next) {
					FavitModular.modules[gmodule.next[index]].state++; // unchain
				}
			}
		}
		
		gmodule.state = 2; // increase to 2 = finished
		
		// load css before modules is injected
		if (gmodule.css) {
			for (index in gmodule.css) {
				var cssFile = gmodule.css[index];
				this.addCss(cssFile);
			}
		}
		
		// replace placeholder with returned module content
		$('#module_'+gmodule.id).replaceWith(R.html);
		
		// load js after module is injected
		if (gmodule.js) {
			for (index in gmodule.js) {
				var jsFile = gmodule.js[index];
				this.addJs(jsFile);
			}
		}
		
		// continue loading modules
		FavitModular.run();
	}
};


/*** REMOVE THIS ITS ONLY A USAGE HINT ****

//ORDER METERS!
FavitModular.addModule({
	name:'sharebox',
	id:'sharebox',
	css:[],
	js:[],
	onload:'',
	options:{},
	next:['profile_guide', 'streams'],
	endpoint:'',
	state: 0
}).addModule({
	name:'profile_guide',
	id:'profile_guide',
	css:[],
	js:[],
	onload:'',
	options:{},
	next:'streams',
	endpoint:'',
	state: 0
}).run();

********* USAGE HINT END *********/
