jQuery(document).ready(function() {
new AjaxUpload('#upload_button', {
// Location of the server-side upload script
// NOTE: You are not allowed to upload files to another domain
action: '/uploadedFiles/upload/',
// File upload name
name: 'File',
// Submit file after selection
autoSubmit: true,
// The type of data that you're expecting back from the server.
// HTML (text) and XML are detected automatically.
// Useful when you are using JSON data as a response, set to "json" in that case.
// Also set server response type to text/html, otherwise it will not work in IE6
responseType: false,
// Fired after the file is selected
// Useful when autoSubmit is disabled
// You can return false to cancel upload
// @param file basename of uploaded file
// @param extension of that file
onChange: function(file, extension){},
// Fired before the file is uploaded
// You can return false to cancel upload
// @param file basename of uploaded file
// @param extension of that file
onSubmit: function(file, extension) {},
// Fired when file upload is completed
// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
// @param file basename of uploaded file
// @param response server response
onComplete: function(file, response)
{
document.getElementById("hidFileID").value = response;
singleImageHandler(response);
}
});
// put all your jQuery goodness in here.
});


function singleImageHandler($filevalue){
//$hiddenField = document.getElementById('hidFileID');
//file upload path
//$filevalue = $hiddenField.value;
//alert($filevalue);

//console.debug($filevalue);
//split the filename on the | separator - value 1 is id value 2 is filename
$fileArray = $filevalue.split('|');
$imageID = $fileArray[0];
$filename = $fileArray[1];
$uniqID= $fileArray[2];
$w= $fileArray[3];
$h= $fileArray[4];

$filetypeArray = $filename.split('.');

if($filetypeArray[1] == 'swf')
{
//console.debug('here in if');
jQuery('singleImage').innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+$w+"' height='"+$h+"'><param name='movie' value='/image/"+$imageID+"/"+$w+"/"+$h+"/"+$filename+"'><param name='quality' value='high'><embed src='/image/"+$imageID+"/"+$w+"/"+$h+"/"+$filename+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+$w+"' height='"+$h+"'></object><br/><a href=\"javascript:unlinkSingleImage('"+$uniqID+"');\">Delete File</a>";
}
else
{
//console.debug('here in else');
//Do this my way echo the html and a delete link!, appendChild only confuses me!
jQuery('#singleImage').html("<img src = '/image/"+$imageID+"/75/0/"+$filename+"' width = '75' alt=''/><br/><a href=\"javascript:unlinkSingleImage('"+$uniqID+"');\">Delete File</a>");
}


//$('btnBrowse').disabled = false;
}


function unlinkSingleImage(uniqID)
{
document.getElementById('hidFileID').value = "";
//new Ajax.Request('/UploadedFiles/delete/'+uniqID, {'method':'get'});

val = $.ajax({ 
type: "GET",
url: '/UploadedFiles/delete/'+uniqID, 
async: false
}
).responseText;	

jQuery('#singleImage').html("");
}
