var hideSpeed = 'fast';
var showSpeed = 'normal';

var linkClicked = false;
var slideIntervalID = 0;
var OAuthAccountsFilter = "";

/*--- Character Counters ---*/
// For tweeting
function updateCharacterCounter()
{
	var charsTyped = $('#statusbox').val().length;
	var charsLeft = 140 - charsTyped;
	var charsLeftString = charsLeft.toString();
	
	// Update counter
	var counter = $('#status-field-char-counter');
	counter.html(charsLeftString);
	
	if(charsLeft >= 20)
		counter.css({color: "#CCCCCC"});
	else if(charsLeft < 20 && charsLeft >= 10)
		counter.css({color: "#5C0002"});
	else
		counter.css({color: "#D40D12"});
	
	// Save button enabled or disabled?
	if(charsTyped > 0 && charsTyped <= 140)
	{
		$('.update-submit').removeAttr("disabled");
		$('.update-submit').removeClass("disabled");
	}
	else
	{
		$('.update-submit').attr("disabled", true);
		$('.update-submit').addClass("disabled");
	}
}

// for short descriptions
function updateDescriptionCounter(ht)
{
	if(ht) // home page
	{
		var charsTyped = $('#short_description-'+ht).val().length;
		var charsLeft = 140 - charsTyped;
		var charsLeftString = charsLeft.toString();
		
		// Update counter
		var counter = $('#tcount-'+ht);
		counter.html(charsLeftString);
		
		if(charsLeft >= 20)
			counter.css({color: "#CCCCCC"});
		else if(charsLeft < 20 && charsLeft >= 10)
			counter.css({color: "#5C0002"});
		else
			counter.css({color: "#D40D12"});
		
		// Save button enabled or disabled?
		if(charsTyped > 0 && charsTyped <= 140)
		{
			$('#desc_submit-'+ht).removeAttr("disabled");
			$('#desc_submit-'+ht).removeClass("disabled");
		}
		else
		{
			$('#desc_submit-'+ht).attr("disabled", true);
			$('#desc_submit-'+ht).addClass("disabled");
		}
	}
	else // article page
	{
		var charsTyped = $('#short_description').val().length;
		var charsLeft = 140 - charsTyped;
		var charsLeftString = charsLeft.toString();
		
		// Update counter
		var counter = $('#tcount');
		counter.html(charsLeftString);
		
		if(charsLeft >= 20)
			counter.css({color: "#CCCCCC"});
		else if(charsLeft < 20 && charsLeft >= 10)
			counter.css({color: "#5C0002"});
		else
			counter.css({color: "#D40D12"});
		
		// Save button enabled or disabled?
		if(charsTyped > 0 && charsTyped <= 140)
		{
			$('.description_submit').removeAttr("disabled");
			$('.description_submit').removeClass("disabled");
		}
		else
		{
			$('.description_submit').attr("disabled", true)
			$('.description_submit').addClass("disabled");
		}
		
		// shrink button enabled or disabled?
		if(charsTyped > 140)
		{
			$('.description_shrink').removeAttr("disabled");
			$('.description_shrink').removeClass("disabled");
		}
		else
		{
			$('.description_shrink').attr("disabled", true)
			$('.description_shrink').addClass("disabled");
		}
	}
}

/*--- Description editing ---*/
function editDescription(ht)
{
	if(ht) // home page
	{
		// Hide all the other divs first
		var vh = document.getElementById("visibleHashes");
		var hashes = vh.value.split("|");
		for(var i = 0; i < hashes.length; i++)
		{
			$('#description-edit-'+hashes[i]).hide(hideSpeed);
			$('#short-description-'+hashes[i]).show();
		}
		
		$('#cancel-'+ht).show();
		
		$('#short-description-'+ht).hide();
		$('#description-edit-'+ht).show(showSpeed);
		
		$('#short_description-'+ht).focus();
		
		if( $('#desc_new-'+ht).val() == "1" )
			$('#short_description-'+ht).val("");
	}
	else // article page
	{
		/*
		// Swap divs
		$('#short-description').hide();
		$('#description-edit').show(showSpeed);
		*/
		$('#short-description').slideUp(500);
		$('#description-edit').slideDown(500);
		
		if( $('#desc_new').val() == "1" )
			$('#short_description').val("");
		else
		{
			var currentHTML = $('#sd').html().replace(/^\s+|\s+$/g, "");
			$('#short_description').val( currentHTML.replace(/<a[^>]+>([^<]+)<\/a>/g, "$1") );
		}
		
		$('#short_description').focus();
	}
}

