		if (document.images) {
			imageObj = new Image();
			images = [
						'/images/headerbackground.gif',
						'/images/titletab2-11.png',
						'/images/contentareabk.gif',			
						'/images/footer_bk.gif',
						'/images/field.gif',
						'/images/shareit.png'
					];
					
			for(i=0; i<=images.length; i++) { imageObj.src=images[i]; }			
		}

		(function($) {

		var types = ['DOMMouseScroll', 'mousewheel'];

		$.event.special.mousewheel = {
		    setup: function() {
		        if ( this.addEventListener ) {
		            for ( var i=types.length; i; ) {
		                this.addEventListener( types[--i], handler, false );
		            }
		        } else {
		            this.onmousewheel = handler;
		        }
		    },

		    teardown: function() {
		        if ( this.removeEventListener ) {
		            for ( var i=types.length; i; ) {
		                this.removeEventListener( types[--i], handler, false );
		            }
		        } else {
		            this.onmousewheel = null;
		        }
		    }
		};

		$.fn.extend({
		    mousewheel: function(fn) {
		        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
		    },

		    unmousewheel: function(fn) {
		        return this.unbind("mousewheel", fn);
		    }
		});


		function handler(event) {
		    var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
		    event = $.event.fix(orgEvent);
		    event.type = "mousewheel";

		    // Old school scrollwheel delta
		    if ( event.wheelDelta ) { delta = event.wheelDelta/120; }
		    if ( event.detail     ) { delta = -event.detail/3; }

		    // New school multidimensional scroll (touchpads) deltas
		    deltaY = delta;

		    // Gecko
		    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
		        deltaY = 0;
		        deltaX = -1*delta;
		    }

		    // Webkit
		    if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
		    if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }

		    // Add event and delta to the front of the arguments
		    args.unshift(event, delta, deltaX, deltaY);

		    return $.event.handle.apply(this, args);
		}

		})(jQuery);
		


		//Initialize global variables
		var witPoll = 15000; //set to every 15 seconds
		var hash = location.hash;
		var lasttab = "";
		var activetab;
		var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
		var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
		
        $(document).ready(function() {


			$('#subject').change(function() {
				if ($(this).val() == "Become an Aristocrat") {
					$('#message').val("If you’re interested in being considering for an invitation to write with WitStream, please let us know here what your Twitter @usernameis. Follow @Witstreamdotcom and we will DM you if you’ve got the goods. If you’re not on Twitter, please direct us to any other relevant credentials or writing we can take a peek at.\n\nThanks for your interest!\n\nThe WitStream Team").focus(function() {
						$(this).val('');
					});					
				}
			});

			


			//Initialize page
		 	if (navigator && navigator.platform && navigator.platform.match(/^(iPad|iPod|iPhone)$/)) {
				$('.rounded, ul.mainmenu li').css({'-webkit-border-radius':'5px'});								
			} else if ($.browser.mozilla){
				if (hash=="") {
					hash = "#spotlight";
				};

				$('.rounded, ul.mainmenu li').css({'-moz-border-radius':'5px'});								
			} else {
				if (!$.support.borderRadius) $('.rounded').corner('round 5px');								
			}

			$('#content').hide();
			$('#home').addClass('activemenu');
			$('#notify').css('visibility','visible').hide();
			$("#dialog").dialog("destroy");
			
			
			//Initialize Tabs
			$("#tabs").tabs({
				add: function(event, ui) {
					$(ui.tab).parent().append('<div class="buttonbox"><button class="closetab">x</button</div>');
					lasttab = ui.tab.hash;
				},
				show: function(event, ui) {	
					if (!$.browser.msie) {
						$('title').html(ui.tab.text + ' | WitStream');
					}
					$('[id='+ui.tab.hash.substring(1)+']').attr('id', 'tmp_'+ui.tab.hash.substring(1));

					
					location.hash = ui.tab.hash;
					window.scroll(0,0);
					
					$('[id=tmp_'+ui.tab.hash.substring(1)+']').attr('id', ui.tab.hash.substring(1));
					if (lasttab != ui.tab.hash) {
						GAnalytics('/page/'+ui.tab.hash.substring(1));
					}
					lasttab = "";
					return false;					
				},
				select: function() {
					window.scroll(0,0);
				}
			});			

			//Initialize Event Triggers
			$('.goodone').live('click', function(e) {
				GAnalytics('/goodone/'+$(this).attr('name'));
				goodOne($(this).attr('name'), $(this));
			});

			$('.livefeeditem').live('mouseenter', function(e) {	
				if (!$(e.target).is('#shareit-box')) {
					$('#shareit-box').fadeOut(222);					
					$('#shareit-field').val('');
												
					$('.livefeeditem').find('div.itemtools').css('visibility','hidden');

					$(this).find('div.itemtools').css('visibility','visible');
					if ($(this).find('span.goodonecount').html() == "0") {
						$(this).find('span.goodonecount').hide();
					} else {
						$(this).find('span.goodonecount').show();						
					}
				}				
			});

			$('#tabs').live('mouseleave', function(e) {
//				$('div.itemtools').css('visibility','hidden')
			});
						
			$('#login').live('click', function(e){
				GAnalytics('/window/login');
				login($('#loginlink').html());
			});
			
			$('#forgot').live('click', function(e) {
				GAnalytics('/window/forgotpassword');
				$('#loginwindow').dialog('close');
				$("#forgotwindow").dialog({
					modal: true,
					resizable: false,
					width: 417,
					height: 295,					
					buttons: {
						Send: passwordCall
					}
				});
			});
				
			$('a#build').live('click', function() {
				createNewTab('search_test', 'search');				
			});
			
			$('.alister').live('click', function(e) {
				GAnalytics('/page/'+getHashtag($(this).attr('href')).substring(1, getHashtag($(this).attr('href')).length));				
				createNewTab(getHashtag($(this).attr('href')).substring(1, getHashtag($(this).attr('href')).length), getHashtag($(this).attr('href')).substring(1, getHashtag($(this).attr('href')).length), 'bio', $(this).attr('title'));
				e.preventDefault();
			});
						
			$('.closetab').live('click', function(e) {
					//Solves a nasty tabs collapsion bug
					if ($(this).parent().parent().hasClass('ui-state-active')) {
						$("#tabs").tabs('select', $(this).parent().find('a').attr('href'));
						$('#tabs').tabs("remove", $( "#tabs" ).tabs( "option", "selected" ));
					}
			});

			$('.hashtag').live('click', function() {								
				GAnalytics('/page/'+$(this).html().toLowerCase());				

				if ($(getHashtag($(this).attr('href').toLowerCase())).length == 0) {
					createNewTab(getHashtag($(this).html().toLowerCase()).substring(1), $(this).html());
				}
				$("#tabs").tabs('select', getHashtag($(this).attr('href').toLowerCase()));
				return false;
			});
			
			$('ul.mainmenu li').live('mouseenter',
				function() { 
					if (!$(this).is('.activemenu')) {
						$('ul.mainmenu li[class!=activemenu]').stop().animate({'backgroundColor':'#3d3d3d'}, 10);			
						$(this).css('backgroundColor','#3f3f40').stop().animate({'backgroundColor':'#ed4921','color':'#ffffff'}, 150);					
					}
				}				
			);
			
			$('ul.mainmenu li').live('mouseleave', 
				function() { 
					if (!$(this).is('.activemenu')) {
						$(this).stop().animate({'backgroundColor':'#3d3d3d','color':'#cccccc'}, 100);				
					}					
				}
			);
			
			$('div.logo').css({'cursor':'pointer'}).click(function() {	
				GAnalytics('/page/home');	
				$('#content').hide();
				$('#tabs').show();
//				$("#tabs").tabs('select', 0);
//				location.hash = '#spotlight';	
			});
			
			$('ul.mainmenu li, div.legal a[class!=thinkflo]').live('click',function(){
				//if mainmenu, make clicked link active
				if ($(this).parent().is('ul.mainmenu')) {					
					$('.activemenu').removeClass('activemenu');
					$(this).addClass('activemenu');
				}
				
				//Menu Exceptions
				
				if ($(this).text() == "Home" || $(this).text() == "mobile" || $(this).text() == "WitPicks" || $(this).text() == "My Profile" || $(this).text() == "Contact Us" || /^Log/.test($(this).text())) {

					if ($(this).text() == "Contact Us") {
						GAnalytics('/window/contactus');
						$("#contactuswindow").dialog({
							modal: true,
							resizable: false,
							width: 517,
							height: 850,					
							buttons: {
								Send: function() {
									$.ajax({
									   type: "POST",
									   url: "/contactus.php",
									   data: $('#contactusform').serialize(),
									   success: function(data){
										alert(data);
											var json = jQuery.parseJSON(data);					
											if (json['status']) {
												$("#contactuswindow").dialog('close');

												if (json['status']=='valid') {
													notifyMsg('Your message has been successfully sent.  We\'ll get back to you.');						
												}
											}
									   }
									 });		
									
								}

							}
						});						
					}



					$('#content').hide();
					$('#tabs').show();
					
					if ($(this).text() == "Home") {
//						$("#tabs").tabs('select', 0);
//						location.hash = '#spotlight';	
						window.location = "/";
					}
					
					
					
					if (/^Log/.test($(this).text()) || $(this).text() == "Blog") {
						$('ul.mainmenu li.activemenu').removeClass('activemenu');
						$('#home').addClass('activemenu');												
					}
					
					
					

				} else {
					
					GAnalytics('/page/'+($(this).text().toLowerCase()));				
					
					if (!$.browser.msie) {					
						$('title').html($(this).text() + ' | Witstream');
					}
					
					$('#content').show();
					$('#tabs').hide();		
					$('#content').html('').load('/content.php?page=' + urlencode($(this).text()), function() {
														
						if ($('div.listing').length != 0) {
							$('div.listing').columnize({columns:3});
						}
					});

					location.hash = urlencode($(this).text()).toLowerCase() + '_';

					if ($(this).text() != "The Aristocrats" && $(this).text() != "FAQs" ) {
						$('ul.mainmenu li.activemenu').removeClass('activemenu');
						$('#about').addClass('activemenu');																							
					}
				}
				
				$('ul.mainmenu li[class!=activemenu]').stop().animate({'backgroundColor':'#3d3d3d','color':'#cccccc'}, 100);
				$('.activemenu').css('backgroundColor','#3f3f40').stop().animate({'backgroundColor':'#ed4921','color':'#ffffff'}, 150);					
				
			});
						
			$('form').live('submit', function(e) {
				e.preventDefault();
				return false;
			});

			$('#remember').change(function() {
				if (!$('#remember').attr('checked')) {
					$.cookie('r', null);
				}
			});
			
			$('a[rel=shareit]').live('mouseenter', function(e) {
				var height = $(this).height();
				var top = $(this).offset().top;
				var left = $(this).offset().left + ($(this).width() /2) - ($('#shareit-box').width() / 2);		
				var value = $(this).attr('href').split('|');
				var field = value[0];
				var url = encodeURIComponent(value[0]);
				var title = $(this).attr('title').replace(/\+/g, ' ');
				var name = $(this).find('span').attr('title');
				$('#shareit-header').height(height);
				$('#shareit-box').fadeIn(222).css({'top':top, 'left':left});
				$('#shareit-field').val(field);
				$('a.shareit-sm').attr('target','_blank');

				$('a[rel=shareit-mail]').attr('href', 'mailto:?subject=' + ('Read that--you\'ll laugh!') + '&body=\"' + (title).replace(/^RT[ ][%]40(\w+)[ ]/, '') + '\"%0A%0A--'+ (name?name + " on ":"") +'WitStream%0A%0A' + url).click(function() {
					GAnalytics('/shareit/mail/'+value[0]);									

				});
				$('a[rel=shareit-delicious]').attr('href', 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + url + '&title=' + title).click(function() {
					GAnalytics('/shareit/delicious/'+value[0]);									
				});
				$('a[rel=shareit-facebook]').click(function(e) {
					e.preventDefault();
					var d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1181412741&u='+ url +'&t='+ title;
					1;
					try{
						//if(!/^(.*\.)?facebook\.[^.]*$/.test(l.host)) throw(0);
						share_internal_bookmarklet(p)
					} catch(z){
						a=function(){
							if(!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=0,width=626,height=436'))url=f+p
							};
						if(/Firefox/.test(navigator.userAgent)) setTimeout(a,0);
						else{
							a()
						}
					}
					void(0)
				});
				$('a[rel=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&amp;url=' + url + '&amp;title=' + title).click(function() {
					GAnalytics('/shareit/digg/'+value[0]);									
				});
				$('a[rel=shareit-stumbleupon]').attr('href', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title).click(function() {
					GAnalytics('/shareit/stumbleupon/'+value[0]);									
				});
				$('a[rel=shareit-twitter]').attr('href', ('http://twitter.com/home?status=' + (((title + ' ' + url).length > 140)?((title).substring(0, (140 - ((url).length + 4))) + '... '+ url):title + ' ' + url))).click(function() {
					GAnalytics('/shareit/twitter/'+value[0]);									
				});
			});


			$('#shareit-box').live('mouseleave', function () {
//				$('#shareit-field').val('');
//				$(this).hide();
			});
			$('#shareit-field').live('click', function () {
				GAnalytics('/shareit/urlcopy/'+$(this).val());				
				$(this).select();
			});

			$('#subscribe').live('click', function() {
				GAnalytics('/window/subscribe');				
				
				$("#subscribewindow").dialog({
					modal: true,
					resizable: false,
					width: 417,
					height: 295,					
					buttons: {
						Signup: function() {
							element = $(this)
							$.ajax({
							   type: "POST",
							   url: "/subscriberadd.php",
							   data: $('#subscribeform').serialize(),
							   success: function(data){	
									var value = jQuery.parseJSON(data);					
									if (value['status'] == "invalid") {
										notifyMsg(value['message']);
										return;
									}

									if (value['status'] == "valid") {
										notifyMsg(value['message']);
										$(element).dialog('close');
										return;
									}


								}
							 });
						}
											
					}
				});
			});			
				
			$("a.youtube").live('click', function() {
				$.fancybox({
						'padding'			: 0,
						'autoScale'			: false,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none',
						'title'				: this.title,
						'width'				: 680,
						'height'			: 495,
						'href'				: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'				: 'swf',
						'swf'				: {
						'wmode'				: 'transparent',
						'allowfullscreen'	: 'true',
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'

						}
					});

				return false;
			});
			
			
			$("a.gmaps").live('click', function() {			
			$.fancybox({
						//'orig'			: $(this),
						'padding'		: 0,
						'width'				: 780,
						'height'			: 800,
						'type'				: 'iframe',
						'href'			: this.href,
						'title'   		: this.title,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'
			});
				return false;
			});


			$("a.weblink").live('click', function() {			
			$.fancybox({
						//'orig'			: $(this),
						'padding'		: 0,
						'width'				: 630,
						'height'			: 830,
						'type'				: 'iframe',
						'href'			: this.href,
						'title'   		: this.title,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'
			});
				return false;
			});

			$("a.link").live('click', function() {			
			$.fancybox({
						//'orig'			: $(this),
						'padding'		: 0,
						'width'				: 890,
						'height'			: 700,
						'type'				: 'iframe',
						'href'			: this.href,
						'title'   		: this.title,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'
			});
				return false;
			});

			$("a.biomax, a.bioback").live('click', function() {
				$('div.bioblurb').slideToggle(0);
				$('div.biofull').slideToggle(0);
			});
			
			

						
			//Lazyloader
			$(window).scroll(function(){
				
				if (($(window).height() + $(window).scrollTop()) >= ($(document).height() - 300)) {
					if (!/[_]/.test($('#tabs ul li:eq('+ $( "#tabs" ).tabs( "option", "selected" ) +')').find('a').attr('href').substring(1))) {
						retrieveWits(activetab || $('#tabs ul li:eq('+ $( "#tabs" ).tabs( "option", "selected" ) +')').find('a').attr('href').substring(1), 'lazy');
					} else {
						//If End of page on profile
						retrieveWits($($('#tabs ul li:eq('+ $( "#tabs" ).tabs( "option", "selected" ) +')').find('a').attr('href')+" div.biotabs").attr('id').substring(0, 24)   , 'biolazy', $($('#tabs ul li:eq('+ $( "#tabs" ).tabs( "option", "selected" ) +')').find('a').attr('href')+" div.biotabs").attr('id').substring(0, 24));
//						notifyMsg($($('#tabs ul li:eq('+ $( "#tabs" ).tabs( "option", "selected" ) +')').find('a').attr('href')+" div.biotabs").attr('id').substring(0, 24));

					}
				};
			});

			//Panel Rotation
			$('div#rotatepanel').cycle({
				fx: 'fade',
				timeout: 15000,
				next: $('a.gotoht'),
				pause: false,
				autostopCount: 1,
				autostop: true
			});


			//Initialize Hot Topics
			hotTopicsLoop = setInterval(function() {
				if ($('ul#hottopics li:first-child').html() != $('ul#hottopics li:last-child').html() && $('ul#hottopics li:first-child').html() != "") {
					$('ul#hottopics li:first-child').fadeTo('slow', 0, function() {														
						$(this).slideUp('slow', function() {
								$(this).appendTo('ul#hottopics').slideDown(0).fadeTo(0, 1);
						});
					});				
				}
			}, 5000);

			function cloneHotTopic() {
				
			}

			//if page is refreshed and not on the requesting hashmark
			if (hash != location.hash) {
				if (hash.substr(hash.length - 1, 1) == "_") {					
				//process pages	
					$.each($('ul.mainmenu li, div.legal a[class!=thinkflo]'), function(index, item) {
						if (('#' + urlencode($(item).text().toLowerCase()) + "_") == hash) {
							$(item).trigger('click');
						}
					})
				} else {
					createNewTab(hash.substring(1), hash.substring(1));

					setTimeout(function() {
						$("#tabs").tabs('select', hash);
					},100);
				}		
			}

/*
			//Hash Watchdog			
			if (location.hash && $(location.hash).length == 0) {				
				createNewTab(location.hash.substring(1), location.hash.substring(1));
				$("#tabs").tabs('select', location.hash);				
			}

			setInterval(function() {
				$.each($('abbr[class!=timeset]'), function(index, item) {
					$(item).html(prettyDate($(this).attr('title') * 1000));
					if ($(this).attr('title') < Math.round(new Date().getTime() / 1000 - 3600)) {									
						$(this).addClass('timeset');
					}
				});				
			}, 600000);
			*/

/*
			//enables the ability to open missing tabs from browser back history
			setInterval(function() {
				if (location.hash != hash) {
					//If Tab called and doesn't exist, add it and display it.
					if ($(location.hash).length == 0) {						
						createNewTab(location.hash.substring(1).toLowerCase(), location.hash.substring(1));
					}

					$("#tabs").tabs('select', location.hash);

					hash = location.hash;
					if ($('.activemenu').text() !="Home" && $('.activemenu').text() !="My Profile") {
						$('ul.mainmenu li.activemenu').removeClass('activemenu');
						$('#home').addClass('activemenu');
						$('ul.mainmenu li[class!=activemenu]').stop().animate({'backgroundColor':'#3d3d3d','color':'#cccccc'}, 100);
						$('.activemenu').css('backgroundColor','#3f3f40').stop().animate({'backgroundColor':'#ed4921','color':'#ffffff'}, 150);																																
					}
					$('#content').hide();
					$('#tabs').show();
				}
			}, 100);
*/

			//Populate Default Tabs - to be rendered serverside in production
			retrieveWits('spotlight', 'init');
			retrieveWits('livefeed', 'init');
			retrieveWits('blacklist', 'init');				

			$.ajax({
			   url: "tabs.php",
			   success: function(data){									
					var json = jQuery.parseJSON(data);					
					for (i=0;i<json.length;i++) {
						$.each(json[i], function(key, value) {
							retrieveWits(value, 'init');
						});
					}
			   }
			 });			
			

//			retrieveWits('goldenglobes', 'init');

			//Initialize witStream polling loop
			setInterval(function() {
				retrieveWits('livefeed', 'pull');
			}, witPoll);
			
			$('#witstream').load('/login.php?l');
			
			$('a').live('click', function() {
				$('a.twitterbutton').attr('href', "http://twitter.com/share?url="+urlencode(document.location));
			});
			
			
});




		/*
		 * JavaScript Pretty Date
		 * Copyright (c) 2008 John Resig (jquery.com)
		 * Licensed under the MIT license.
		 */
		// converts ISO time to casual time
		function prettyDate(time){
			if (Math.round(new Date(time).getTime()) > Math.round(new Date().getTime())) {
				time = new Date().getTime();
			}
			var date = new Date(time),

				diff = (((new Date()).getTime() - date.getTime()) / 1000),
				day_diff = Math.floor(diff / 86400);
				month_diff = Math.floor(diff / 2628000);

			if ( isNaN(day_diff) || day_diff < 0)
				return;
			var v = day_diff == 0 && (
					diff < 60 && "a moment ago" ||
					diff < 120 && "about a minute ago" ||
					diff < 3600 && Math.floor( diff / 60 ) + " minute"+(Math.floor( diff / 60 )==1?"":"s")+" ago" ||
					diff < 7200 && "1 hour ago" ||
					diff < 86400 && Math.floor( diff / 3600 ) + " hour"+(Math.floor( diff / 3600 )==1?"":"s")+" ago") ||
				day_diff == 1 && "Yesterday" ||
				day_diff < 7 && day_diff + " day"+(day_diff==1?"":"s")+" ago" ||
				day_diff < 31 && Math.ceil( day_diff / 7 ) + " week"+(Math.ceil( day_diff / 7 )==1?"":"s")+" ago" ||
				day_diff < 365 && Math.ceil( month_diff / 30.416 ) + " month"+(Math.ceil( month_diff / 30.416 )==1?"":"s")+" ago"

				;
			if (!v)
				window.console && console.log(time);
			return v ? v : '';
		}
		
		function is_numeric(val) {

		    if (isNaN(parseFloat(val))) {

		          return false;

		     }

		     return true

		}
		

		function getHashtag(value) {
			var values = value.split('#');
			return "#" + values[(values.length-1)];
		}

		function stripBad(string) {
			for (var i=0, output='', valid="eE-0123456789."; i<string.length; i++) 
				if (valid.indexOf(string.charAt(i)) != -1) { 
					output += string.charAt(i);
				}
		    return output; 
		}

		//Functions
		function base_convert(number, frombase, tobase) {			
			if (/^W/.test(number)) {
				return 'W'+ parseInt(number.substring(1,number.length) + '', frombase | 0).toString(tobase | 0);
			} else {
		    	return parseInt(number + '', frombase | 0).toString(tobase | 0);
			}
		}
		
		function urlencode(str) {
		    str = (str+'').toString();
		    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
		}

		function login(state) {			

			if ($('#loginlink').html() == 'Log Off') {				
				loginCall('logoff');										
			} else {
					$("#loginwindow").dialog({
						modal: true,
						resizable: false,
						width: 417,
						height: 425,					
						buttons: {
							Login: loginCall		
						}
					});
			}
		}

		function goodOne(id, element) {			
			$.ajax({
			   type: "POST",
			   url: "/goodone.php",
			   data: 'id='+id,
			   success: function(data){									
					var json = jQuery.parseJSON(data);					
					if (json['result']) {						
						$(element).parent().find('span.goodonecount').html(json['result']);
						
						if ($(element).parent().find('span.goodonecount').html() == "0") {
							$(element).parent().find('span.goodonecount').hide();
						} else {
							$(element).parent().find('span.goodonecount').show();						
						}
					}					
			   }
			 });			
		}

		function loginCall(status) {
//			if (!$.browser.msie) {
				$.ajax({
				   type: "POST",
				   url: "/login.php",
				   data: (status=='logoff'?'logoff=logoff':$('#loginform').serialize()),
				   success: function(data){	
						var json = jQuery.parseJSON(data);		
						if (json['status']!="failure") {						
							$("#loginblock").remove();
							$('div.contentarea').after('<div id=loginblock>'+json['content']+'</div>');
							$('#loginlink').text((json['status']=="login"?'Log Off':'Log In'));
							$("#loginwindow").dialog('close');
						} else {
							$('#loginwindow').parent().effect('shake', { times: 4 }, 100);
						}	
				   }
				 });
//			} else {
//				alert("Sorry, we are still working away at the site.  There's some problems in IE and we haven't had the time to fix them yet, so for now, could you use another browser?  Something modern, like Chrome, Firefox, Safari, Opera or even iPhone and iPad mobile Safari.  We will fix the site for IE soon though.");
//			}
		}

		function passwordCall() {			
			$.ajax({
			   type: "POST",
			   url: "/password.php",
			   data: $('#forgotform').serialize(),
			   success: function(data){									
					var json = jQuery.parseJSON(data);					
					if (json['status']) {
						$("#forgotwindow").dialog('close');

						if (json['status']=='valid') {
							notifyMsg('Your password has been successfully sent to you at ' + json['email'] + '.  Please check your inbox in the next minute or so.');						
						}

					}					
			   }
			 });		
		}

		function ucwords(str) {
		    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
		        return $1.toUpperCase();
		    });
		}

		function replaceLinks(text) {
			//Transform URLS

			var text = text.replace(/(\b(href[=]["]http|src[=]["]http|https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@\/%=~_|])/ig,"<a href='$1' class='link' target=_blank>$1</a>");

			//Transform Hashtags
			text = text.replace(/(^|\s)#(\w*[a-zA-Z_]+\w*)/ig,"&nbsp;<a class='hashtag' href='#$2'>$2</a>");
			return text; 			
		}
		
		function createHash(firstname, lastname) {
			return '#' + (firstname.replace(' ', '-').toLowerCase() +'_' + lastname.replace(' ', '-').toLowerCase()).replace(/[^-a-zA-Z 0-9_]+/g,'I');
		}


		function strpos (haystack, needle, offset) {
		    // Finds position of first occurrence of a string within another  
		    // 
		    // version: 1008.1718
		    // discuss at: http://phpjs.org/functions/strpos
		    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		    // +   improved by: Onno Marsman    
		    // +   bugfixed by: Daniel Esteban
		    // +   improved by: Brett Zamir (http://brett-zamir.me)
		    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
		    // *     returns 1: 14
		    var i = (haystack+'').indexOf(needle, (offset || 0));
		    return i === -1 ? false : i;
		}

		function myTruncate(string, limit)
		{
			var breakchr=".";
			var pad="...";
		  // return with no change if string is shorter than $limit
		  if((string).length <= limit) return string;

		  // is $break present between $limit and the end of the string?
		var breakpoint = strpos(string, breakchr, limit);
		    if(breakpoint < (string.length - 1)) {
		      string = string.substring(0, breakpoint) + pad + "&nbsp;<a class='biomax'>MORE</a>";;
		    } else {
				string = string.substring(0, limit) + pad + "&nbsp;<a class='biomax'>MORE</a>";
			}

		  return string;
		}


		function createNewTab(name, label, type, id) {
			location.hash = name;
			if (!/[_]/.test(name)) {

				if (/^[a-zA-Z0-9_]+$/.test(name) && /^[a-zA-Z0-9_]+$/.test(label)) {


					if (name == "Invite") {
						
						if ('undefined' !== typeof witinvite) {
							if (witinvite == "TRUE") {
								$("#tabs").tabs("add","#"+name, label.replace('_',' '));
								$('#'+name).html('<ul id="'+name+'-list"></ul>');
								$("div#Invite").load('/invite.php', function() {
									$('#pulltweets').change(function() {
										if ($(this).is(':checked')) {
											$('#tweetname').removeClass('disabled');
									        $('#twittername').removeAttr('disabled');
									    } else {
											$('#tweetname').addClass('disabled');
									        $('#twittername').attr('disabled', true);
									    }										
									});
									
									$('#invitesave').click(function() {
										
										if ($('#agreetou').is(':checked')) {											
										} else {
											notifyMsg('You must agree to the Terms of Use');
											return;											
										}
										
										
										
										if ($('#invitefirstname').val() == "" || $('#invitelastname').val() == "") {
											notifyMsg('The name fields are blank. Please reenter and try again');
											return;
										}
										
										
										if (!/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test($('#inviteemail').val())) {
											notifyMsg('The Email Address is invalid. Please reenter and try again.');
											return;											
										}
										
										if ($('#invitepassword').val() != $('#inviteconfirm').val()) {
											notifyMsg('The Passwords do not match. Please reenter and try again.');
											return;
										}
										if ($('#invitepassword').val().length < 6) {
											notifyMsg('Your Password needs to be at least six characters. Please reenter and try again.');
											return;
										}
										//names[0].replace('-',' ').replace('I','~'), 'lastname': names[1].replace('-',' ').replace('I','~')
										$.ajax({
											url: '/inviteuser.php?code='+document.location.pathname.substring(1)+'&'+Math.round(new Date().getTime()),
											type: 'POST',
											data: $('#inviteform').serialize(),
											success: function(data) {
												var json = jQuery.parseJSON(data);					
												if (json['status']) {
													if (json['status']=='success') {
														$('#user').val($('#inviteemail').val());
														$('div#tabs ul.ui-tabs-nav li.ui-state-active div.buttonbox button.closetab').trigger('click');																			
														$('#login').trigger('click');														
														notifyMsg('You have been setup successfully.  Please log in to continue.');																																		
													} else {
														notifyMsg(json['error']);																				
													}
												}

											}

										});
									});
									
									
								});
								

								
								
							} 
						} else {
							
							window.location = "/";
							
						}
					} else {

						//old create tab code here
						if ($('#'+name).length == 0) {
							$("#tabs").tabs("add","#"+name, label.replace('_',' '));
							$('#'+name).html('<ul id="'+name+'-list"></ul>');
							
						}				


						retrieveWits(name, 'init');

					}

				}
				
			} else {

				var names = name.replace('+',' ').split('_');
				
				if (names[0]=='search') {
					notifyMsg(names[0]);
				} else {
				
				if ($(createHash(names[0], names[1])).length == 0) {
					$.ajax({
						url: '/getuser.php?'+Math.round(new Date().getTime()),
						data: {'firstname': names[0].replace('-',' ').replace('I','~'), 'lastname': names[1].replace('-',' ').replace('I','~')},
						success: function(data) {
							
							//Create Profile page							
							var json = jQuery.parseJSON(data);
							//Add Profile Tab
							$("#tabs").tabs("add", createHash(json['firstname'], json['lastname']), ucwords(json['firstname'])+' '+json['lastname']);

							//Create content
/*
							$(createHash(json['firstname'],json['lastname'])).html('<div class="biocontainer" id="' + json['_id'] + '-bio"><div class="bioleftpanel"><div class="bioprofilepic" id="'+ json['_id'] + '-pic"></div><div class="bioheader"><h2 id="'+json['_id']+'-name"></h2>'+(json['twitteruser']==""?"":"<h3><a target=_blank href='http://twitter.com/"+json['twitteruser']+"'>@"+json['twitteruser']+"</a></h3>")+'<div class="bioblurb"><p class="bioedit">'+myTruncate(json['bio'], 333)+'</p></div><div class="biofull" style="display: none;"><p class="biofulltext">'+json['bio']+'</p><a class="bioback">LESS</a></div></div></div><div class="biorightpanel"><div class="tabs biotabs" id="'+ json['_id'] +"-tabs"+'" ><ul style="visibility: hidden;" class="biotabs-tabs"><li><a href="#'+json['_id']+'stream"><span>Stream</span></a></li><li><a href="#'+json['_id']+'calendar"><span>Calendar</span></a></li>				        <li><a href="#'+json['_id']+'videos"><span>Videos</span></a></li>				        <li><a href="#'+json['_id']+'reviews"><span>About</span></a></li>				        <li><a href="#'+json['_id']+'buystuff"><span>Buy Stuff</span></a></li>				    </ul>					<div id="'+json['_id']+'stream"><ul id="'+json['_id']+'-list"></ul></div>					<div id="'+json['_id']+'calendar"><ul id="'+json['_id']+'calendarcontent"></ul></div>					<div id="'+json['_id']+'videos"><ul id="'+json['_id']+'videocontent"></ul></div>					<div id="'+json['_id']+'reviews"><ul id="'+json['_id']+'reviewcontent"></ul></div>					<div id="'+json['_id']+'buystuff"><ul id="'+json['_id']+'productscontent"></ul></div>				</div></div><div style="clear: both;"></div></div>');
*/
$(createHash(json['firstname'],json['lastname'])).html('<div class="biocontainer" id="' + json['_id'] + '-bio"><div class="bioleftpanel"><div class="bioprofilepic" id="'+ json['_id'] + '-pic"></div><div class="bioheader"><h2 id="'+json['_id']+'-name"></h2>'+(json['twitteruser']==""?"":"<h3><a target=_blank href='http://twitter.com/"+json['twitteruser']+"'>@"+json['twitteruser']+"</a></h3>")+'<div class="bioblurb"><p class="bioedit">'+myTruncate(json['bio'], 333)+'</p></div><div class="biofull" style="display: none;"><p class="biofulltext">'+json['bio']+'</p><a class="bioback">LESS</a></div></div></div><div class="biorightpanel"><div class="tabs biotabs" id="'+ json['_id'] +"-tabs"+'" ><ul style="visibility: hidden;" class="biotabs-tabs"><li><a href="#'+json['_id']+'stream"><span>Stream</span></a></li><li><a href="#'+json['_id']+'reviews"><span>Links</span></a></li></ul>					<div id="'+json['_id']+'stream"><ul id="'+json['_id']+'-list"></ul></div><div id="'+json['_id']+'reviews"><ul id="'+json['_id']+'reviewcontent"></ul></div></div></div><div style="clear: both;"></div></div>');


							$("#"+json['_id']+"-name").html(json['firstname'] + "&nbsp;" + json['lastname']);
							$("#"+json['_id']+"-pic").html("<img width=143 height=143 src='/images/pics/"+ createImagePath(json['firstname'], json['lastname']) +"' alt='"+json['firstname']+" "+json['lastname']+"'/>");

							//Create Profile Tabs
							$("#" + json['_id'] + "-tabs").tabs();

							if (json['twitterid']==0) {
								json['twitterid']= json['_id'];
							}
							
							
							//Select Tab
							$("#tabs").tabs('select', createHash(json['firstname'], json['lastname']));	
							

							//Retrieve Stream
							retrieveWits(json['_id'], 'bio', json['twitterid'], json['_id']);	
							retrieveCalendar(json['_id']);
							retrieveVideos(json['_id']);
							retrieveReviews(json['_id']);
							retrieveProducts(json['_id']);

							$('div#'+ json['_id'] +"-tabs ul.biotabs-tabs").hide().css({'visibility':'visible'}).slideDown(1000);
						}
					});
				} else {
					$("#tabs").tabs('select', createHash(names[0], names[1]));	
												
				}
			
				}
			}
			
			$('#content').hide();
			$('#tabs').show();
			
			$('ul.mainmenu li.activemenu').removeClass('activemenu');
			$('#home').addClass('activemenu');	
			$('ul.mainmenu li[class!=activemenu]').stop().animate({'backgroundColor':'#3d3d3d','color':'#cccccc'}, 100);
			$('.activemenu').css('backgroundColor','#3f3f40').stop().animate({'backgroundColor':'#ed4921','color':'#ffffff'}, 150);	

		}

		function retrieveCalendar(id) {
			thisid = id;
			//Retrieve Calendar
			$.ajax({
			   type: "POST",
			   url: "/calendarview.php?"+ Math.round(new Date().getTime()),
			   data: 'id='+thisid,
			   success: function(data){	
					var cal = jQuery.parseJSON(data);					
					if (cal['status']) {

						if (cal['entries'].length>0) {
						var calentries = "";
						$.each(cal['entries'], function(index, item) {
							var eventdate = new Date(item['eventdatestamp'] * 1000);
							calentries += "<li class='eventitem'><div class='eventdate'>" +days[eventdate.getDay()] + "<br />" + months[eventdate.getMonth()] + "<br />" + eventdate.getDate() + "<br />"  + eventdate.getFullYear() + "<br />" + eventdate.getHours() + ":" + ((eventdate.getMinutes()<10)?"0":"") + eventdate.getMinutes() + "</div><div class='eventdetail'>" + item['eventname'] + "<br />" + item['eventdescription'] + "<br />" + item['eventlocation'] + "<br />" + item['eventaddress'] + ", " + item['eventcity'] + ", " + item['eventstate'] + " " + item['eventzip'] + "&nbsp;<a target=_blank class='gmaps' href='http://maps.google.com/maps?f=&q="+ urlencode(item['eventaddress'])+",+" + urlencode(item['eventcity'])+",+"+urlencode(item['eventstate'])+ (item['eventzip']==""?"":", "+item['eventzip'])+"'>[map]</a><br />" + item['eventurl'] + "<br />" + item['eventlineup'] + "<br />" + item['eventprice'] + "<br />" + item['eventbuytix'] + "</div></li>";
							$('#'+thisid+'calendarcontent').html(calentries);
						});
						} else {
							$.each($('#'+thisid+'-tabs ul li a span'), function(index, item) {
								if ($(item).text()=="Calendar") {
									//$('#'+thisid+'-tabs').tabs("remove", index);
									if ( (typeof(userid) == 'undefined' || userid != thisid) ) {
//										$(item).parent().parent().hide();										
									}
								}
							});
							
						}
					}					
			   }
			 });		

			
		}

		function retrieveVideos(id) {
			thisid = id;
			//Retrieve Calendar
			$.ajax({
			   type: "POST",
			   url: "/videosview.php?"+ Math.round(new Date().getTime()),
			   data: 'id='+thisid,
			   success: function(data){	
					var vid = jQuery.parseJSON(data);					
					if (vid['status']) {
						if (vid['entries'].length>0) {
						var entries = "";
						$.each(vid['entries'], function(index, item) {
							entries += "<li class='videoitem'><a href='" + item['videourl'] + "' class='youtube'>" + item['videotitle'] + "</a></li>";
							$('#'+thisid+'videocontent').html(entries);
						});
						} else {
							$.each($('#'+thisid+'-tabs ul li a span'), function(index, item) {
								if ($(item).text()=="Videos") {
//									$('#'+thisid+'-tabs').tabs("remove", index);
									if ( (typeof(userid) == 'undefined' || userid != thisid) ) {
//										$(item).parent().parent().hide();										
									}
								}
							});
						}
					}					
			   }
			 });		
		}

		
		function retrieveReviews(id) {
			thisid = id;
			//Retrieve Calendar
			$.ajax({
			   type: "POST",
			   url: "/reviewsview.php?"+ Math.round(new Date().getTime()),
			   data: 'id='+thisid,
			   success: function(data){	
					var rev = jQuery.parseJSON(data);					
					if (rev['status']) {
						if (rev['entries'].length>0) {
						var entries = "";
						$.each(rev['entries'], function(index, item) {
							entries += "<li class='reviewitem'>"+ item['reviewsbody'] + "</li>";
							$('#'+thisid+'reviewcontent').html(entries);
						});
						} else {
							$.each($('#'+thisid+'-tabs ul li a span'), function(index, item) {
								if ($(item).text()=="About") {
//									$('#'+thisid+'-tabs').tabs("remove", index);
									if ( (typeof(userid) == 'undefined' || userid != thisid) ) {									
//										$(item).parent().parent().hide();										
									}
								}
							});
						}
					}					
			   }
			 });		
		}

		function retrieveProducts(id) {
			thisid = id;
			//Retrieve Calendar
			$.ajax({
			   type: "POST",
			   url: "/productsview.php?"+ Math.round(new Date().getTime()),
			   data: 'id='+thisid,
			   success: function(data){	
					var prd = jQuery.parseJSON(data);				
					if (prd['status']) {
						if (prd['entries'].length>0) {
						var entries = "";
						$.each(prd['entries'], function(index, item) {
							entries += "<li class='productitem'>" + (item['producturl']==""?item['productname']:"<a target=_blank href='"+ item['producturl']+"'>"+ item['productname'] + "</a>") + " - "+ item['producttype'] +" "+ item['productprice']+"<span>"+item['productdescription']+"</span></li>";
							$('#'+thisid+'productscontent').html(entries);
						});
						} else {
							$.each($('#'+thisid+'-tabs ul li a span'), function(index, item) {
								if ($(item).text()=="Buy Stuff") {
//									$('#'+thisid+'-tabs').tabs("remove", index);
									if ( (typeof(userid) == 'undefined' || userid != thisid) ) {									
//										$(item).parent().parent().hide();										
									}
								}
							});
						}
					}					
			   }
			 });		
		}
		


		function processHashtags(name, value) {	
			var hashtag = $('#' + name + value['id_str'] + ' a.hashtag');
			$.each(hashtag, function(index, value) {
				if ($(hashtag[index]).html() != null) {
					var tabpieces = ($(hashtag[index]).attr('href')).split('#');
					$(hashtag[index]).attr('href',('#' + tabpieces[1].replace(/[^a-zA-Z 0-9]+/g,'')) );
					$(hashtag[index]).html(tabpieces[1]).click(function(){
						if ($('#'+tabpieces[1]).length == 0) {
							var element = '#' + tabpieces[1] + '-list';
							$(element).append('<li>' + tabpieces[1] + '</li>');
						}
						$("#tabs").tabs('select', '#' + tabpieces[1] );
					});
				}
			});
		}
		
		function GAnalytics(page) {
			if (typeof(pageTracker) != "undefined") {
					pageTracker._trackPageview(page); 
			}
		}

		function notifyMsg(message) {
			$('div#notify').text(message).slideDown(500).delay(4000).fadeOut(1000);
		}

		function createImagePath(firstname, lastname) {
			return ((firstname.replace(' ', '-') +'_' + lastname.replace(' ', '-')).replace(/[^a-zA-Z 0-9+_]+/g,'').toLowerCase() + '.png');			
		}

		function retrieveWits(tab, type, id, gid) {
			//tabs: spotlight, livefeed, blacklist, #topics
			//type: init, lazy
			var element = '#'+ tab +'-list';


			$.ajax({
				url: '/getwits.php?'+Math.round(new Date().getTime()),
				data: {'last': ($('#'+ tab + '-list li:first-child abbr.timestamp').attr('title')), 'first': ($('#'+ tab + '-list li:last-child abbr.timestamp').attr('title')), 'type': type, 'tab': tab, 'id': id, 'gid': gid },
				success: function(data) {

					//Initialize local variables
					var countposts = 0;
					var json = jQuery.parseJSON(data);
					//To minimize bandwidth utilization, we encode the results type only on exception transations
					if (json['type']) var results = json['results']; else var results = json;


					$.each(results, function(key, value) {


						var orig = $(window).scrollTop();

						//Handle real-time deleted posts
						if (value['status'] == 'deleted') {													
							$.each($('li.' + value['id_str']), function() {
								$(this).slideUp('slow', function() {
									$(this).remove();
								});								
							});
														
						}  else {



							//If the wit does not exist, we add it on the page 
							if ($('#' + tab.replace("_", "") + '_' + value['id_str']).length == 0) {
								
								
								//Count the total number of posts for the Notification window
								countposts++;

								var wit = '<li id="' + tab.replace("_", "") + '_' + value['id_str'] + '" time="'+value['created_at']+'" value="' + value['id_str'] + '" class="' + value['id_str'] + '  livefeeditem" onclick = "void(0)">';
								$.each(value['hashtags'], function(index, value) {
									wit += "<div class='posticons " + value.replace("#", "_").toLowerCase() + "'></div>";
								});
								var permalink = value['id_str'];
								wit += '<div class="post" id="'+value['id_str']+'"><div class="biopic"><a name="live' + value['id_str'] + '" class="alister" href="' + createHash(value['user']['firstname'],value['user']['lastname']) + '"><img border=1 class="thumbnails" alt="'+ (createHash(value['user']['firstname'],value['user']['lastname'])).substring(1) +'" src="'+(value['user']['twitterimg'].length>0?(("https:" == document.location.protocol?'https://www.witstream.com/ssl.php?url='+value['user']['twitterimg']:value['user']['twitterimg'])):'/images/thumb/'+createImagePath(value['user']['firstname'], value['user']['lastname']))+'" /></a></div><div class="comment-a-lister-name"><a name="live' + value['id_str'] + '" title="'+value['user']['id']+'" class="alister" href="' + createHash(value['user']['firstname'],value['user']['lastname']) + '">'+value['user']['firstname']+'&nbsp;'+value['user']['lastname']+'</a></div><abbr class="timestamp" title="' + value['created_at'] + '">' + value['created_at'] + '</abbr></h4><p>' + replaceLinks(value['text']) + '</p><div class="itemtools"><a class="goodone" name="'+ value['permalink'] +'">GOOD ONE</a> <span class="goodonecount">'+value['goodonecount']+'</span> | <a href="http://wits.ms/'+ value['permalink'] +'" title="'+ urlencode( ((value['user']['twitteruser'].length>1?"RT @"+value['user']['twitteruser']+" ":"")) + value['originaltext']) +'" rel="shareit"  onclick="void(0)"><span title="' + urlencode(value['user']['firstname']) + ' ' + value['user']['lastname']+'">SHARE</span></a></div><hr /><div class=commentcontainer>';

								if (value['comments']) {
									$.each(value['comments'], function(ind, comment) {
										wit += "<div class='comments' id='"+comment['timestamp']+"'><div class=commentcontainer id='"+value['id_str']+"' ><div class=commentwrapper><img src='"+ ((typeof(comment['twitterimg']) != "undefined" && comment['twitterimg'] != "" && comment['twitterimg'] != null) ? ("https:" == document.location.protocol?'https://www.witstream.com/ssl.php?url='+comment['twitterimg']:comment['twitterimg']) : ("/images/thumb/" + createImagePath(comment['firstname'], comment['lastname']))) + "' /><div class=commentuser><a href='"+ createHash(comment['firstname'], comment['lastname']) + "' class='alister'><span>" + (comment['firstname'] + " " + comment['lastname']).toUpperCase() + "</span></a><abbr style='margin-left: -0px;' class='timestamp' title='" + comment['timestamp'] + "'>" + comment['timestamp'] + "</abbr></div><span class='commentpostarea'>"+comment['text']+"</span><div class=commenttools></div></div></div></div>";
									})
								}

								wit +='</div></div></li>';

								if (json['type'] == 'lazy'  || json['type'] == 'biolazy') {								

									$(element).append(wit);
								} else {
									if (type != "init") {
										$.each(value['hashtags'], function(index, tag) {
											//Assigns specific post IDs for existing tabs from livefeed polling
											wittab = wit.replace(('li id="livefeed'), ('li id="' + tag.replace("#","").replace("_", "")) );

											//Inserts onto other open tabs
											if (type=='pull') {
												if ($('#' + tag.replace("#","") + '-list').length > 0) {										

													//If specific post ID does not exist
													if ($('li#' + tag.replace("#","").replace("_", "") + "_" + value['id_str']).length == 0) {																						
														//We add the post
														
														$('#' + tag.replace("#","") + '-list').prepend(wittab);
														//And make sure it's displayed in cronological order (just in case things are out of order) 

														$('#' + tag.replace("#","") + '-list li').tsort({order:"desc",attr:"time"});	
														$.each($('.livefeeditem').find('abbr[class!=timeset]'), function(index, item) {
															$(item).html(prettyDate(parseInt($(this).attr('title')) * 1000));

															if ($(this).attr('title') < Math.round(new Date().getTime() / 1000 - 3600)) {									
																$(this).addClass('timeset');
															}
														});	
														$('#' + tag.replace("#","") + '_' + value['id_str']).hide().slideDown(2000);									
														
													}																		
												}
											}
										});	
																		
									} else {
										window.scroll(0,0);										
									}
									
									if ($('#' + tab.replace("_", "") + "_" + value['id_str']).length == 0) {
										$(element).prepend(wit);
									}
									
								}

								$('#' + tab + '_' + value['id_str']).attr('title', value['created_at']).find('abbr').attr('title', value['created_at']);

								processHashtags(tab, value);
								//$('abbr[class!=timeset]').addClass('timeset').timeago();	
								$.each($(element).find('abbr[class!=timeset]'), function(index, item) {
									$(item).html(prettyDate(parseInt($(this).attr('title')) * 1000));

									if ($(this).attr('title') < Math.round(new Date().getTime() / 1000 - 3600)) {									
										$(this).addClass('timeset');
									}
								});
								//Animation effects
								if (json['type'] == 'lazy' || json['type'] == 'biolazy') $('#' + tab + '_' + value['id_str']).hide().fadeIn(1500); else if (countposts < 2) {

											//Window scroll to match inserted wit
											//var itemheight = $('#' + tab + '_' + value['id_str']).height();
											//$('html, body').animate({scrollTop: parseInt(orig + itemheight)}, 2000);
//										postanimate = jQuery('html, body').animate({scrollTop:(window.pageYOffset + $('#' + tab + '_' + value['id_str']).height())}, 2000);									
										$('#' + tab + '_' + value['id_str']).hide().slideDown(2000);
										
//										$('html, body').animate({scrollTop: parseInt($('html, body').scrollTop + $('#' + tab + '_' + value['id_str']).height)}, 2000);
								}
								 
							}
						
						}
						
					});
					
//					if (type=="init") id();
					
/*					
					//Trigger Notiification HUD
					if (countposts > 0 && liveLast > 0 && $(window).scrollTop() != 0 && json['type'] != 'first') { 
						$('div.notify').slideDown(2000).delay(4000).fadeOut(1000).text(countposts + ' new post' + (countposts==1?'':'s') + ' just arrived in the Live Feed.');
					}					
*/
				
				
				}
			});
			
		}
		
