function update_event(json) {
	$event = json
//	$event = $event.event;
//current date: 10/23/09
}
(function($){
	
	$(document).ready(function() {
		
		//jquery support for iphone/ipad events
		var support = {};
		var events = [
		'touchstart',
		'touchmove',
		'touchend',
		'gesturestart',
		'gesturechange',
		'gestureend'
		];

		var el = document.createElement('div');

		for( i in events ) {
		var eventName = events[i];
		eventName = 'on' + eventName;
		var isSupported = (eventName in el);
		if (!isSupported) {
		el.setAttribute(eventName, 'return;');
		isSupported = typeof el[eventName] == 'function';
		}
		support[events[i]] = isSupported;
		}

		support.touches =
		support.touchstart
		&& support.touchend
		&& support.touchmove;

		support.gestures =
		support.gesturestart &&
		support.gesturechange &&
		support.gestureend;

		$.fn.browserTouchSupport = support;

		var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
		if (badBrowser) {
			jQuery(function(){jQuery('#home_page_wrap, #footer, div#logo_bird').pngFix( { blankgif:'ext.gif' } );});
			$("#header").append("<div style='width:500px; padding:15px; display:block; position:relative; background-color:#ffdad8; border:solid 1px #ddaa91; clear:both; display:block; position:relative; margin:20px auto 0; color:#880000;'>Looks like you're using an older version of internet explorer... our site was not designed to work with that. It is too outdated to hack our code to fit its quirks and comply with its issues. It would mean compromise on the stellar overall experience of the average user and unfortunately, we can't do that. Please upgrade! Or use <a href='http://getfirefox.com' target='_blank'>firefox</a>.</div>")
		}
		
		////////Global Variables//////
		$refreshTime = 12000;
		$callFinished = true;
		$runQueue = false;
		$runLive = false;
		$max_id = "";
		$emptyCalls = 0;
		$totalTweets = 0;
		$totalCalls = 0;
		$gateOpen = false;
		$t = "";//global timeout
		$t = ""; //global refresh time
		window.twitter = [];
		window.twitter['last_id'] = 0
		window.twitter['last_twitter_id'] = 0
		$temp_tweet_array = new Array();
		$.fn.reverse = [].reverse;

		///////footer///////
		if($('#switcharoo')[0]){
 			var emailval = $('#switcharoo').html(); 
			emailval=emailval.replace("AT",'@').replace('DOT','.');
			$('#switcharoo').html(emailval);
		}
		if($('.switcharoo')[0]){
 			var emailval = $('.switcharoo').html(); 
			emailval=emailval.replace("AT",'@').replace('DOT','.');
			$('.switcharoo').html(emailval);
		}

		//info pages
		$("#main_content.pages ul#info_nav li").click(function(){
			$(this).siblings('li').removeClass('selected').end().addClass("selected");
			var link = $(this).find('a').attr("href").replace("#","");
			$(".content_mid div.padded_container:visible").fadeOut(50);
			window.location.hash = link;
			$("#"+link).fadeIn(250);
			return false;
		});
		//footer hookup
		$("#footer_link_privacy, #footer_link_terms").click(function(){
			window.location=$(this).attr('href');
			window.location.reload(true)
		});
		$("#main_content.pages").find("#pricing .column").find('p').css("cursor","help").qtip({
			style: { width: { max: 250 }, tip: 'leftMiddle', name: 'blue', border: {	width: 1,	radius: 3, color:"#2EBBE4" } }, show: { delay: 0 }, hide: { delay: 0 }, position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' } }	
		});
		$("#main_content.pages").find("#pricing .column").find('p').mouseout(function(){
			$(".qtip").hide();
		});
		
		if($("#main_content").is('.pages')) { 
			var hash = window.location.hash; 
			if(hash != ""){ $('a[href='+hash+']').click(); } 
			if($("#home_page_wrap")[0]){
				///////
				//TODO: use the new delay() native function in the new jquery instead of timeouts.
				///////
				//if ( window.addEventListener ) {
					var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
					$(document).keydown(function(e){
					var target = e.keyCode ? e.keyCode : e.charCode
					kkeys.push( target );
					if ( kkeys.toString().indexOf( konami ) >= 0 ){
						kkeys = [];
						scroll(0,0);
						$('.clicker').animate({height:'0px'},400);
						$("<div id='crazy_bird' style='z-index:5;width:140px;height:140px;position:absolute;top:-140px;right:10px;background:url(/images/animated_bird.gif) top left no-repeat;display:block;'></div>").insertAfter("#logo_bird").animate({top:"110px"},1000);
						setTimeout("jQuery.moveFowl()", 4250)
						$("#logo_bird").animate({height:'128px', top:'-128px'},100).animate({height:'128px'},600).animate({top:'128px'}, 350)
						.animate({top:'118px'}, 35).animate({top:'128px'}, 35).animate({top:'121px'}, 25).animate({top:'121px'}, 25);
						$("#home_page_wrap h2").animate({'margin-left':'auto'},2000)
						.css({backgroundImage:'url(/images/page/fight_to_the_death.png)',backgroundPosition:'center bottom'});
						$('#img_inner_container').find('img:visible').fadeOut(300).end()
						.animate({height:'100%'},2100)
						.css({width:'784px','background-image':'url(/images/page/tmnt.gif)', backgroundPosition:'100px center', 'background-repeat':'no-repeat'});
						$.moveFowl = function(){
							jQuery('#crazy_bird').animate({right:'467px'}, 300, 'swing',
								function(){ jQuery.movebirdy(); jQuery(this).animate({right:'425px'}, 80).animate({right:'420px'}, 570).animate({top:'108px',right:'428px'}, 570).animate({top:'108px',right:'420px'}, 570).animate({top:'111px',right:'428px'}, 570).animate({top:'-40px',right:'', left:'170px'}, 270).animate({top:'-42px',right:'', left:'163px'}, 170).animate({top:'-40px', left:'172px'}, 170, function(){ jQuery.movesign();} ).animate({top:'-39px', left:'171px'}, 800).animate({top:'-139px', left:'171px'}, 100).fadeOut(); })
						}
						$.movesign = function(){
							$('h1').animate({"margin-top":'20px', "margin-left":'84px'}, 100, 'swing');
						}
						$.movebirdy = function(){
							$("#logo_bird").animate({ left:"220px"},50,'swing').animate({ left:"230px"},50)
						}
						$("#logo_bird").animate({top:"130px"},1000).animate({top:"110px", left:"30px"},100).animate({top:"130px", left:"60px"},100)
							.animate({top:"120px", left:"90px"},100).animate({top:"140px", left:"120px"},100).animate({top:"130px", left:"150px"},100)
							.animate({top:"150px", left:"180px"},100).animate({top:"140px", left:"210px"},100).animate({top:"160px", left:"240px"},100)
							.animate({top:"160px", left:"240px"},400);
					}
				 }, true);
				//}

				//now slider stuff
				var pic_count = $("#imgcontainer").find('img').length;
				var totallength = Number(pic_count * 787);
				$("#img_inner_container").width(totallength);
				$("#home_page_wrap").find('.clicker').click(function(){
					if(!$("#img_inner_container").is(":animated")){
						$img = $("#imgcontainer").find('img');
						var cur_pos = Number($("#img_inner_container").css("left").replace("px",""));
						if($(this).is("#click_right")){
							if( cur_pos >  ((totallength - 787)*(-1)) ){
								//slide right
								$("#img_inner_container").animate({left:(cur_pos-787)+"px"});
							}
							else{
								//slide left
								$("#img_inner_container").animate({left:0});
							}
						}
						else{
							if( cur_pos > -15 ){
								//slide right
								$("#img_inner_container").animate({left:(totallength - 787)*(-1)+"px"});
							}
							else{
								//slide left
								$("#img_inner_container").animate({left:(cur_pos+787)+"px"});
							}
						}
					}
					return false;
				});
			}
		}

		//////signup page/////
		$("#signup form input:not(name[authenticity_token])").each(function(){ if( $(this).val() == "" ) $(this).val($(this).attr("title")); var $text_value = $(this).val(); if ( $(this).attr("title") == $text_value ) $(this).clearonfocus(); });
		$("#signup form").submit(function(){
			if( $(this).find('input#account_email').val() == "joeshmoe@paratweet.com" ) { $(this).find('input#account_email').val(''); }
			if( $(this).find('input#account_login').val() == "emilio" ) { $(this).find('input#account_login').val(''); }
			if( $(this).find('input#account_first_name').val() == "First" ) { $(this).find('input#account_first_name').val(''); }
			if( $(this).find('input#account_last_name').val() == "Last" ) { $(this).find('input#account_last_name').val(''); }
			if( $(this).find('input#account_password').val() == "password" ) { $(this).find('input#account_password').val(''); }
		});
		$('#signup').find("#step_1.content").click(function(e){
			$this = $(e.target);
			if( $(e.target).parents().is('.column:not(.disabled_column)') ){
				$('.column').removeClass('selected');
				//$("#intro_offer").removeClass('selected');
				$this.parents('.column').addClass("selected").next('input[type=radio]').click();
				return false;
			}
			if( $(e.target).is('.column:not(.disabled_column)') ){
				$('.column').removeClass('selected')
				//$("#intro_offer").removeClass('selected');
				$this.addClass("selected").next('input[type=radio]').click();
				return false;
			}
		});

		if($("#signup form")[0]){
			pic1= new Image(1,1); 
			pic1.src="/images/page/step_1_intro_offer_hover.png"; //preloading
			pic2= new Image(1,1); 
			pic2.src="/images/page/step_1_intro_offer_hover2.png"; //preloading
			//and then select great plan as default
			$("#great").click();
			$.fn.qtip.styles.mystyle2 = {
				//
			}
			$("#signup #step_1").find('p.tooltip').css("cursor","help").qtip({
				style: { width: { max: 250 }, tip: 'leftMiddle', name: 'blue', border: {	width: 1,	radius: 3, color:"#2EBBE4" } },  position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' } }	
			});
			$("#signup #step_1").find('p.tooltip').mouseout(function(){
				$(".qtip").hide();
			});
		}

		//////events list page//////
		$("body").find("#event_list").find("ul.events .name").qtip({
		 	style: { width: { max: 350 }, tip: 'topMiddle', name: 'dark', border: {	width: 1,	radius: 3, color:"#2EBBE4" } },  position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle' } }	
		}).end();
		$("body").find("#event_list").find("ul.events .name").find('.name_text').click(function(){
			$(this).toggle();
			$(this).siblings('form').toggle();
			$(this).parent('.name').siblings('.delete').toggle();
			return false;
		}).end()
		.find('form.edit_event').live('submit',function(){
			$this = $(this);
			var new_name = $this.find('#event_name').val();
			$.ajax({
				type: "POST",
				url: $this.attr('action'),
				data: "_method=put&authenticity_token="+ encodeURIComponent($(this).find('input[name=authenticity_token]').val()) +"&event[name]="+new_name,
				success: function(msg){
					$this.toggle();
					$this.parent().children('.name_text').html(new_name).toggle();
					$this.parents('.name').siblings('.delete').toggle();
				},
				error: function(msg){
					if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those settings did not get saved... try again. Check your internet as well.</div>').slideDown(400);
					$.hide_bar(3000);
					}
					$this.toggle();
					$this.parent().children('.name_text').toggle();
					$this.parents('.name').siblings('.delete').toggle();
				}
		 });
			return false;
		}).end().end()
		.find('.delete').bind('click',function(){
			$this = $(this).parent('li');
			var thisform = $(this).siblings('.name').find('form.edit_event');
			$.ajax({
				type: "POST",
				url: thisform.attr('action'),
				data: "_method=put&authenticity_token="+ encodeURIComponent(thisform.find('input[name=authenticity_token]').val()) +"&event[active]=false&event[access_key]=00000000",
				success: function(msg){
					$this.slideUp(200);
					if(!$("#add_event")[0])
						$("form#new_event").after('<a id="add_event" href="/events/new">Add a new event</a>');
				},
				error: function(msg){
					if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So that event didn\'t quite get deleted... try again. Check your internet as well.</div>').slideDown(400);
					$.hide_bar(3000);
					}
				}
		 });
			return false;
		}).end()
		.find('#add_event').live('click',function(){
			//put in new form
			$("#new_event").parents('li').appendTo($("ul.events")).find('form').slideDown();
			$(this).slideUp();
			return false;
		}).end()
		.find('embed, object').qtip({
			content: "<h3>Quick Note</h3><p>Right now this application is unsigned. What does that even mean?! It basically means we didn't pay the ridiculous price that adobe air certificate signers charge (yet). So when you install this app, it's going to tell you that it has an unknown publisher. Guess what - that's us. When we get an 'official' certificate, we'll let you know, and you'll need to redownload the app. Thanks!</p>",
			show: 'mouseover',
			hide: 'mouseout',
			style: { tip: 'leftBottom',	name: 'blue',	border: {	width: 3,	radius: 5, color:"#2EBBE4" } },position: { corner: { target: 'rightMiddle', tooltip: 'leftBottom' } }
		});

		//account settings page
		$("#settings").find('a.change_password').click(function(){
			$("#password_container").slideDown();
			$(this).hide();
			return false;
		})
		$('#settings').find("#plan.content").click(function(e){
			$this = $(e.target);
			if( $(e.target).parents().is('.column:not(.disabled_column)') ){
			/*$('.column').removeClass('selected');
				$("#intro_offer").removeClass('selected');
				$this.parents('.column').addClass("selected").next('input[type=radio]').click(); */
				return false;
			}
			if( $(e.target).is('.column:not(.disabled_column)') ){
				/*$('.column').removeClass('selected')
				$("#intro_offer").removeClass('selected');
				$this.addClass("selected").next('input[type=radio]').click();*/
				return false;
			}
		}).end()
		.find("#intro_offer").click(function(){
			/*$('.column').removeClass('selected');
			$(this).addClass('selected').next('input[type=radio]').click();*/
			
		});
		$('#settings').find("#payment_settings").find('#payment_history').each(function(){
			$history = $(this).find("#full_history");
			$(this).find('a').click(function(){
				$(this).slideUp(30);
				$history.slideDown(40);
				return false;
			});
		});
		if($("#settings form")[0]){
			pic1= new Image(1,1); 
			pic1.src="/images/page/step_1_intro_offer_hover.png"; //preloading
			pic2= new Image(1,1); 
			pic2.src="/images/page/step_1_intro_offer_hover2.png"; //preloading
			//and then select great plan as default
			$("#settings form").find('input:checked').prev('div').addClass("selected");
		}


		//////MODERATE PAGE//////
		if(typeof(page)!= "undefined" && page == "moderate"){
			//first setup up a click event on the single tweet
			$("#event_single_tweet:checkbox").click(function(){
				if( $(this).is(":checked") && !$("#event_dark").is(":checked") )
					$("#event_dark").attr('checked', true)
			});
			$("#event_dark").click(function(){
				if( !$("#event_dark").is(":checked") )
					$("#event_single_tweet:checkbox").attr('checked', false);
			});
			
			$tt = ( $("#unbirthed_tweets ul.unbirthed").attr("id") == "free") ? "yes" : "no";
			$base_url = $event.pending_tweets_path;
			var auth_token = "", event_terms = "", form_goto = "", termsArray = new Array();
			//onload - pull last group of live approved tweets to the live ul list
			if($event.access_key == null || $event.access_key == ""){
				$("#unbirthed_tweets ul.unbirthed, #live_tweets ul.live").attr("id","");
				$tt = "no";
				//remove the free id from events that aren't even created yet
				// - the controls need to work but won't actually send to the db
			}else{
				$.ajax({
					type: "get",
					url: "/events/"+$event.access_key+"/tweets/last_group?limit=30",
					timeout:14000,
					dataType: "json",
					success: function(json, textStatus){
						var big_array2 = new Array();
						$.each($(json),function(){
							var tmp_array = [this.id,this.profile_image_url,this.text,this.from_user, this.created_at, this.twitter_id, this.image_thumb_urls, this.image_urls];
							big_array2.push(tmp_array);
						});
						big_array2.sort();
						big_array2.reverse();
						var tweet_photos_checked = ( $("#event_tweet_photos").is(':checked') ) ? 1 : 0 ;
						$.each(big_array2, function() {
							if($('#live_tweets ul.live #tw'+this[0]).length == 0 ){
								var new_text = this[2].replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return F.charAt(0)+'<a href="http://www.twitter.com/'+F.substring(1)+'">'+F.substring(1)+"</a>"});
								var divstr = '<li id="tw'+this[0]+'"><span class="loading">Pending...</span><span class="tweet" title='+this[4]+'>'+
								'<img width="50" height=50" src="'+this[1]+'" >'+
								'<p>'+ new_text +" from <span class='user_name'>" + this[3] + "</span>" +'</p></span><span class="x"></span></li>';
								$('#live_tweets ul.live').append(divstr);
								var thumbnail;
								if(tweet_photos_checked == 1){
									thumbnail = this[6];
									if(thumbnail.length > 0){
										$('#live_tweets #tw'+this[0]).addClass("small_text").find('p').after("<img src='"+thumbnail+"' width='55' class='thumbnail' height='55' style='float: right; margin-right: 5px;'>");
									}
								}
							}
						});
						$.checkListWidth();
						var isChrome = /chrome/.test( navigator.userAgent.toLowerCase() )
						if (!isChrome && $.fn.browserTouchSupport.touches) {
							$('#live_tweets img.thumbnail').each(function(){
								var imgsrc = $(this).attr('src');
								$(this).qtip({
									content: { text: '<img src='+imgsrc+' alt="loading..." width="200" height="200">', title: { text:false } },
									style: { width: { max: 225 }, tip: 'leftMiddle', name: 'blue', border: {	width: 1,	radius: 3, color:"#2EBBE4" } }, 
									show: { solo: true, delay: 0, when: { event: 'touchstart' } },
									hide: { delay: 0, when: { event: 'touchend' } }, 
									position: { adjust: { screen: true }, corner: { 
										target: 'rightMiddle', tooltip: 'leftMiddle' 
									} }	
								});
							});
						}
						else{
							$('#live_tweets img.thumbnail').each(function(){
								var imgsrc = $(this).attr('src');
								//		 	style: { width: { max: 350 }, tip: 'topMiddle', name: 'dark', border: {	width: 1,	radius: 3, color:"#2EBBE4" } },  position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle' } }	
								$(this).qtip({
									content: { text: '<img src='+imgsrc+' alt="loading..." width="200" height="200">' },
									style: { width: { max: 225 }, tip: 'leftMiddle', name: 'blue', border: { width: 1, radius: 3, color:"#2EBBE4" } }, 
									position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' } },
									show: { when: { event: "click" }, solo: true, delay: 0 },
									hide: { delay: 1750, when: { event:'inactive' } }
								});
							});
						}
					},
					error: function(msg){
						if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup while we tried to show you what tweets are already live. This won\'t affect the live display.</div>').slideDown(400);
						$.hide_bar(6000);
					 	}
					}
				});
			}
			$.reassemble_terms = function(){
				event_terms = "";
				$('#settings_drop span.input_term').each(function(i, domEle){ event_terms += $(domEle).text() + ","; });
				event_terms=event_terms.substr(0,event_terms.length - 1);
				$("#settings_drop").find('input#event_terms').val(event_terms);
				var a1 = new Array();
				a1=event_terms.split(",");
				$.each( a1, function(i){ if(a1[i].indexOf(" ") != -1) { a1[i] = '"'+a1[i]+'"'; } });
				var joined_terms = escape(a1.join("+OR+"));
				var unescaped_terms = unescape(joined_terms);
				var urltoshow = "http://search.twitter.com/search?q="+unescaped_terms
				$("#settings_drop").find('.left:first').find(".url").remove().end().append("<a href='http://search.twitter.com/search?q="+joined_terms+"' class='url' target='_blank'>"+urltoshow+"</span>");
			}
			//javascript response time to twitter
			//$("#response_time").each(function(){
				//first go fetch twitter last public timeline tweet
				
				//then do a time comparison
				
				//then change the number in the div, and change the class to appropriate color (green, orange, red or black)
			//});
			$("#reveal_features").click(function(){
				var parent = $(this).parent();
				if( parent.is(".selected") ){
					parent.removeClass("selected")
					.find("#features")
						.animate({height:"0"}, 300, function(){ $(this).hide(); } ).end();
				}
				else{
					featureHeight = 105;
					if($("#custom_background")[0]) { featureHeight += 30; }
					if($("#tweet_photos")[0]) { featureHeight += 30; }
					parent.addClass("selected")
					.find('div#features')
						.height(0).show().animate({height:featureHeight+"px"}, 300).end();
				}
				return false;
			});
			$("#settings_drop")
			.find('form.edit_event, form.new_event').each(function(){
				auth_token = $(this).find('input[name=authenticity_token]').val();
				form_goto = $(this).attr('action');
				event_terms = $(this).find('input#event_terms').val();
				$.reassemble_terms();
			}).end()
			.find("span.input_term a").live('click',function(){
				$(this).parent('span').slideUp(function(){
					$(this).remove();
					$.reassemble_terms();
				})
			}).end();
			$("#settings_drop")
			.find('#add_term').click(function(){
				if($("form.edit_event span.input_term").length > 3 || $("form.new_event span.item_term").length > 3) return false;
				var term = $('input[name=temp_field]').val().replace(",",""); var exists = false;
				$.each( $('span.input_term'), function(i){ if( term == $(this).text() ){ exists = true; } } );
				if( term != "" && ( exists === false ) ){
					$(this).after('<span class="input_term"><a href="#"></a>'+term+'</span>');
					var current_terms = $('input#event_terms').val();
					new_terms = ( current_terms == "" ) ? term : current_terms + "," + term;
				}
				$.reassemble_terms();
				return false;
			}).end()	
			.find("input[name=temp_field]").bind("keydown", function(e) {
				if (e.keyCode == 13 || e.charCode == 13) { $("#add_term").click(); $(this).val(""); return false; }
			}).each(function(){ $(this).val($(this).attr("title")); var $text_value = $(this).val(); if ( $(this).attr("title") == $text_value ) $(this).clearonfocus(); })
			.end()
			.find('a.cancel').click(function(){
				//we need to reset all the input fields
				$("#event_question, #event_instruction, #event_terms").each(function(i){
					var tmpval = $(this).attr("title");
					$(this).val(tmpval);
				});
				var split_terms = $("#event_terms").val().split(",");
				var leng = split_terms.length, temp_html="";
				$("span.input_term").remove();
				for (i=0; i<leng; i++) { 
					if(split_terms[i]!="")
						temp_html += "<span class='input_term'><a href='#'></a>"+split_terms[i]+"</span>";
				}
				$("#add_term").after(temp_html);
				$("#settings_drop").animate({height:"0"}, 300);
				$("#settings_tab").removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
				$("#settings_tab_a").css({bottom:"-58px"})
				return false;
			});
			$('a.clear_tweets').click(function(){
				//clear/archive the db
				$.archiveTweets();
			});
			$('#settings_tab_a').click(function(){
				$this = $("#settings_tab");
				if( $this.is('.open') ){
					$(this).css({bottom:"-52px"});
					$this.animate({bottom:"0"}, 350);
					question_value = escape($('input#event_question').val());
					question_value = (question_value == "undefined") ? "" : question_value ;
					var speedval = $("select#event_speed").val();
					var profanity = ( $("#event_profanity_filter").is(':checked') ) ? 1 : 0 ;
					var single_tweet = ( $("#event_single_tweet").is(':checked') ) ? 1 : 0 ;
					var custom_background = ( $("#event_custom_background").is(':checked') ) ? 1 : 0 ;
					var tweet_photos = ( $("#event_tweet_photos").is(':checked') ) ? 1 : 0 ;
					var dark = ( $("#event_dark").is(':checked') ) ? 1 : 0 ;
					instruction_value = escape($('input#event_instruction').val());
					if(instruction_value == "undefined") { event_instruction = "" }
					if($("form.edit_event")[0]){
						$.ajax({
							type: "POST", url: form_goto, data: "_method=put&authenticity_token="+ encodeURIComponent(auth_token) +"&event[terms]="+event_terms+"&event[question]="+question_value+"&event[instruction]="+instruction_value+"&event[profanity_filter]="+profanity+"&event[speed]="+speedval+"&event[custom_background]="+custom_background+"&event[single_tweet]="+single_tweet+"&event[dark]="+dark+"&event[tweet_photos]="+tweet_photos,
							success: function(msg){
								$("#settings_drop").animate({height:"0"}, 300);
								$this.removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
								question_value = (unescape(question_value).length > 35) ? unescape(question_value).substr(0,35) + "..." : unescape(question_value);
								$("#snippet .right").html(question_value);
								$("#snippet .left").html(unescape(instruction_value));
								$("#event_question").attr("title",question_value);
								$("#event_instruction").attr("title",unescape(instruction_value));
								$("#event_terms").attr("title",event_terms)
								
							},
							error: function(msg){ if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those settings did not get saved... try again. Check your internet as well.</div>').slideDown(400); $.hide_bar(3000); } $("#settings_drop").animate({height:"0"}, 300); $this.removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
							}
					 });
					}
					else{
						$("#snippet .left").html(unescape(instruction_value));
						$("#event_instruction").attr("title",instruction_value);
						$("#event_terms").attr("title",event_terms);
						//if it's not editing an event, then it's a new event.
						//event_terms = event_terms.replace(",","+OR+")
						if(typeof($.joined_terms) != "undefined" && $.joined_terms != "" && $.joined_terms != null)
							var tempterms = $.joined_terms;
						if( $("#search_control").is(".off") ){/*donothing*/}
						else{ $("#search_control").click();}
						var a1 = new Array();
						a1=event_terms.split(",");
						$.each( a1, function(i){ if(a1[i].indexOf(" ") != -1) { a1[i] = '"'+a1[i]+'"'; } });
						$.joined_terms = escape(a1.join("+OR+"));
						if( tempterms != $.joined_terms ){ window.twitter['last_twitter_id'] = ""; }
						$.twitterURL = "http://search.twitter.com/search.json?q="+$.joined_terms+"&callback=?";

						$("#settings_drop").animate({height:"0"}, 300);
						$this.removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
					}
				}
				else{
					$('input[name=temp_field]').val("");
					$(this).css({bottom:"-36px"});
					$this.animate({bottom:"0"},150).removeClass('closed').addClass('open').animate({bottom:"-40px"}, 200);
					$("#settings_drop").animate({height:"280px"}, 250);
				}
				return false;
			}).click();

			//controls the tweets coming from twitter
			$("#search_control").click(function(e){
				if(!$(this).is(':animated')){
					if( $(this).is('.off') ){
						//turn off the search queue and reset the timer, reset the empty calls, and turn the switch off
						$runQueue = false;
						$emptyCalls = 0;
						$(this).toggleClass("off");
						clearTimeout($t2);
					}
					else{
						$runQueue = true;
						setTimeout("jQuery.pullTweets()",100);
						if($gateOpen === false)
							clearTimeout($t);
						$(this).toggleClass("off");
					}
				}
				return false;
			});
			$("#archive_pending").click(function(){
				$.archivePendingTweets();
			})

			//controls the tweets moving from pending to live
			$('#gate_control').click(function(e){
				if(!$(this).is(':animated')){
					if( $(this).is('.off') ){
						$gateOpen = false;
						$(this).toggleClass('off');
						send_approved();
					}
					else{
						$gateOpen = true;
						clearTimeout($t);
						setTimeout('jQuery.scrollingTweets();',1000);
						$(this).toggleClass('off');
					}
				}
				return false;
			});

			$('#feed_control').click(function(e){
				if(!$(this).is(':animated')){
					$this = $(this);
					if( $this.is('.pause') ){
						$runLive = false;
						if($event.access_key == null || $event.access_key == ""){
							alert("Once you have an account set up, you can test this out.")
							return false;
						}
						else{
							$.ajax({ type: "POST", url: form_goto, data: "_method=put&authenticity_token="+ encodeURIComponent($('form.edit_event').find('input[name=authenticity_token]').val()) +"&event[paused]="+true,
								success: function(msg){ $this.toggleClass("pause"); },
								error: function(msg){ if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those settings did not get saved... try again. Check your internet connection as well.</div>').slideDown(400);
									$.hide_bar(3400);
								 }
								}
						 });
						}
					}
					else{
						$runLive = true;
						if($event.access_key == null || $event.access_key == ""){
							alert("Once you have an account set up, you can test this out.")
							return false;
						}
						else{
							$.ajax({
								type: "POST", url: form_goto, data: "_method=put&authenticity_token="+ encodeURIComponent($('form.edit_event').find('input[name=authenticity_token]').val())+"&event[paused]="+false,
								success: function(msg){ $this.toggleClass("pause"); },
								error: function(msg){ if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those settings did not get saved... try again. Check your internet connection as well.</div>').slideDown(400); $.hide_bar(3400);
								 }
								}
							});
						}
					}
				}
				return false;
			});

			//general slider action
			//first set up the live! dealio
			if($('#feed_control').hasClass("pause"))
				$('#feed_control').css("background-position", "0");

			$(".slider").click(function(){
				if(!$(this).is(':animated')){
					if($(this).is(".off"))
						$(this).animate({backgroundPosition: "0"})
					else if($(this).is("#feed_control") && !$(this).is(".pause") && $event.access_key != null)
						$(this).animate({backgroundPosition: "0"})
					else
						$(this).animate({backgroundPosition: "-42px"})
				}
				return false;
			});

			////////SETTINGS PANE////////
			$('#settings')
				.find('#add_term').click(function(){
					var term = $('input[name=temp_field]').val().replace(",",""); var exists = false;
					$.each( $('.input_term'), function(i){ if( term == $(this).text() ){ exists = true; } } );
					if( term != "" && ( exists === false ) ){
						$(this).after('<span class="input_term"><a href="#"></a>'+term+'</span>');
						var current_terms = $('input[name=terms]').val();
						new_terms = ( current_terms == "" ) ? term : current_terms + "," + term;
						$('input[name=terms]').val(new_terms.replace(",,",","));
					}
					return false;
				}).end()
				.find('.input_term > a').live('click',function(){
					var delete_term = $(this).parent().text(); var terms = "";
					$.each($('input[name=terms]').val().split(","), function(i){ if(!(this == delete_term)){ terms = (terms == "") ? this : terms + "," + this; } });
					$('input[name=terms]').val(terms);
					$(this).parent().slideUp(200, function(){$(this).remove();});
					return false;
				}).end()
				.find("input[name=temp_field]").bind("keydown", function(e) {
					if (e.keyCode == 13 || e.charCode == 13) { $("#add_term").click(); $(this).val(""); return false; };
				}).each(function(){ $(this).val($(this).attr("title")); var $text_value = $(this).val(); if ( $(this).attr("title") == $text_value ) $(this).clearonfocus(); }).end();
			}
	 });
	
	$.pullTweets = function(){
		$t2 = setTimeout('jQuery.pullTweets()',$refreshTime);
		var quicklen = $('#unbirthed_tweets ul.unbirthed li').length;
		if( $runQueue === true && $callFinished === true && quicklen < 50 )
		{	
			if($event.access_key == null || $event.access_key == "")
				$.fetch_tweets($.twitterURL+"&since_id="+window.twitter['last_twitter_id']);
			else
				$.fetch_tweets($base_url + "?since_id="+window.twitter['last_id']+"&since_twitter_id="+window.twitter['last_twitter_id']); 
			
		}
	};

	/////////TWEETS////////////
	$.fetch_tweets = function(url){
		$callFinished = false;
		$totalCalls++;
		$("#unbirthed_tweets .loading").show();
		$.ajax({
			type: "get",
			url: url,
			timeout:16000,
			dataType: "json",
			success: function (json, textStatus){
				$.successfulFetch(json, textStatus);
			},
			error: function(request, errorType, errorThrown) {
				$.errorFetch(request, errorType, errorThrown);
			}
		});
	};
	
	$.concat_collection = function(obj1, obj2) {
		var i; var arr  = new Array(); var len1 = obj1.length; var len2 = obj2.length; for (i=0; i<len1; i++) {arr.push(obj1[i]);}
		for (i=0; i<len2; i++) {arr.push(obj2[i]);}
		return arr;
	}
	//function call for tweets pulled with an error, whether from ruby on normal events or javascript for free events
	$.errorFetch = function(request, errorType, errorThrown){
		$("#unbirthed_tweets .loading").hide();
		$callFinished = true;
		try {
			error_status = request.status;
			if (errorType == 'timeout') { 
				$("#wrapper").prepend('<div id="top_message_bar">Sorry, looks like the request for the latest tweets timed out...</div>').slideDown(400); $.hide_bar(3000);
			}
			else{
				if(error_status == "503")
					$("#wrapper").prepend('<div id="top_message_bar">Sorry, but you are over your rate limit. ('+error_status+')</div>').slideDown(400);
				else{
					if( $("#settings_drop").find('.input_term')[0] )
						$("#wrapper").prepend('<div id="top_message_bar">Sorry, there was something wrong with that request. Twitter is on the fritz. Take a break perhaps? ('+error_status+')</div>').slideDown(400); 
					else
						$("#wrapper").prepend('<div id="top_message_bar">Sorry, there was something wrong with that request. Make sure you have a search term specified (at least one). ('+error_status+')</div>').slideDown(400); 
				}
				$.hide_bar(3000);
			}
		}
		catch (e) {}
	}
	//function call for tweets pulled successfully, whether from ruby on normal events or javascript for free
	$.successfulFetch = function(json, textStatus){
		$("#unbirthed_tweets .loading").hide();
		$callFinished = true;
		var big_array = new Array();
		if($event.access_key == null || $event.access_key == ""){
			$.each($(json.results),function(){
				var timecreatedat = $.relative_time(this.created_at);
				var tmp_array = [this.id,this.profile_image_url,this.text,this.from_user, timecreatedat, this.image_thumb_urls, this.image_urls];
				big_array.push(tmp_array);
			});
		}
		else{
			$.each($(json),function(){
				var tmp_array = [this.id,this.profile_image_url,this.text,this.from_user, this.created_at, this.twitter_id,this.image_thumb_urls, this.image_urls];
				big_array.push(tmp_array);
			});
		}

		big_array.sort();
		$emptyCalls = (big_array.length == 0) ? $emptyCalls + 1 : 0 ;
		var big_array_length = big_array.length;
		var tweet_photos_checked = ( $("#event_tweet_photos").is(':checked') ) ? 1 : 0 ;
		for(i = 0; i < big_array_length; i++){
			var this_id = big_array[i][0]
			
			if($('#unbirthed_tweets #tw'+this_id).length == 0 ){
				var new_text = big_array[i][2].replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return F.charAt(0)+'<a href="http://www.twitter.com/'+F.substring(1)+'">'+F.substring(1)+"</a>"});
				var divstr = '<li id="tw'+this_id+'"><span class="loading"></span><span class="tweet" title="'+big_array[i][4]+'">'+
				'<img width="50" height=50" src="'+big_array[i][1]+'" >'+
				'<p>'+ new_text +" from <span class='user_name'>" + big_array[i][3] + "</span>" +'</p></span><span class="x" title="Manually Reject"></span><span class="check" title="Manually Approve">+</span></li>';
				if(window.twitter['last_id'] < this_id){
					window.twitter['last_id'] = this_id;//store last id pulled
					window.twitter['last_twitter_id'] = ($event.access_key == null || $event.access_key == "")? this_id : big_array[i][5]; //and now also store the twitter id
				}
				$('#unbirthed_tweets ul.unbirthed').append(divstr);
				var thumbnail;
				if(tweet_photos_checked == 1){
					thumbnail = ($event.access_key == null || $event.access_key == "")? big_array[i][5] : big_array[i][6];
					if(thumbnail.length > 0){
						$('#unbirthed_tweets #tw'+this_id).addClass("small_text").find('p').after("<img src='"+thumbnail+"' width='55' class='thumbnail' height='55' style='float: right; margin-right: 5px;'>");
					}
				}
				$totalTweets++;
			}
		}
		var isChrome = /chrome/.test( navigator.userAgent.toLowerCase() )
		if (!isChrome && $.fn.browserTouchSupport.touches) {
			$('#unbirthed_tweets img.thumbnail').each(function(){
				var imgsrc = $(this).attr('src');
				$(this).qtip({
					content: { text: '<img src='+imgsrc+' alt="loading..." width="200" height="200">', title: { text:false } },
					style: { width: { max: 225 }, tip: 'leftMiddle', name: 'blue', border: {	width: 1,	radius: 3, color:"#2EBBE4" } }, 
					show: { solo: true, delay: 0, when: { event: 'touchstart' } },
					hide: { delay: 0, when: { event: 'touchend' } }, 
					position: { adjust: { screen: true }, corner: { 
						target: 'rightMiddle', tooltip: 'leftMiddle' 
					} }	
				});
			});
		}
		else{
			$('#unbirthed_tweets img.thumbnail').each(function(){
				var imgsrc = $(this).attr('src');
				$(this).qtip({
					content: { text: '<img src='+imgsrc+' alt="loading..." width="200" height="200">', title: { text:false } },
					style: { width: { max: 225 }, tip: 'leftMiddle', name: 'blue', border: { width: 1, radius: 3, color:"#2EBBE4" } }, 
					position: { corner: { target: 'rightMiddle', tooltip: 'leftMiddle' } },
					show: { when: { event: "click" }, solo: true, delay: 0 },
					hide: { delay: 1750, when: { event:'inactive' } }
				});
			});
		}
		//console.log($refreshTime);
		//calculate refresh time
		var pending_length = $('#unbirthed_tweets ul.unbirthed li').length;
		if( pending_length < 5 && $totalCalls < 4 )
			$refreshTime = 12000;
		else if( pending_length == 0 && $emptyCalls > 3)
			$refreshTime = 30000;
		else if( pending_length < 5 && $totalCalls > 3 && $totalCalls < 11 )
			$refreshTime = 20000;
		else if( pending_length < 5 && $totalCalls > 10 )
			$refreshTime = 25000;
		else if( pending_length < 15 && $totalCalls < 4 )
			$refreshTime = 15000;
		else if( pending_length < 15 && $totalCalls > 3 )
			$refreshTime = 25000;
		else $refreshTime = 35000;
		
		if($emptyCalls > 12 && pending_length == 0){
			//click on button that stops search - the following line looks deceiving but when the off class is on it, it's actually on :P
			if($("#search_control").is(".off"))
				$("#search_control").click();
			//clear empty calls
			$emptyCalls = 0;
			//clear $totalApicalls
			$totalCalls = 0;
			//reset refresh time
			$refreshTime = 12000;
			//throw up error with close button
			$("#wrapper").prepend('<div id="top_message_bar" style="background:#FFE185;">Hey we noticed that there haven\'t been any new tweets in a while... are you using the right hashtag? Are you still there? We paused the search feature for you - click it again to turn it back on.<span class="close" style="margin-left:10px; font-size:12px; text-decoration:underline;cursor:pointer;padding:3px; color:#fff; background:#2EBBE4;">Close</span></div>').slideDown(400);
			$('#top_message_bar span.close').click(function(){
				$.hide_bar(50);
				return false;
			})
		}
	}

	$.scrollingTweets = function(){
		if($gateOpen === true){
			$('#unbirthed_tweets ul.unbirthed li:first').slideUp(500,function(){ 
				$top_tweet = $(this);
				if( $top_tweet.is(".bad") ){
					$top_tweet = $top_tweet.next('li:not(".bad")'); $(this).remove();
				}
				var id_num = $top_tweet.attr("id");
				$temp_tweet_array.push(id_num);
				id_num = id_num.replace("tw","")
				if( $temp_tweet_array.length < 3 && $('#unbirthed_tweets ul.unbirthed li').length > 0 )
				{
					$top_tweet.addClass('pending_tweet').prependTo('#live_tweets ul.live').slideDown(150);
				}	
				else{
					send_approved(id_num);
				}
			});
			if ( $('#unbirthed_tweets ul.unbirthed li').length < 1 ){ if ( $('#live_tweets ul.live').find("li.pending_tweet")[0] ){ send_approved(); } }
		}
		$t = setTimeout('jQuery.scrollingTweets()',2950);
		if( $('#live_tweets ul.live li').length > 25 ){
			$('#live_tweets ul.live li:last').remove();
		}
		$.checkListWidth();
	};
	
	function send_approved(id_num){
		if(typeof(id_num) != "undefined"){
			$max_id = id_num.replace('tw','');
			if( typeof($top_tweet) != "undefined" && $top_tweet[0] ){
				$top_tweet.addClass('pending_tweet').prependTo('#live_tweets ul.live').slideDown(150);
			}
		}
		var ids_to_send = "";
		$.checkDupes();
		var length = $temp_tweet_array.length;
		for(i=0; i<length; i++) { ids_to_send += $temp_tweet_array.pop() + ","; }
		ids_to_send = ids_to_send.substr(0,ids_to_send.length - 1);
		ids_to_send = ids_to_send.replace(/tw/ig,"");
		if(ids_to_send != ""){
			if($event.access_key == null || $event.access_key == ""){
				temp = ids_to_send.split(",");
				ids_to_send="";
				$.each(temp,function(i, n){
					$('#live_tweets ul.live').find('li#tw'+n).removeClass("pending_tweet");
				});
			}
			else{
				$.post($event.url+"/approve/?ids="+ids_to_send, function(data){ 
					temp = ids_to_send.split(",");
					ids_to_send="";
					$.each(temp,function(i, n){
						$('#live_tweets ul.live').find('li#tw'+n).removeClass("pending_tweet");
					});
				});
			}
		}
		$temp_tweet_array = [];
	}
	
	$.checkListWidth = function(){
		if( $("#live_tweets li").length > 17 )
			{ $('#live_tweets ul.live').css({"margin-right":"-15px"}); $("#live_tweets").width("473px") }
		else
			{ $('#live_tweets ul.live').css({'margin-right':'0'}); $("#live_tweets").width("458px") }
	}
	
	$.checkDupes = function(id_num){
		var id_array = $temp_tweet_array;
		if(id_num != ""){
			//if id_num is sent in, then it was just rejected, or manually approved, or a concat string was sent in
			$.each(id_array,function(i){
				if( id_array[i] == id_num )
					$temp_tweet_array.splice(i,1);
			})
		}
		else{
			//else we're just checking to make sure there are no duplicates anywhere
		}
	}

	$.archiveTweets = function(){
		if(confirm("This is going to clear and archive the database tweets pulled in previous to this point in time. Good times to do this would be when you change the question that the audience is addressing.")){
			if($event.access_key == null || $event.access_key == ""){
				$("#wrapper").prepend('<div id="top_message_bar">Cleared!</div>').slideDown(400);
				$.hide_bar(3000);
				//first do it to the unbirthed tweets, and once that's done, then the live tweets. order is important here.
				$("#unbirthed_tweets").find('.control').each(function(){
					if($(this).is(".pause")) $(this).click();
					//just in case
					$runQueue = false;
					$gateOpen = false;
				}).end()
				.find('ul').slideUp().html("").slideDown().end();
				$("#live_tweets").find('.control').each(function(){
					if($(this).is(".pause")) $(this).click();
					//just in case - double send ajax post too? idk
					$runLive = false;
				}).end()
				.find('ul').slideUp().html("").slideDown().end();
				$("#settings_tab_a").css({bottom:"-52px"});
				$("#settings_tab").animate({bottom:"0"}, 350);
				$("#settings_drop").animate({height:"0"}, 300);
				$("#settings_tab").removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
				$emptyCalls = 0;
				//clear $totalApicalls
				$totalCalls = 0;
				//reset refresh time
				$refreshTime = 12000;
			}
			else{
				$.ajax({
					type: "POST",
					url: $event.url+"/archive",
					success: function(msg){
						$("#wrapper").prepend('<div id="top_message_bar">Cleared!</div>').slideDown(400);
						$.hide_bar(3000);
						//first do it to the unbirthed tweets, and once that's done, then the live tweets. order is important here.
						$("#unbirthed_tweets").find('.control').each(function(){
							if($(this).is(".pause")) $(this).click();
							//just in case
							$runQueue = false;
							$gateOpen = false;
						}).end()
						.find('ul').slideUp().html("").slideDown().end();
						$("#live_tweets").find('.control').each(function(){
							if($(this).is(".pause")) $(this).click();
							//just in case - double send ajax post too? idk
							$runLive = false;
						}).end()
						.find('ul').slideUp().html("").slideDown().end();
						$("#settings_tab_a").css({bottom:"-52px"});
						$("#settings_tab").animate({bottom:"0"}, 350);
						$("#settings_drop").animate({height:"0"}, 300);
						$("#settings_tab").removeClass('open').addClass('closed').animate({bottom:"-60px"}, 200);
						$emptyCalls = 0;
						//clear $totalApicalls
						$totalCalls = 0;
						//reset refresh time
						$refreshTime = 12000;
					},
					error: function(msg){
						if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those tweets weren\'t quite archived... try again. Check your internet as well.</div>').slideDown(400);
							$.hide_bar(3000);
						}
					}
				});
			}
		}
		return false;
	}
	
	$.archivePendingTweets = function(){
		if(confirm("This is going to clear out the pending tweets. Good times to do this would be when you change the question and/or answer that the audience is addressing.")){
			if($event.access_key == null || $event.access_key == ""){
				$("#wrapper").prepend('<div id="top_message_bar">Pending Tweets Cleared!</div>').slideDown(400);
				$.hide_bar(3000);
				//first do it to the unbirthed tweets, and once that's done, then the live tweets. order is important here.
				$("#unbirthed_tweets").find('.control').each(function(){
					if($(this).is(".pause")) $(this).click();
					//just in case
					$runQueue = false;
					$gateOpen = false;
				}).end()
				.find('ul').slideUp().html("").slideDown().end();
				$emptyCalls = 0;
				$totalCalls = 0;
				$refreshTime = 12000;
			}
			else{
				$.ajax({
					type: "POST",
					url: $event.url+"/archive?pending=1",
					success: function(msg){
						$("#wrapper").prepend('<div id="top_message_bar">Cleared Pending Tweets!</div>').slideDown(400);
						$.hide_bar(3000);
						$("#unbirthed_tweets").find('.control').each(function(){
							if($(this).is(".pause")) $(this).click();
							//just in case
							$runQueue = false;
							$gateOpen = false;
						}).end()
						.find('ul').slideUp().html("").slideDown().end();
						$emptyCalls = 0;
						$totalCalls = 0;
						$refreshTime = 12000;
					},
					error: function(msg){
						if( msg.status == 0 ){ $("#wrapper").prepend('<div id="top_message_bar">Unfortunately, the server had a small hiccup. Ya know, spicy food and all. So those tweets weren\'t quite removed... try again. Check your internet as well.</div>').slideDown(400);
							$.hide_bar(3000);
						}
					}
				});
			}
		}
		return false;
	}
	
	$.approveTweet = function(e){
		if($tt == "no"){
			if ( $(e.target).is('span.check') ){
				$this = $(e.target);
				$this_li_id=$this.parent('li').attr('id');
				var id_num = $this_li_id.replace('tw','');
				if($event.access_key == null || $event.access_key == ""){
					if($this.parent('li').is('.pending_tweet'))
						$this.parent('li').removeClass("pending_tweet");
					else{
						setTimeout('jQuery("#unbirthed_tweets").find("li#tw'+id_num+'").slideUp(100, function(){ jQuery(this).prependTo("#live_tweets ul.live").find("span.check").remove().end().slideDown(400); })',300);
					}
				}
				else{
					$.post($event.url+"/"+id_num+"/approve", function(data){
						if($this.parent('li').is('.pending_tweet'))
							$this.parent('li').removeClass("pending_tweet");
						else
						 setTimeout('jQuery("#unbirthed_tweets").find("li#tw'+id_num+'").slideUp(100, function(){ jQuery(this).prependTo("#live_tweets ul.live").find("span.check").remove().end().slideDown(400); })',300); 
					});
				}
				return false;
				$.checkListWidth();
			}
		}
	}

	$.rejectTweets = function(e){
		if($tt == "no"){
			if ( $(e.target).is('span.x') ){
				$this = $(e.target);
				live = ( $this.parents('ul').is('.live') ) ? true : false;
				$this_li_id=$this.parent('li').attr('id');
				var id_num = $this_li_id.replace('tw','');
				$this.parent('li').addClass('bad');
				if($event.access_key == null || $event.access_key == ""){ /* do nothing */ }
				else{
					$.post($event.url+"/"+id_num+"/reject", function(data){ 
					//do nothing
					});
				}
				if(live === true){
					setTimeout('jQuery("#live_tweets").find("li#tw'+id_num+'").slideUp(100, function(){ jQuery(this).remove();	jQuery.checkListWidth(); })',300);
				}
				else{
					setTimeout('jQuery("#unbirthed_tweets").find("li#tw'+id_num+'").slideUp(100, function(){ jQuery(this).remove(); })',300);
				}
				$.checkDupes($this_li_id);
				$.checkListWidth();
				return false;
			}
		}
	}
	
	//function to show the difference b/w the time that twitter 
	//returns for the tweet and now... - aka, relative time.
	$.relative_time = function(C){
		//dateformat: 2009-03-28T21:34:24Z
		var B=C.split(" ");
		C=B[1]+" "+B[2]+", "+B[4]+" "+B[3];
		var A=Date.parse(C);
		var D=(arguments.length>1)?arguments[1]:new Date();
		var E=parseInt((D.getTime()-A)/1000);
		E=E+(D.getTimezoneOffset()*60);
		if(E<60){return"less than a minute ago"}else{if(E<120){return"about a minute ago"}else{if(E<(60*60)){return(parseInt(E/60)).toString()+" minutes ago"}else{if(E<(120*60)){return"about an hour ago"}else{if(E<(24*60*60)){return"about "+(parseInt(E/3600)).toString()+" hours ago"}else{if(E<(48*60*60)){return"1 day ago"}else{return(parseInt(E/86400)).toString()+" days ago"}}}}}}
	};

	$.hide_bar = function(seconds){
		setTimeout('jQuery("#top_message_bar").slideUp(500, function(){ jQuery(this).remove(); })', seconds);
	}
		
	jQuery.fn.clearonfocus = function() {
		return this
			.bind('focus', function() {
				if ( !this.defaultValue ) this.defaultValue = this.value;
				if ( this.defaultValue && this.defaultValue != this.value ) return;
				this.value = '';
			})
			.bind('blur', function() {
				if ( this.value.match(/^\s*$/) )
					this.value = this.defaultValue;
			});
	};
	

})( jQuery.noConflict() );