function editHomeDescription(ht)
{
	if(linkClicked)
		return;
	
	// Hide all the other divs first
	var vh = document.getElementById("visibleHashes");
	var hashes = vh.value.split("|");
	for(var i = 0; i < hashes.length; i++)
	{
		$('#description-wrapper-'+hashes[i]).animate( { scrollTop: 0}, 250 );
		$('#cancel-'+hashes[i]).hide();
	}
	
	$('#description-wrapper-'+ht).animate( { scrollTop: 100}, 750 );
	
	$('#cancel-'+ht).fadeIn(750);
	
	$('#short_description-'+ht).focus();
	
	if( $('#desc_new-'+ht).val() == "1" )
		$('#short_description-'+ht).val("");
}

function submitDescription(ht)
{
	if(ht) // home page
	{
		var new_description = $('#short_description-'+ht).val();
		
		// Send it off to the ether
		$.post("/ajax/saveDescription.php", { page_title: ht, desc: new_description, user: wgUserName }, 
			function(returnValue)
			{
				if(returnValue == "true")
				{
					// Swap the elements
					$('#description-edit-'+ht).hide(hideSpeed);
					$('#short-description-'+ht).show(showSpeed);
					
					// Set the description to what was just saved
					$('#sd-'+ht).html(new_description);
					$('#desc_new-'+ht).val("0");
					
					// Linkify
					linkifyDescriptions();
				}
				else
				{
					alert("We were unable to process your request. Please try again later.");
				}
			}
		);

	}
	else
	{
		var new_description = $('#short_description').val();
		var pt = $('#page_title').val();
		
		// Send it off to the ether
		$.post("/ajax/saveDescription.php", { page_title: pt, desc: new_description, user: wgUserName }, 
			function(returnValue)
			{
				if(returnValue == "true")
				{
					// Swap the elements
					$('#description-edit').hide(hideSpeed);
					$('#short-description').show(showSpeed);
					
					// Set the description to what was just saved
					$('#sd').html(new_description);
					$('#desc_new').val("0");
					
					// Linkify
					linkifyDescriptions();
				}
				else
				{
					alert("We were unable to process your request. Please try again later.");
				}
			}
		);
	}
}

function submitHomeDescription(ht)
{
	if(ht) // home page
	{
		var new_description = $('#short_description-'+ht).val();
		
		// Send it off to the ether
		$.post("/ajax/saveDescription.php", { page_title: ht, desc: new_description, user: wgUserName }, 
			function(returnValue)
			{
				if(returnValue == "true")
				{
					// Swap the elements
					$('#description-wrapper-'+ht).animate( { scrollTop: 0}, 500 );
					$('#cancel-'+ht).fadeOut(500);
					
					// Set the description to what was just saved
					$('#sd-'+ht).html(new_description);
					$('#desc_new-'+ht).val("0");
					
					// remove the orange border, if it exists
					$('#sd-'+ht+'-wrapper').removeAttr("class");
					
					// Linkify
					linkifyDescriptions();
				}
				else
				{
					alert("We were unable to process your request. Please try again later.");
				}
			}
		);

	}
	else
	{
		var new_description = $('#short_description').val();
		var pt = $('#page_title').val();
		
		// Send it off to the ether
		$.post("/ajax/saveDescription.php", { page_title: pt, desc: new_description, user: wgUserName }, 
			function(returnValue)
			{
				if(returnValue == "true")
				{
					// Swap the elements
					$('#description-edit').hide(hideSpeed);
					$('#short-description').show(showSpeed);
					
					// Set the description to what was just saved
					$('#sd').html(new_description);
					$('#desc_new').val("0");
					
					// Linkify
					linkifyDescriptions();
				}
				else
				{
					alert("We were unable to process your request. Please try again later.");
				}
			}
		);
	}
}

function cancelDescriptionSubmit(ht)
{
	if(ht) // Home page
	{
		// Swap elements
		$('#description-edit-'+ht).hide(hideSpeed);
		$('#short-description-'+ht).show(showSpeed);
	
		// Reset anything they may have typed into the text area
		$('#short_description-'+ht).val( $.trim( $('#sd-'+ht).html() ) );
	}
	else // article page
	{
		/*
		// Swap elements
		$('#description-edit').hide(hideSpeed);
		$('#short-description').show(showSpeed);
		*/
		$('#description-edit').slideUp(500);
		$('#short-description').slideDown(500);
	
		// Reset anything they may have typed into the text area
		$('#short_description').val( $.trim( $('#sd').html() ) );
	}
}

