// Eval current context
var context = eval('({"url_login":"\/user\/login?destination=upload","allow_blank_referrer":"1","enabled_imagerotate":true,"path_upload":"\/var\/www\/sifnt\/upload\/upload","path_cache":"\/var\/www\/sifnt\/upload\/upload\/cache","path_tmp":"\/tmp","path_magicdb":"extra\/magic\/magic","url_host":"http:\/\/www.sifnt.net.au","url_root":"\/upload","url_upload":"\/upload\/upload","url_redirect":false,"url_redirect_root":"http:\/\/mirror.sifnt.net.au\/upload","filegroup_unfiled":18,"js_inserttext":"inserttext_phpbb3","path_userdata":"include\/lib\/phpbb3.php","phpbb3_dsn":"mysqli:\/\/sifnt:wsj627@localhost\/sifnt_v2","phpbb3_tblprefix":"phpbb_","path_python":"\/usr\/bin\/python","path_pyodconverter":"\/var\/www\/sifnt\/upload\/extra\/pyodconverter\/DocumentConverter.py","path_java":"\/usr\/bin\/java","path_jodconverter":"\/var\/www\/sifntupload\/extra\/jodconverter\/jodconverter-cli-2.2.1.jar"})');

// Dynamically define inserttext function
function inserttext(type, text1, text2, text3){
    inserttext_phpbb3(type, text1, text2, text3);
}
// Global Variables
var fileInputNum = 0;

// Show upload modal
function showUploadModal(options){
    var parameters = {
        title:'Upload Files',
        noResizeWidth: true,
        maxWidth: 492,
        addClass: 'upload-modal',
        onLoad: function(){
            addFileInput();
        }
    }
    
    if(options){
        if(options.onSuccess){
            $.extend(parameters, {parameters: {onsuccess: options.onSuccess}});
        }
    }
    
    Modal.show(context.url_root + '/' + 'upload.php?action=new&output=iframe', parameters);
    
    return true;
}

function addFileInput(){
    var files = $('.fileinputs:first');
	files.data('filenum', fileInputNum);
	var filelist = $('.filelist:first');
	
	// Check that a file has been selected
	if(files.children('div').length){
		var lastDiv = files.children('div:last');
		var lastFileName = lastDiv.find('.filepath span').html();
		
		if(!lastFileName){
			return;
		}
		
		// Hide others
		lastDiv.hide();
		filelist
			.append($('<div>')
				.addClass('filenum' + lastDiv.data('filenum'))
				.data('filenum', lastDiv.data('filenum'))
				.append(lastFileName)
				.append(' ')
				.append($('<a>')
					.attr('href', "javascript:removeFileInput(" + lastDiv.data('filenum') + ");")
					.append('x')
					.addClass('closebutton')
				)
			)
			.css('display', 'block');
	}
	
    var div = $('<div>')
		.data('filenum', fileInputNum)
		.addClass('filenum' + fileInputNum);
    
    // Main Inputs
    // File Input
    div.append($('<div>')
	    .addClass('fileinput-section')
	    .append($('<input>')
		    .attr('type', 'radio')
		    .attr('name', 'file_source[' + fileInputNum + ']')
		    .attr('value', 'file')
		    .attr('checked', true)
		    .click(function(){checkFileSource(this);}))
	    .append($('<label>').html('File').addClass('inline'))
	    .append($('<input>')
		    .attr('type', 'radio')
		    .attr('name', 'file_source[' + fileInputNum + ']')
		    .attr('value', 'url')
		    .click(function(){checkFileSource(this);}))
	    .append($('<label>').html('URL').addClass('inline'))
	    .append($('<div>')
		    .append($('<input>')
			    .attr('type', 'file')
			    .attr('name', 'file_upload[' + fileInputNum + ']'))
			    .change(function(){hideFileInput(this);})
		    .addClass('filesource-file'))
	    .append($('<div>')
		    .append($('<input>')
			    .attr('type', 'text')
			    .attr('name', 'file_url[' + fileInputNum + ']')
			    .change(function(){checkFileURL(this);})
			    .addClass('wide'))
		    .append($('<input>')
			    .attr('type', 'hidden')
			    .attr('name', 'tmp_name[' + fileInputNum + ']'))
		    .addClass('filesource-url')
			.append(' ')
			.append($('<a>')
				.attr('href', 'javascript:;')
				.click(function(){ $(this).prevAll('input:text[name^=file_url]').trigger('change'); })
				.html('Check'))
		    .hide()));

    // Options
    div.append($('<div>')
        .attr('id', 'options_' + fileInputNum)
        .attr('class', 'fileinputoptions')
        .hide());
    
    files.append(div);
    
    // Description Input
    div.append($('<label>').html('Description'));
    div.append($('<input>')
        .attr('type', 'text')
        .attr('name', 'file_description[' + fileInputNum + ']')
        .attr('class', 'wide'));
    div.append($('<br />'));
    
    // File Group Select
    var filegroup_select = $('<select>')
        .attr('name','filegroup_id['+fileInputNum+']')
        .attr('class', 'filegroup')
    filegroup_select.append($('#filegroup_id_dummy').children().clone());
    
    // Select same group as previous file
    if(fileInputNum > 0){
		var prevOption = div.prev().find('.filegroup option:selected').val();
		filegroup_select.find("option[value='" + prevOption + "']").attr('selected', 'selected');
    }
    
    div.append($('<label>').html('Group'));
    div.append(filegroup_select);
    div.append(' ').append($('<a>')
        .attr('href', context.url_root + '/upload.php?action=addgroup')
        .click(function(){ return !showAddGroup(this); })
        .html('Add Group'));
    div.append($('<br />'));
    
    // Tag input
    div.append($('<label>').html('Tags'));
    div.append($('<select>')
        .attr('name', 'file_tags['+fileInputNum+']')
        .attr('id', 'file_tags_' + fileInputNum)
    );
    div.append($('<br />'));
    
    // Activate Tags
    $('#file_tags_' + fileInputNum).fcbkcomplete({
      json_url: context.url_root + '/ajax/taglist.php',
      json_cache: true,
      filter_case: true,
      filter_hide: true,
      newel: true        
    });
    	
    // Update Modal
    Modal.centerFloat();
    
    fileInputNum++;
}

