var imageIDs = [];
var gallery_id = -1;

function fileQueueError(fileObj, error_code, message) {
  var error_str;
  if(fileObj != null)
    error_str = fileObj.name + " "  + _("could not be uploaded because") + " ";
  else
    error_str = _("Sorry, your files could not be uploaded because") + " ";

  switch(error_code) {
    case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
      error_str += _("you have exceeded the upload limit of 60. After uploading up to 60 images you may upload additional images to this album.");
        break;
    case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
      error_str += _("you have exceeded the maximum file size for individual images of 4000 kb. Please try again.");
        break;
    case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
      error_str += _("you can only upload .jpg, .gif, or .png files to your album. Please try again.");
        break;
    default:
      error_str += ("there was an error. Please try again.");
  }
  $('#error').html(error_str);
  //$('#error').effect("highlight", {}, "slow");
}

function fileQueued(file) {
  $('#queue').append('<li class="hide" id="' + file.id + '"><span class="filename">' + file.name + '</span><span id="progress_' + file.id + '" class="progress" /><span class="xupload"><a href="#" onclick="swfu.cancelUpload(\'' + file.id + '\', false);$(\'#' + file.id + '\').fadeOut(\'slow\', function() { $(this).remove() });return false;"><img src="/images/icons/cross-sm.gif" alt="" /></a></span></li>');
  $('#progress_' + file.id).progressBar({ value: 0, boxImage: "/images/progressbar/progressbar.gif", barImage: "/images/progressbar/progressbg_orange.gif"  });
  $('#' + file.id).fadeIn();
}

function uploadProgress(fileObj, bytesLoaded) {
  var percent = Math.ceil((bytesLoaded / fileObj.size) * 100);
  $('#progress_' + fileObj.id).progressBar(percent);
}

function uploadStart(fileObj) {
  $('#error').html("");
}

function uploadSuccess(fileObj, server_data) {
  data = server_data.split(",");  
  gallery_id = data[0];
  imageIDs.push(data[1]);
  $('#thumbnails').append('<div><img src="' + data[2] + '" alt="" class="imgborder" /></div>');
  $('#' + fileObj.id).animate({"opacity" : "+=0"}, 2000).fadeOut("slow", function(callback) { $(this).remove() });
}

function uploadComplete(fileObj) {
  if (this.getStats().files_queued > 0) {
    this.startUpload();
  } else if (imageIDs.length > 0 && gallery_id > 0) {
    var gallery_edit = '/galleries/' + gallery_id + '/photos/' + imageIDs.toString() + '/edit?upload=1';
    //$('#status').html(this.getStats().successful_uploads + ' photos successfully uploaded.');
    //$('#status').append('<br /><a href="">Edit these photos.</a>');
    $('#spinner').show();
    window.setTimeout(function() { window.location = gallery_edit }, 5000); 
  }
}

function cancelFile(id) {
  this.cancelUpload(id, false);
  $('#' + id).fadeOut().remove();
}

function uploadError(fileObj, error_code, message) {
  /*
     var image_name =  "error.gif";
     try {
     switch(error_code) {
     case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
     try {
     var progress = new FileProgress(fileObj,  this.customSettings.upload_target);
     progress.SetCancelled();
     progress.SetStatus("Stopped");
     progress.ToggleCancel(true, this, fileObj.id);
     }
     catch (ex) { this.debug(ex); }
     case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
     image_name = "uploadlimit.gif";
     break;
     default:
     alert(message);
     break;
     }

  //AddImage("/images/" + image_name);

  } catch (ex) { this.debug(ex); }
  */
}