function cancelHomeDescriptionSubmit(ht){
	// Swap elements
	$('#description-wrapper-' + ht).animate( {scrollTop: 0}, 500);
	$('#cancel-' + ht).fadeOut(500);
	
	// Reset anything they may have typed into the text area
	$('#short_description-' + ht).val($.trim($('#sd-' + ht).html()));
}

function tweetShrink()
{
	var text = $('#short_description').val();
	$('#shrink-prev').val(text);
	$.get("/ajax/utils.php?action=shrink&text="+text, 
		function(shortText)
		{
			$('#short_description').val(shortText);
			updateDescriptionCounter();
		}
	);
}

/*--- OAuth Functions ---*/
function submitOAuthUpdate()
{
	var status_text = $('#statusbox').val();
	var userKeyArray = new Array();
	
	// ensure a checkbox is selected
	var cbs = $('#oauth-accounts input').each(function(){
		if (this.checked) 
			userKeyArray.push(this.value);
	});
	
	if(userKeyArray.length == 0)
	{
		alert("Please select an account");
		return;
	}
	
	var userKeys = "";
	for(var i=0; i < userKeyArray.length; i++)
	{
		if(i == 0)
			userKeys += userKeyArray[i];
		else
			userKeys += "|" + userKeyArray[i];
	}
	
	// Send it off to the ether
	$.post("/ajax/oauthActions.php?action=submit", { status: status_text, uids: userKeys},
		function(returnValue)
		{
			if(returnValue == "success")
			{
				// populate the message
				displayMessage("Message posted!");
				
				// Clear out the status box for everything but the hashtag
				$('#statusbox').val( "#"+wgTitle.toLowerCase() );
				
				// update the character counter
				updateCharacterCounter();
			}
			else
			{
				displayError(returnValue);
			}
		}
	);
}

function deleteOAuthAccount(username, user_key)
{
	var confirmation = confirm("Really delete @"+username+"?");
	if(confirmation)
	{
		$.get("/ajax/oauthActions.php?action=delete&user_key=" + user_key,
			function(returnValue)
			{
				if(returnValue == "success")
				{
					// populate the message
					displayMessage("Account deleted!");
					
					// remove the row
					$('#oauth-' + user_key).fadeOut();
					$('#oauth-' + user_key).remove();
				}
				else
				{
					displayError(returnValue);
				}
			});
	}
}

/*--- Data Manipulation ---*/
function createPage(pageTitle)
{
	$.post("/ajax/quicksubmit.php", { title: pageTitle, user: wgUserName } );
}

