function initUploadify(backendScript, thumbDir, uploadDir, buttonText) {
    $('#file_upload').uploadify({
        'uploader'       : '/uploadify/uploadify.swf',
        'script'         : backendScript,
        'cancelImg'      : '/uploadify/cancel.png',
        'buttonText'     : buttonText,
        'folder'         : uploadDir,
        'multi'          : true,
        'auto'           : true,
        'fileExt'        : '*.jpeg;*.jpg;*.gif;*.png',
        'fileDesc'       : 'Image Files (.JPG, .GIF, .PNG)',
        'queueSizeLimit' : 54,
        'simUploadLimit' : 3,
        'removeCompleted': true,
        'onError'        : function (event,ID,fileObj,errorObj) { 
        },
        'onComplete'  : function(event, ID, fileObj, response, data) {
            if(response == "maxlimit") {
                alert("Vous avez atteint le maximum autorisé");
            }
            else {
                var split = response.split('.');
                $('#mainCatalogue').append('<li class="orpheline ui-corner-all" id="' + split[0] + '"><img src="' + thumbDir + response + '.png"><div class="close ui-corner-all"><img onclick="deletePhoto(' + split[0] + ');" src="../../images/fo/icons/delete.png" /></div></li>');
                var length = $(".orpheline").length;
                $('#photo_count_total').html(length);
                length = $("#mainCatalogue").find("li").length;
                $('#photo_count_unpublished').html(length);
            }
        }
    });
}

function deletePhoto(id) {
    $.ajax({
        type: "POST",
        url: "/offer/remove",
        data: "ajaxAction=upload&photo=" + id,
        success: function(msg){
        }
    });
    $('#' + id).fadeOut(500);
}