function removeFileInput(filenum){
    $('.filenum' + filenum).remove();
	
	if($('.filelist label').nextAll().length == 0){
		$('.filelist').hide();
	}
    
    // Update Modal
    Modal.centerFloat();
}

function showAddGroup(id){
	$(id).prev().addClass('thisgrouplist');
	return Dialog.newDialog({
		title: 'Add Group',
		onClose: function(){$('.thisgrouplist').removeClass('thisgrouplist')},
		load: {
			url: context.url_root + '/upload.php?action=addgroup'
		},
		modal: true,
		addClass: 'addgroup-modal'
	});
	
	return true;
}

function addGroup(id){
    var form = $('#addgroup');
    var dS = $('.filegroup');

    form.ajaxSubmit({
        data: {ajax: 1, submit: 1},
        dataType: 'json',
        success: function(data){
            if(data.success){
                dS.each(function(index, i){
                    // Save currently selected option
                    var selected = $(i).find('option:selected').val();
                    
                    // Fill with new options
                    $(i).empty();
                    $.each(data.filegroups, function(index, fg){
                        $(i).append($('<option>')
                            .attr('value', fg.filegroup_id)
                            .html(fg.filegroup_name));
                    });
                    
                    // Select saved option
                    $(i).find("option[value='" + selected + "']").attr('selected', 'selected');
                });
                
                // Set selected option on file group was added to
                $(".thisgrouplist option[value='" + data.filegroup_id + "']")
					.attr('selected', 'selected')
					.trigger('change');
				
                
                $('.addgroup-modal').destroyDialog();
            }
            else{
                ajaxErrorMessage($('.addgroup-modal .errmsg'), data.error);
            }
        }
    });
    
    return true;
}

function showUploadProgress(rand){
	addFileInput();
	
	if($('.filelist div').length == 0){
		return false;
	}
	
	if($('.filelist div').length > 0){
		var lastDiv = $('#files .fileinputs > div:last');
		var lastFileName = lastDiv.find('.filepath span').html();
		
		if(!lastFileName){
			lastDiv.remove()
			$('#files > a').remove();
		}
	}
	$('.fileinputs:first')
		.append($('<p>').append('<b>Upload Progress</b>'))
        .append($('<div>').attr('class', 'uploadprogress'))
        .append($('<div>').attr('class', 'uploadstatus').html('Connecting...'));
    $('.uploadprogress').progressbar({value: 0});

	// Hide Upload and Close buttons
	$('.fileinputs:first').closest('.sm_window').find('.submit').hide();
	$('.fileinputs:first').closest('.sm_window').find('.closebutton').hide();
	
	// Disable modal close
	Modal.disableClose($('.fileinputs:first').closest('.sm_window'));
    
    $(document).data('uploadprogresspending', false);
    $(document).data('donecount', false);
    $(document).everyTime('500ms', 'getUploadProgress', function(){getUploadProgress(rand);});
}

