
var ajax_loader = '<img src="'+baseurl+'/images/ajax-loader-f6.gif" class="loader" />';

var edit_button = '<a href="" id="edit_status" class="underline">edit</a>';

var status;

function update_status() {
	
	//$('#status').hide().after(ajax_loader);
	
	status = $('#status').val();
		
	var scriptData = {'status': status};
	
	url = baseurl+"/content/ajax/ajax_update_status.php";
	
	$('#status_div').html(ajax_loader);
	
	$.ajax({
			url: url,
			cache: false,
			data: scriptData,
			dataType: 'json',
			success: function(response){
				if (response.result == 'success'){
					$('#status_div').html('<p>'+status+' '+edit_button+'</p>');
				}
	
				$("#edit_status").click(function() {
					show_status_box();
					return false;
				});
			},
			error: function(error){
				alert("Failed to update status");
				var errorString = "";
						$.each(error, function(key,value) {
								errorString+="&"+key+"="+value;
						});
				alert(errorString);
				/*alert("url: "+url);
				var scriptString = "";
						$.each(scriptData, function(key,value) {
								scriptString+="&"+key+"="+value;
						});
				alert(scriptString);*/
			}
	});
		
}

function show_status_box() {
	
	if (!status) status = initStatusText;
	
	charsLeft = 140 - status.length;
	
	html = '<textarea class="textfield autogrow no_margin width_98" id="status" maxlength="140">' + status + '</textarea>';
	html += '<small>Limit: 140 characters | <span class="charsLeft">'+charsLeft+' remaining</span></small>';
	html += '<input type="button" class="submit align_right" id="status_submit" value="Update" />';
	
	$('#status_div').html(html);
	
	refresh_ajax();
	
}

function refresh_ajax() {
	
	$("#status_submit").click(function() {
		if ($('#status').val()!=defaultStatusText){
			update_status();
		}
	});
		
	$('#status').keyup(function(){ var limit = $(this).attr('maxlength'); ($(this).val().length < limit) ? $('.charsLeft').html(limit-$(this).val().length) : $(this).val($(this).val().substr(0,limit)) + $('.charsLeft').html('<span style="color: rgb(255, 0, 0);">0 remaining</span>');});
	
}

<!-- JB CODE

var state = 'none';

function showhide(layer_ref) {

if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}

}

function togglethis(layer_ref) {
	showhide(layer_ref);
	showhide('show_button');
}

// END JB CODE -->

$(function() {
	
	defaultStatusText = "What are you working on?";
	
	initStatusText = $("#status").val();
		
	$("#status").focus(function() {
		if ($(this).val()==defaultStatusText){
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val()==""){
			$(this).val(defaultStatusText);
		}
	});
	
	refresh_ajax();

});

$(document).ready(function() {

 // hides the slickbox as soon as the DOM is ready

 // (a little sooner than page load)

  $('#slickbox').hide();

 // shows the slickbox on clicking the noted link

  $('a#slick-show').click(function() {

 $('#slickbox').show('slow');

 $('#short_profile').hide('slow');

 return false;

  });

 // hides the slickbox on clicking the noted link

  $('a#slick-hide').click(function() {

 $('#slickbox').hide('slow');

 $('#short_profile').show('slow');

 return false;

  });

 // toggles the slickbox on clicking the noted link

  $('a#slick-toggle').click(function() {

 $('#slickbox').toggle(400);

 return false;

  });

});