function linkifyDescriptions()
{
	var sds = $(".sd");
	for (var i = 0; i < sds.length; i++)
	{
		// get the current HTML
		var currentHTML = $('#' + sds[i].id).html();
		
		// Remove all hyperlinks
		var newHTML = currentHTML.replace(/<a[^>]+>([^<]+)<\/a>/g, "$1");
		
		// hyperlink links
		newHTML = newHTML.replace(/([A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+)/g, '<a href="$1" onclick="linkClicked=true;">$1</a>');
		
		// hyperlink hashtags
		newHTML = newHTML.replace(/#+([_A-Za-z0-9-]+)/ig, '#<a href="http://wthashtag.com/$1" onclick="linkClicked=true;">$1</a>');
		
		// hyperlink @names
		newHTML = newHTML.replace(/@+([_A-Za-z0-9-]+)/ig, '@<a href="http://twitter.com/$1" onclick="linkClicked=true;">$1</a>');
		
		// stick it in
		$('#' + sds[i].id).html(newHTML);
	}
}

/*--- Article page data functions ---*/
function loadData()
{
	// Build out the chart
	var chart = new FusionCharts("/skins/WTHv4/charts/FCF_Column2D.swf", "chart1Id", "400", "300");
	chart.setDataURL("/cache/"+wgPageName+"/data.xml");
	chart.render("chartcontainer");
	
	$('#stats').load("/ajax/tagStats.php?tag="+wgPageName);
	$('#panel-1').show();
	
	$('#contrib-loading').hide();
	$('#stats').fadeIn(1000);
}

function generateChartPreview()
{
	return;
	var hashtag = $('#chartHashtag').val();
	$('#chartPreview').html('<img src="images/loading-circle-big.gif" />');
	
	// load data
	$.ajax({
		type: "GET",
		url: "/bots/cacheTweets.php?preview=1&hashtag=%23"+hashtag,
		success: function(d)
		{
			var chart = new FusionCharts("/skins/WTHv4/fusioncharts/FCF_Column2D.swf", "chart1Id", "400", "300");
			chart.setDataURL("/cache/"+hashtag+"/data.xml");
			chart.render("chartPreview");
			
			$('#chartEmbedCode').show();
			$('#chartEmbedCode').html('&lt;iframe src="http://api.wthashtag.com/chart/'+hashtag+'" height="350" width="500" style="border: none"&gt;&lt;/iframe&gt;');
		}
	});
}

function showStatsPanel(panelNum)
{
	var panelHeight = 300;
	var targetOffset = (panelNum - 1) * panelHeight;
	$('#stats').animate( { scrollTop: targetOffset}, 750 );
}

function showTDPanel(panelRel)
{
	var visiblePanel = Number( $('#visibleTDPanel').val() );
	var numberOfPanels = Number( $('#tdPanelCount').val() );
	var requestedPanel = visiblePanel + Number(panelRel);
	
	if(requestedPanel > 0 && requestedPanel <= numberOfPanels)
	{
		var panelHeight = 135;
		var targetOffset = (requestedPanel - 1) * panelHeight;
		
		$('#twitter-descriptions').animate( { scrollTop: targetOffset }, 750 );
	
		$('#visibleTDPanel').val(requestedPanel);
		
		if(requestedPanel == 1)
			$('#tdp-prev').attr("class", "tdp-prev disabled");
		else
			$('#tdp-prev').attr("class", "tdp-prev");
		
		if(requestedPanel == numberOfPanels)
			$('#tdp-next').attr("class", "tdp-next disabled");
		else
			$('#tdp-next').attr("class", "tdp-next");
	}
}

function showParticipationPanel(panel)
{
	var caID = $('#participate-actions .active').attr('id');
	if(caID == "participate-"+panel)
		return false;
		
	var prev = caID.replace("participate-", "");
	
	$('#participate-actions .active').removeClass('active');
	$('#participate-'+panel).addClass('active');
	
	$('#participate-wrapper .'+prev).slideUp(500);
	$('#participate-wrapper .'+panel).slideDown(500);
}

function transcriptSelector(disp)
{
	if(disp == "block")
	{
		$('#tweetbox').hide(hideSpeed); // Hide conversation selector
		$('#transcript-options').show(showSpeed); // Show tweetbox
	}
	else
		$('#transcript-options').hide(hideSpeed);
}

function conversationSelector(disp)
{
	if(disp == "block")
	{
		// Hide transcript selector
		$('#transcript-options').hide(hideSpeed);
		
		// Show tweetbox
		$('#tweetbox').show(showSpeed);
		$('#statusbox').focus();
	}
	else
		$('#tweetbox').hide(hideSpeed);
}

/*--- Home page functions ---*/
function slideSwitch()
{
	var $active = $('#how-it-works .active');
	if($active.length == 0 )
		$active = $('#slideshow div:first');
	
	var $next =  $active.next().length ? $active.next() : $('#how-it-works div:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function() {
			$active.removeClass('active last-active');
		});
}

function slideShift(inc)
{
	if (inc == 1)
	{
		slideSwitch();
		clearInterval(slideIntervalID);
		slideIntervalID = setInterval("slideSwitch()", 8000);
	}
	else
	{
		var $active = $('#how-it-works .active');
		if($active.length == 0 )
			$active = $('#slideshow div:first');
		
		var $next =  $active.prev().length ? $active.prev() : $('#how-it-works div:last');
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
				$active.removeClass('active last-active');
			});
		
		clearInterval(slideIntervalID);
		slideIntervalID = setInterval("slideSwitch()", 8000);
	}
}

function showTagCloud(hour)
{
	// remove active class
	var activeLink = $('#taglinks .active');
	var activeID = activeLink.attr('id').replace("tcl", "tcd");
	var activePanel = $('#'+activeID);
	activeLink.removeClass('active');
	activePanel.removeClass('active');
	
	var newPanel = $('#tcd-'+hour);
	if($('#tcd-'+hour+' img'))
		newPanel.load("http://wthashtag.com/ajax/displayMostUsed.php?timeframe="+hour+"&display=cloud");
	
	$('#tcl-'+hour).addClass('active');
	newPanel.addClass('active');
}