function getUploadProgress(rand){
    if(!$(document).data('uploadprogresspending')){
        $(document).data('uploadprogresspending', true);
        $.post(context.url_root + '/upload.php',
            {action: 'ajax', mode: 'uploadprogress', rand: rand},
            function(data){
                $(document).data('uploadprogresspending', false);
                if(!data.done){
                    $(document).data('donecount', 5);
                    
                    $('.uploadprogress').progressbar('value', parseInt(data.percent));
                    $('.uploadstatus').empty();
					$('.uploadstatus')
						.append(data.uploaded + '/' + data.total + ' (' + data.percent + "%)\t")
						.append(data.speed + "\t")
						.append(data.timeleft + " remaining...")
                }
                else{
                    var doneCount = $(document).data('donecount');
                    if(doneCount < 5){
                        $(document).data('donecount', doneCount++);
                    }
                    else{
                        $(document).stopTime('getUploadProgress');
                        $('.uploadprogress').progressbar('value', 100);
                        $('.uploadstatus').html('Processing...');
                    }
                }
            },
        'json');
    }
}

// Show Insert Modal
function showInsertDialog(){
    Dialog.newDialog({
		load: {
			url: context.url_root + '/' + 'insert.php'
		},
        title: 'Your Files',
        addClass: 'insertfile',
        noResizeWidth: true,
        maxWidth: 602
    });
    
    return true;
}

// Refresh Insert Modal
function refreshInsertDialog(){
    $('.sm_window.insertfile .sm_content div:first')
        .load(context.url_root + '/insert.php', {ajax: true}, function(){$('.insertfile').centreDialog();});
}

// Change to a different Recent Files page
function loadRecentFilesPage(filePage){
    $('.section.recentfiles').load(context.url_root + '/insert.php .section.recentfiles > *', {file_page: filePage});
    
    return true;
}

// Change to a different Groups page
function loadGroupsPage(groupPage){
    $('.section.groups').load(context.url_root + '/insert.php .section.groups > *', {group_page: groupPage});
    
    return true;
}

// Change to a different Tags page
function loadTagsPage(tagPage){
    $('.section.tags').load(context.url_root + '/insert.php .section.tags > *', {tag_page: tagPage});
    
    return true;
}

// Change to a different Group page
function loadGroupPage(filePage, container, options){
	container.load(context.url_root + '/insert.php', {ajax: 1, action: 'showgroup', file_page: filePage, filegroup_id: options.filegroup_id, tag: options.tag});
}

// Load Group
function loadGroup(groupId, groupName){
    var tabNum = tabs.tabs('length');
    tabs.tabs(
        'add',
        context.url_root + '/insert.php?ajax=true&action=showgroup&filegroup_id=' + groupId,
        groupName,
		tabNum
    );
    tabs.data('group-tab', tabNum);
}

// Load Tag
function loadTag(tag){
    var tabNum = tabs.tabs('length');
    tabs.tabs(
        'add',
        context.url_root + '/insert.php?ajax=true&action=showgroup&tag=' + tag,
        tag,
		tabNum
    );
    tabs.data('group-tab', tabNum);
}

function loadSearch(query, page){
	if(!page){
		page = 1;
	}
	
	$(document).stopTime('search-timer');
	
	$(document).oneTime(1000, 'search-timer', function(){
		$('#searchresultstab').css('display', 'block');
		var tabNum = 4;
			
		tabs.tabs('url', tabNum, context.url_root + '/insert.php?ajax=true&action=showsearch&q=' + query + '&file_page=' + page);
		tabs.tabs('select', tabNum);
		tabs.tabs('load', tabNum);
	});
}

function checkFileSource(id){
	switch($(id).attr('value')){
		case 'file':
			$(id).closest('.fileinputs').find('div.filesource-file').show();
			$(id).closest('.fileinputs').find('div.filesource-url').hide();
			
			break;
		
		case 'url':
			$(id).closest('.fileinputs').find('div.filesource-file').hide();
			$(id).closest('.fileinputs').find('div.filesource-url').show();
			
			break;
	}
}

