$(document).ready(function() {

	$('#avatar').uploadify ({
		'uploader'  : '/wp-content/themes/2011/javascripts/uploadify/uploadify.swf',
		'script'    : '/wp-content/themes/2011/ajax_image_upload.php',
		'cancelImg' : '/wp-content/themes/2011/javascripts/uploadify/cancel.png',
		'fileDesc'  : 'Fichiers images',
		'fileExt'   : '*.jpg;*.jpeg;*.gif;*.png',
		'auto'		: true,
		'removeCompleted' : false,
		'folder'    : '/wp-content/uploads/test',
		'buttonText': '',
		'buttonImg' : '/wp-content/themes/2011/javascripts/uploadify/parcourir.png',
		'width'     : 71,
		'height'    : 20,
		'fileDataName' : 'avatar_id',
		'onAllComplete' : function(event,data) {
    		console.log(data);
	    },
		onError: function (a, b, c, d) {
			if (d.status == 404)
				console.log('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
			else if (d.type === "HTTP")
				console.log('error '+d.type+": "+d.status);
			else if (d.type ==="File Size")
				console.log(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
			else
				console.log('error '+d.type+": "+d.text);
		},
		'onComplete': function(e,q,f,r,d) {
			switch(r) {
				case "erreur_upload":
					console.log("Le script a foiré ...");
					break;
				default:
					$('#avatar_id').html('<p>Aper&ccedil;u de l\'avatar :</p><img src="wp-content/uploads/temp/'+r+'" alt="" />');
					$('#avatar_name').val(r);
					break;
			}
		}
	});
});

$('#avatar_id img').live('click',function() {
		$('#avatar_id').empty();
		$('#avatar_name').val("");
});
