max_length = 140;
$(document).ready(function(){
	$('#chat_all_guide').jqm({
	    trigger: '#btn_chatall_help',
	    toTop:true,
	    overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
	    overlayClass: 'whiteOverlay'
	    });
	    //.jqDrag('.jqDrag'); /* make dialog draggable, assign handle to title */
	
	var options = {
		target:'#chat_list',
		resetForm: true,
		beforeSubmit:function(){
		    $("#status-field-char-counter").html("    ");
			$("#status-field-char-counter").addClass("loading");
		},
		success:resetChatForm
	}
	$("#chatform").ajaxForm(options);
	$("#status-field-char-counter").html(max_length);
	$("#tweeting_button").attr('disabled','disabled');
	$("#tweeting_button").addClass("btn-disabled");
	$("#tweeting_button").click(function(){
		val = $("#status").val();
		if(val.length > 0 && val.length <= max_length){
			$("#chatform").ajaxSubmit(options);
		}
		return false;
	});
	
	$("#status").keyup(function(){
		var box = $(this).val();
		var count = max_length - box.length;
		if(box.length > 0 && box.length < max_length){
			if($("#tweeting_button").attr('disabled') != 'undefined'){
				$("#tweeting_button").removeAttr('disabled');
				$("#tweeting_button").removeClass('btn-disabled');
			}
		}else{
			if(!$("tweeting_button").hasClass("btn-disabled")){
				$("#tweeting_button").addClass("btn-disabled");
				$("#tweeting_button").attr('disabled','disabled');
			}
		}
		if(count < 10){
			var cssObj = {
				'color':'rgb(212, 13, 18)'
			}
		}else if(count < 20){
			var cssObj = {
				'color':'rgb(92,0,2)'
			}
		}else{
			var cssObj = {
				'color':'rgb(204, 204, 204)'
			}
		}
		$('#status-field-char-counter').css(cssObj);
		$('#status-field-char-counter').html(count);
		return false;
	});
});




resetChatForm = function(){
	$("#status-field-char-counter").removeClass("loading");
	$("#status-field-char-counter").html(max_length);
}