function deleteFile(id, options){
	if(confirm('Are you sure?')){
		$.post(context.url_root + '/' + 'upload.php', {action: 'delete', file_id: id, ajax: 1}, function(data){
			if(data.success){
				if(options){
					if(options.onComplete){
						options.onComplete();
					}
				}
			}
		}, 'json');
	}
}

function hideFileInput(id){
	var fileSection = $(id).closest('.fileinput-section');
	
	fileSection.hide();
	fileSection.after(
		$('<div>')
			.addClass('filepath')
			.append($('<label>').html('File Name'))
			.append($('<span>').html(fileSection.find('.filesource-file input').val()))
			.append(' ')
			.append($('<a>')
				.attr('href', 'javascript:;')
				.click(function(){ showFileInput(this); })
				.html('Change')));
	checkFileType(id);
}

function showFileInput(id){
	$(id).closest('.filepath').prev('.fileinput-section').find('.error').remove();
	$(id).closest('.filepath').prev('.fileinput-section').show();
	$(id).closest('.filepath').remove();
}

function checkFileURL(id){
	$('form#upload input[type="submit"]').attr('disabled', true);
	fileUrlInput = $(id);
	
	var fileSection = $(id).closest('.fileinput-section');
	
	fileSection.hide();
	var filePathSection = $('<div>')
		.addClass('filepath')
		.append($('<label>').html('File Name'))
		.append('Checking URL... ')
        .append($('<img>').attr('src', context.url_root + '/images/loading-spinner.gif'))
		.append(' ')
		.append($('<a>')
			.attr('href', 'javascript:;')
			.click(function(){ showFileURLInput(this); }));
	fileSection.after(filePathSection);

	
	$.post(
		context.url_root + '/upload.php',
		{action: 'ajax', mode: 'checkfileurl', file_url: fileUrlInput.val()},
		function(data){
			if(data.success){
				filePathSection
					.empty()
					.append($('<label>').html('File Name'))
					.append($('<span>').html(data.file_name))
					.append(' ')
					.append($('<a>')
						.attr('href', 'javascript:;')
						.click(function(){ showFileInput(this); })
						.html('Change'));
				filePathSection
					.prev('.fileinput-section')
					.find('.filesource-url input[type="hidden"]')
					.val(data.tmp_name);
					
				checkFileOptions(id, data.file_type);
			}
			else{
				fileSection.find('.error').remove();
                fileSection
					.show()
					.append($('<span>')
						.addClass('error')
						.html(data.error.validation[0]));
				filePathSection.remove();
			}
			$('form#upload input[type="submit"]').attr('disabled', false);
		},
		'json'
	);
}

function checkFileType(id){
	var fileInputDiv = $(id).closest('.fileinputs');
	var fileOptions = fileInputDiv.find('.fileinputoptions');
	var fileName = $(id).closest('.fileinput-section').find('.filesource-file input').val();
	
	$.post(
		context.url_root + '/upload.php',
		{
			action: 'ajax',
			mode: 'checkfiletype',
			file_name: fileName
		},
		function(data){
			if(data.success){
				checkFileOptions(id, data.file_type);
			}
		},
		'json'
	);
}


function checkFileOptions(id, fileType){
	var fileInputDiv = $(id).closest('.fileinputs');
	var fileOptions = fileInputDiv.find('.fileinputoptions');
	
	fileOptions.empty();
	switch(fileType){
		case 'image':
			if(context.enabled_imagerotate){
				fileOptions
					.append($('<label>')
						.html('Image Options'));
				
				// Image Rotate
				fileOptions
					.append($('<div>')
						.attr('class', 'imageoptions_rotate')
						.append('Rotate (Clockwise): <input type="radio" name="image_rotate[' + fileInputDiv.data('filenum') + ']" value="0" checked="checked" \/> 0&deg; ')
						.append('<input type="radio" name="image_rotate[' + fileInputDiv.data('filenum') + ']" value="90" \/> 90&deg; ')
						.append('<input type="radio" name="image_rotate[' + fileInputDiv.data('filenum') + ']" value="180" \/> 180&deg; ')
						.append('<input type="radio" name="image_rotate[' + fileInputDiv.data('filenum') + ']" value="270" \/> 270&deg; <br \/>'));
			}
			
			break;
		
		case 'audio':
			break;
		
		case 'video':
			break;
		
		case 'document':
			// Document Options
			fileOptions
				.append($('<label>')
					.html('Document Options'));
			
			// Convert to PDF
			fileOptions
				.append($('<div>').attr('class', 'documentoptions_pdf')
					.append($('<input>')
						.attr('type', 'checkbox')
						.attr('name', 'document_pdf[' + fileInputDiv.data('filenum') + ']')
						.attr('value', '1'))
					.append(' Convert to PDF<br />'));
			
			break;
	}
	
	fileOptions.show();
}