/*--- Misc ---*/
function cleanseSearch()
{
	var searchInput = $('#searchInput').val().replace("#", "");
	searchInput = searchInput.toLowerCase();
	$('#searchInput').val( searchInput );
}

function getMostUsedTags()
{
	$('#last24').load("http://wthashtag.com/ajax/displayMostUsed.php?timeframe=24&display=list");
	$('#last72').load("http://wthashtag.com/ajax/displayMostUsed.php?timeframe=72&display=list");
	$('#last168').load("http://wthashtag.com/ajax/displayMostUsed.php?timeframe=168&display=list");
}

function shortenURL()
{
	var apiURL = "";
	var service = $('#shortener').val();
	var longURL = $('#longurl').val();
	
	if(longURL == "" || longURL == "Shorten a link")
		return;
	
	if(service == "")
	{
		displayError("Unsupported Shortening service");
		return;
	}
	
	$.get("/ajax/utils.php", { 'action': 'shorten', 'service': service, 'longURL': longURL },
		function(shortURL)
		{
			if(shortURL == "error")
			{
				displayError("An error occurred while shortening that URL", 2000);
			}
			else
			{
				var tweetText = $('#statusbox').val();
				var newText = tweetText;
				
				// add a space only if the last character isn't a space
				if(tweetText.substring(tweetText.length - 1) != " ")
					newText += " ";
				
				newText += shortURL;
				
				$('#statusbox').val(newText);
				$('#longurl').val("");
				
				displayMessage("URL shortened", 2000);
			}
		}
	);
}

function displayError(error, timeout)
{
	if(!timeout)
		timeout = 3000;
	
	$('#tweet-above .error').html(error);
	$('#tweet-above .error').fadeIn(750);
	setTimeout("fo($('#tweet-above .error'));", timeout);
}

function displayMessage(message, timeout)
{
	if(!timeout)
		timeout = 3000;
		
	$('#tweet-above .message').html(message);
	$('#tweet-above .message').fadeIn(750);
	setTimeout("fo($('#tweet-above .message'));", timeout);
}

function fo(el)
{
	$(el).fadeOut();
}


function twitterAction(text, id)
{
	pauseStream();
	$('#statusbox').val(text);
	/*
	if(id)
	{
		$('#in_reply_to_status_id').val(id);
		$('#replyto').val("Replying to "+text.replace("@",""));
		$('#replyto').show();
	}
	*/
	
	updateCharacterCounter();
	$('#statusbox').focus();
}

function streamFilter(filter)
{
	var query = $('#tweets').attr('title');
	
	if(filter == "keywords")
	{
		var keywords = prompt("Please enter the keywords you want to filter out.\nIf multiple words, separate them with a space.", "");
		
		var keywordList = keywords.split(" ");
		var keywordFilter = "";
		for(var i = 0; i < keywordList.length; i++)
		{
			keywordFilter += " -"+keywordList[i];
		}
		
		$('#filter-keywords').attr('title', "Filtering: " + keywordFilter);
	}
	
	var filters = {
		'replies': " "+OAuthAccountsFilter,
		'keywords': " "+keywordFilter,
		'links': " filter:links",
		'retweets': " -RT",
		'images': " twitpic.com OR yfrog.com"
	}
	
	if(filter == "keywords")
	{
		if(keywordFilter == "")
		{
			$('#filter-'+filter).removeClass('active');
			$('#tweets').attr('title', query.replace(filters[filter], "") );
		}
		else
		{
			if($('#filter-'+filter).attr('class') != "active")
				$('#filter-'+filter).addClass('active');
			
			$('#tweets').attr('title', query + filters[filter]);
		}
	}
	else
	{
		if($('#filter-'+filter).attr('class') == "active")
		{
			$('#filter-'+filter).removeClass('active');
			$('#tweets').attr('title', query.replace(filters[filter], "") );
		}
		else
		{
			$('#filter-'+filter).addClass('active');
			$('#tweets').attr('title', query + filters[filter]);
		}
	}
	
	window.wthstream = {};
	$('.wthstream').html("");
	$('.wthstream').each(function(e) { rrp = 12; fetch_tweets(this); });	
}

