                function countKeys(box){
                   if( box.value.length > 512 ){
                      box.value=box.value.substring(0,512);
                   }
                   $(".characters-left").html('characters left: '+(512-box.value.length));
                   return true;
                }
		var button = $('#upload'), interval;
		new AjaxUpload(button, {
			action: 'index.php?upload', 
			name: 'picture',
			onSubmit : function(file, ext){
				if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)){
					button.attr('value','saving picture');
				} else {					
					// extension is not allowed
					alert('Please select an image to upload.');
					// cancel upload
					return false;				
				}	
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = button.attr('value');
					if (text.length < 17){
						button.attr('value',text + '.');					
					} else {
						button.attr('value','saving picture');				
					}
				}, 200);
			},
			onComplete: function(file, response){
							
				window.clearInterval(interval);
                                response = jQuery.parseJSON(response);
				if(response.status=="success"){
				  button.attr('value','picture saved');
				  this.enable();
                                  $('#new-like-post #left').css('background','transparent');
                                  $('#new-like-post #left').html('<center><img src="img/uploads/'+response.fileth+'" class="thumbpreview picborder"></center>');
                                  $('#likeit #picture').val('true');
                                  $('#likeit #picid').val(response.picid);
                                  $('#likeit #pickey').val(response.pickey);
                                } else {
                                  alert('Error: '+response.msg);
			          button.attr('value','add a picture');
                                  $('#new-like-post #left').html('');
                                  $('#likeit #picture').val('false');
                                  $('#likeit #picid').val('false');
                                  $('#likeit #pickey').val('false');
                                }
										
			}
		});