// Show image in dialog
function showImage(src, options){
    var placeholder = $('<div>').addClass('spinner').addClass('image-placeholder').css('width', '100px');
    Dialog.newDialog($.extend({
        addClass: 'image-dialog',
        load: {
            url: placeholder
        }
    }, options));
    
    $('<img>')
        .load(function(){
            $(this).hide();
            var content = $(placeholder).parent('div');
            content
                .empty()
                .append(this)
                .animate({
                    width: $(this).width() + 'px',
                    height: $(this).height() + 'px'
                },
                {
                    step: function(){$(content).centreDialog();},
                    complete: function(){
                        $(this).find('img').fadeIn();
                        $(content).centreDialog();
                    }
                });
        })
        .attr('src', src);
}

// Show file details in dialog
function showDetails(fileId, options){
	var maxWidth = $(window).width() - 50;
	var maxHeight = $(window).height() - 110;
	
	Dialog.newDialog($.extend({
		load: {
			url: context.url_root + "/view.php",
			data: {
				action: 'details',
				file_id: fileId,
				max_width: maxWidth,
				max_height: maxHeight
			}
		}
	}, options));
}

// Set filegroup
function setGroup(fileId, options){
	$.post(
		context.url_root + '/upload.php',
		{
			action: 'ajax',
			mode: 'setgroup',
			file_id: fileId,
			filegroup_id: options.groupId
		},
		function(data){
			if(!data.success){
				alert('An error occurred setting the file group, please try again later.');
			}
		},
		'json'
	);
}

// Add file tag
function addTag(fileId, options){
	if(options.tag){
		$('#filetags').load(
			context.url_root + '/upload.php',
			{
				action: 'ajax',
				mode: 'addtag',
				file_id: fileId,
				tag: options.tag
			},
			function(){
				$('#newtag')
					.val('')
					.autocomplete('close');
			}
		);
	}
}

// Remove file tag
function removeTag(fileId, options){
	$.post(
		context.url_root + '/upload.php',
		{
			action: 'ajax',
			mode: 'removetag',
			file_id: fileId,
			tag: options.tag
		},
		function(data){
			if(data.success){
				options.element.remove();
			}
		},
		'json'
	);
}

// Default successful upload redirect function
function successRedirect(data){
    file_ids = data.file_ids.join(',');    
    if(file_ids.length > 1){
	location.href = context.url_root + "/view.php?action=filmstrip&file_ids=" + file_ids;
    }
    else{
	location.href = context.url_root + "/view.php?action=details&file_id=" + file_ids;
    }
}

// Click-Insert wrapper functions
// TODO: Define an solid API so more of these functions can be written by third parties
// phpBB2
function inserttext_phpbb2(type, text1, text2, text3){
	var text;
	
	switch(type){
		case 'image':
			text = '[img]' + text1 + '[/img]';
			
			if(text2){
				text = '[url=' + text2 + ']' + text + '[/url]';
			}
			
			break;
			
		case 'file':
			text = '[url=' + text1 + ']' + text2 + '[/url]';
			
			break;
	}
	
	emoticon(text);
}

// phpBB3
function inserttext_phpbb3(type, text1, text2, text3){
	var text;
	
	switch(type){
		case 'image':
			text = '[img]' + text1 + '[/img]';
			
			if(text2){
				text = '[url=' + text2 + ']' + text + '[/url]';
			}
			
			break;
			
		case 'file':
			text = '[url=' + text1 + ']' + text2 + '[/url]';
			
			break;
		
		case 'sifntuploadembed':
			text = '[sifntuploadembed]' + text1 + '[/sifntuploadembed]';
			
			break;
	}
	
	insert_text(text, true);
}

