/*
////////////////////////////////////////////////////////
///////// Flash MediaPlayer CALLBACKS //////////////////
////////////////////////////////////////////////////////

Of course, there's a lot more updates that can be received. Here's the complete list:

   1. item, index: the currently playing playlistitem.
   2. load, percent: the percentage loaded of the current item.
   3. size, width,height: the dimensions of the current item.
   4. state, index: the current playback state.
   5. time, elapsed, remaining: the current elapsed and remaining time.
   6. volume, percent: the current volume.

   0=stop,1=buffer,2=play
*/

function getUpdate(typ, pr1, pr2, swf) { 
  //if(typ == 'state') { alert('the current state is: '+pr1'); }
  //$('status').innerHTML += 'Type='+typ+' Param1='+pr1+' Param2='+pr2+' SWF='+swf+' <br/>';
  
  if (swf == 'top_player') {
      switch (typ) {
          case 'state': AUDIOO.player.onStateChange(pr1);break;
          case 'time' : AUDIOO.player.onTimeChange(pr1, pr2);break;
          case 'load' : AUDIOO.player.onLoadChange(pr1);break; // pr1 - load progress in Percents!
          case 'volume': AUDIOO.player.onVolumeChange(pr1);break; // pr1 -- in percents
          
      }
  } else if(swf == 'mini_player') {
    
       switch (typ) {
          case 'state': AUDIOO.miniPlayer.onStateChange(pr1);break;
          case 'time' : AUDIOO.miniPlayer.onTimeChange(pr1, pr2);break;
          case 'load' : AUDIOO.miniPlayer.onLoadChange(pr1);break; // pr1 - load progress in Percents!
          case 'volume': AUDIOO.miniPlayer.onVolumeChange(pr1);break; // pr1 -- in percents
      }
      
      
  } else {
      
  }

  
};






/////////////////////////////////////////////////////////////
/////////////// SWF UPLOAD CALLBACKS ////////////////////////
/////////////////////////////////////////////////////////////

/*
File object

{ id : string, // SWFUpload file id, used for starting or cancelling and upload 
  index : number, // The index of this file for use in getFile(i) 
  name : string, // The file name. The path is not included. 
  size : number, // The file size in bytes 
  type : string, // The file type as reported by the client operating system 
  creationdate : Date, // The date the file was created 
  modificationdate : Date, // The date the file was last modified 
  filestatus : number, // The file's current status. Use SWFUpload.FILE_STATUS to interpret the value. 
}


Stats Object

{ 
  in_progress : number // 1 or 0 indicating if a file upload is currently in progress 
  files_queued : number // The number of files currently in the queue 
  successful_uploads : number // The number of files that have uploaded successfully (caused uploadSuccess to be fired) 
  upload_errors : number // The number of files that have had errors (excluding cancelled files) 
  upload_cancelled : number // The number of files that have been cancelled 
  queue_errors : number // The number of files that caused fileQueueError to be fired }

*/





/* Demo Note:  This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete.
The FileProgress class is not part of SWFUpload.
*/


/* **********************
   Event Handlers
   These are my custom event handlers to make my
   web application behave the way I went when SWFUpload
   completes different tasks.  These aren't part of the SWFUpload
   package.  They are part of my application.  Without these none
   of the actions SWFUpload makes will show up in my application.
   ********************** */

function uploadLoaded() {
    //alert('Loaded!');
}

function fileQueued(file) {
    try {
        top.frames['content'].AUDIOO.upload.onFileQueued(file);
    } catch (ex) {
        this.debug(ex);
    }
}

function fileQueueError(file, errorCode, message) {
	
    try {
        /*
		if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
			alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
			return;
		}

		var progress = new FileProgress(file, this.customSettings.progressTarget);
		progress.setError();
		progress.toggleCancel(false);

		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			progress.setStatus("File is too big.");
			this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			progress.setStatus("Cannot upload Zero Byte files.");
			this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
			progress.setStatus("Invalid File Type.");
			this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		default:
			if (file !== null) {
				progress.setStatus("Unhandled Error");
			}
			this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		}
		*/
        AUDIOO.upload.onFileQueueError(file, errorCode, message);
		
	} catch (ex) {
        this.debug(ex);
    }
    
    
}

// called just before File selection dialog
function fileDialogStart() {
    try {
        top.frames['content'].AUDIOO.upload.onFileDialogStart();
    }  catch (ex) {
        this.debug(ex);
    }
}


// called just AFTER File selection dialog
function fileDialogComplete(numFilesSelected, numFilesQueued) {
    try {
        top.frames['content'].AUDIOO.upload.onFileDialogComplete(numFilesSelected, numFilesQueued);
    } catch (ex)  {
        this.debug(ex);
    }
}

/** this is called for each file queued for upload */
function uploadStart(file) {
	
    try {
		/* I don't want to do any file validation or anything,  I'll just update the UI and
		return true to indicate that the upload should start.
		It's important to update the UI here because in Linux no uploadProgress events are called. The best
		we can do is say we are uploading.
		 */
		return AUDIOO.upload.onUploadStart(file);
	}
	catch (ex) {}
	
}



//** progress event **/
function uploadProgress(file, bytesLoaded, bytesTotal) {
    try {
        AUDIOO.upload.onUploadProgress(file, bytesLoaded, bytesTotal);
	} catch (ex) {
		this.debug(ex);
	}
}

//** called at the end of file upload, but BEFORE uploadComplete event **/
function uploadSuccess(file, serverData) {
	try {
		AUDIOO.upload.onUploadSuccess(file, serverData);
	} catch (ex) {
		this.debug(ex);
	}
}


function uploadComplete(file) {
	/*
    if (this.getStats().files_queued === 0) {
		document.getElementById(this.customSettings.cancelButtonId).disabled = true;
	}*/
	
	//alert('Complete:'+file.name);
	
	
}

// This event comes from the Queue Plugin
function queueComplete(numFilesUploaded) {
    AUDIOO.upload.onQueueComplete(numFilesUploaded);
}

function uploadError(file, errorCode, message) {
	try {
		//var progress = new FileProgress(file, this.customSettings.progressTarget);
		//progress.setError();
		//progress.toggleCancel(false);

		AUDIOO.upload.onUploadError(file, errorCode, message);
		
		/*
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
			progress.setStatus("Upload Error: " + message);
			this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
			progress.setStatus("Upload Failed.");
			this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.IO_ERROR:
			progress.setStatus("Server (IO) Error");
			this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
			progress.setStatus("Security Error");
			this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			progress.setStatus("Upload limit exceeded.");
			this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
			progress.setStatus("Failed Validation.  Upload skipped.");
			this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			// If there aren't any files left (they were all cancelled) disable the cancel button
			if (this.getStats().files_queued === 0) {
				document.getElementById(this.customSettings.cancelButtonId).disabled = true;
			}
			progress.setStatus("Cancelled");
			progress.setCancelled();
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			progress.setStatus("Stopped");
			break;
		default:
			progress.setStatus("Unhandled Error: " + errorCode);
			this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
			break;
		}
		
		*/
	} catch (ex) {
        this.debug(ex);
    }
}