function showTwitPic(tail)
{
	$.getJSON("/ajax/utils.php?action=twitpic&tail="+tail,
		function(json)
		{
			if(json.error)
				alert(json.error);
			else
				tb_show('', json.image);
		}
	);
}

function showOAuthTweetBox(text)
{
	$('#box-wrapper').show();
	$('#box').fadeIn('slow');
	if(text)
	{
		$('#statusbox-ol').val(text);
		updateOverlayCharacterCounter();
	}
	
	$('#statusbox-ol').focus();
	
	return false;
}

function hideOAuthTweetBox()
{
	$('#box').fadeOut('slow');
	$('#box-wrapper').hide('slow');
	return false;
}

function updateOverlayCharacterCounter()
{
	var charsTyped = $('#statusbox-ol').val().length;
	var charsLeft = 140 - charsTyped;
	
	// Update counter
	var counter = $('#status-field-char-counter-ol');
	var charsLeftString = charsLeft.toString();
	counter.html(charsLeftString);
	
	if(charsLeft >= 20)
		counter.css({color: "#CCCCCC"});
	else if(charsLeft < 20 && charsLeft >= 10)
		counter.css({color: "#5C0002"});
	else
		counter.css({color: "#D40D12"});
	
	// Save button enabled or disabled?
	if(charsTyped > 0 && charsTyped <= 140)
	{
		$('.update-submit-ol').removeAttr("disabled");
		$('.update-submit-ol').removeClass("disabled");
	}
	else
	{
		$('.update-submit-ol').attr("disabled", true);
		$('.update-submit-ol').addClass("disabled");
	}
}

function shortenOverlayURL()
{
	var apiURL = "";
	var service = $('#shortener-ol').val();
	var longURL = $('#longurl-ol').val();
	
	if(longURL == "" || longURL == "Shorten a link")
		return;
	
	if(service == "")
	{
		displayError("Unsupported Shortening service");
		return;
	}
	
	$.get("/ajax/utils.php", { 'action': 'shorten', 'service': service, 'longURL': longURL },
		function(shortURL)
		{
			if(shortURL == "error")
			{
				displayError("An error occurred while shortening that URL", 2000);
			}
			else
			{
				var tweetText = $('#statusbox-ol').val();
				var newText = tweetText;
				
				// add a space only if the last character isn't a space
				if(tweetText.substring(tweetText.length - 1) != " ")
					newText += " ";
				
				newText += shortURL;
				
				$('#statusbox-ol').val(newText);
				$('#longurl-ol').val("");
				
				displayMessage("URL shortened", 2000);
			}
		}
	);
}

function submitOAuthUpdateOverlay()
{
	var status_text = $('#statusbox-ol').val();
	var userKeyArray = new Array();
	
	// ensure a checkbox is selected
	var cbs = $('#oauth-accounts-ol input').each(function(){
		if (this.checked)
			userKeyArray.push(this.value);
	});
	
	if(userKeyArray.length == 0)
	{
		alert("Please select an account");
		return;
	}
	
	var userKeys = "";
	for(var i=0; i < userKeyArray.length; i++)
	{
		if(i == 0)
			userKeys += userKeyArray[i];
		else
			userKeys += "|" + userKeyArray[i];
	}
	
	// Send it off to the ether
	$.post("/ajax/oauthActions.php?action=submit", { status: status_text, uids: userKeys},
		function(returnValue)
		{
			if(returnValue == "success")
			{
				// populate the message
				displayMessageOverlay("Message posted!");
				
				// Clear out the status box for everything but the hashtag
				$('#statusbox-ol').val("");
				
				// update the character counter
				updateOverlayCharacterCounter();
				
				// close the overlay
				hideOAuthTweetBox();
			}
			else
			{
				displayErrorOverlay(returnValue);
			}
		}
	);
}

function displayErrorOverlay(error, timeout)
{
	if(!timeout)
		timeout = 3000;
	
	$('#tweet-above-ol .error').html(error);
	$('#tweet-above-ol .error').fadeIn(750);
	setTimeout("fo($('#tweet-above-ol .error'));", timeout);
}

function displayMessageOverlay(message, timeout)
{
	if(!timeout)
		timeout = 3000;
		
	$('#tweet-above-ol .message').html(message);
	$('#tweet-above-ol .message').fadeIn(750);
	setTimeout("fo($('#tweet-above-ol .message'));", timeout);
}

$(document).ready(function() {
	linkifyDescriptions();
});