// Handle generic sifntUploadEmbed function
function sifntUploadEmbed(options){
	if(options.fileId){
		var fileId = options.fileId;
		var cs = $(".sifntembed_" + fileId);
	}
	else if(options.url){
		var urlParts = options.url.split('/');
		var fileId = urlParts[5]; // TODO: Support different URL levels, current only supports sifntupload being at the second level
		var cs = $('.' + options.divClass);
	}
	
	cs.each(function(i, c){
		c = $(c);
		
		if(c.children().length == 0){
			
			// Create AV container
			var avcId = 'sifntembed_' + Math.ceil((fileId + (Math.random()*100)));
			var avc = $('<div>').attr('id', avcId);
			c.append(avc);
			
			// Get file details
			$.post(
				context.url_root + '/view.php',
				{
					action: 'ajax',
					mode: 'file_details',
					file_id: fileId
				},
				function(data){
					if(data.success){
						var file = data.file;
						var file_url = context.url_root + '/get/' + file.file_id + '/' + file.file_cleanname;
						
						// Determine default dimensions
						switch(file.file_extra){
							case 'audio':
								var width = 290;
								var height = 39;
								
								break;
							
							case 'video':
								var width = 480;
								var height = 335;
								
								break;
						}
						
						var oFile = $('<div>')
										.css('font-size', '10px')
										.append(
											$('<a>')
												.attr('href', file_url + '.' + file.file_ext)
												.click(function(){
													showDetails(fileId);
													return false;
												})
												.text('Original File')
										)
										.append(' ')
										.append(
											$('<a>')
												.attr('href', 'javascript:;')
												.click(function(){
													window.open(context.url_host + context.url_root + '/view/embed/' + file.file_id, 'sifntuploadpopout_' + Math.ceil((Math.random()*100)), 'width=' + (width + 10) + ',height=' + (height + 60) + ',resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no');
												})
												.text('Pop Out')
										)
										.append(' ')
										.append(file.file_viewed + ' plays')
						
						// Choose embed type
						switch(file.file_extra){
							case 'image':
								var image_width = '';
								if(avc.width() < file.image_width){
									image_width = '-' + avc.width();
								};
								
								avc.append(
									$('<a>')
										.attr('href', file_url + '.' + file.file_ext)
										.click(function(){
											showDetails(fileId);
											return false;
										})
										.append(
											$('<img>')
												.attr('src', file_url + image_width + '.' + file.file_ext)
										)
								);
								
								break;
							
							case 'audio':								
								if(file.queue_id){
									switch(file.queue_progress){
										case '-1':
											avc.text('Conversion of ' + file.description + ' to MP3 has failed.');
											break;
										
										case '0':
											avc.text(file.file_description + ' is currently in the conversion queue');
											break;
										
										case '1':
											avc.text(file.file_description + ' is currently converting to MP3...');
											break;
									}
									
									c.append(oFile);
								}
								else{
									audioOptions = {
										soundFile:  file_url + '.mp3',
										animation: 'no',
										transparentpagebg: 'yes'
									};

									if(file.audio_embedtitle){
										audioOptions = $.extend(audioOptions, {titles: file.audio_embedtitle});
									}
									else{
										audioOptions = $.extend(audioOptions, {titles: file.audio_title});
									}
									
									AudioPlayer.embed(avcId, audioOptions);
								}
								
								c.append(oFile);

								break;
							
							case 'video':
								if(file.queue_id){
									switch(file.queue_progress){
										case '-1':
											avc.text('Conversion of ' + file.description + ' to H.264 has failed.');
											break;
										
										case '0':
											avc.text(file.file_description + ' is currently in the conversion queue');
											break;
										
										case '1':
											avc.text(file.file_description + ' is currently converting to H.264...');
											break;
									}
									
									c.append(oFile);
								}
								else{
                                    var ar = parseInt(file.video_height) / parseInt(file.video_width);
                                    var video_width = width;
                                    var video_height = Math.ceil(width * ar);

									avc
										.css('width', video_width + 'px')
										.css('height', video_height + 'px');
									
									flowplayer(avcId, context.url_root + '/js/lib/flowplayer/flowplayer-3.2.1.swf', {
										clip: {
											autoPlay: true,
											autoBuffering: false
										},
										playlist: [
											file_url + '.jpg',
											{url: file_url + '.flv', autoPlay: false}
										]
									});
								
									c.append(oFile);
								}
								
								break;
							
							default:
								avc.text('Error: ' + file.file_cleanname + '.' + file.file_ext + ' is not supported by sifntUploadEmbed');
								break;
						}
					}
					else{
						avc.text('Error: File ID ' + fileId + ' may not exist.');
					}
				},
				'json'
			);
		}
	});
}
