$(document).ready(function(){

var button = $('#button1.button'), interval;
	new AjaxUpload(button,{
	
		action: 'http://classifieds.inbahrain.info/for_sale/pic_upload/', 
		name: 'userfile',
		onSubmit : function(file, ext){

			button.text('Uploading');
			
			// 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.text();
				if (text.length < 16){
					button.html('&nbsp;'+text + '.');					
				} else {
					button.text('Uploading');				
				}
			}, 200);
		},
		onComplete: function(file, response){
			button.text('Upload');
						
			window.clearInterval(interval);
						
			// enable upload button
			this.enable();
			
			// add file to the list
			$('<li></li>').appendTo('ol.files').append(response);						
		}
	});


});	

function uploaded(){
	$('div#button1').text("File Uploaded");
	$('input[name=userfile][type=file]').remove();
}
