
var filePath = 'http://www.budokin.com/mod/video/operations.php';
var pluginPath = 'http://www.budokin.com/mod/video/';
var actionPath = 'http://www.budokin.com/actions/';

function prepareSyndicatedUpload(videoTitle, videoDescription, videoCategory, videoTags, nextUrl, videoAccessId, videoContainerGuid) 
{ 
  var ytParams = 'operation=create_upload_form' +
		'&videoTitle=' + videoTitle +
      '&videoDescription=' + videoDescription +
      '&videoCategory=' + videoCategory +
      '&videoTags=' + videoTags +
      '&nextUrl=' + nextUrl +
      '&videoAccessId=' + videoAccessId +
	   '&videoContainerGuid=' + videoContainerGuid;

	$.ajax({
		type: "post", 
		url: filePath, 
		data: ytParams, 
		success: function(data){ 		
			$("#syndicatedUpload").html(data);
		}
	});

}

function updateVideoMetaData(videoTitle, videoDescription, videoCategory, videoTags, videoId, videoGuid, videoAccessId, videoContainerGuid) 
{		
	// YouTube API Parameters
	var ytParams = 'operation=edit_meta_data' +
		'&newVideoTitle=' + videoTitle +
	   '&newVideoDescription=' + videoDescription +
	   '&newVideoCategory=' + videoCategory +
	   '&newVideoTags=' + videoTags +
	   '&videoId=' + videoId;
									
	// Elgg Parameters
	var elggParams = '?videoTitle=' + videoTitle +
	   '&videoDescription=' + videoDescription +
	   '&videoCategory=' + videoCategory +
	   '&videoTags=' + videoTags +
	   '&videoGuid=' + videoGuid +
	   '&videoAccessId=' + videoAccessId
	
	$.ajax({
		type: "post",
		url: filePath,
		data: ytParams,
		success: function(data){ 		
			window.location = actionPath + 'video/edit' + elggParams;
		}
	});
}

function presentFeed(op, maxResults, startIndex, searchTerm, resultsDiv)
{
   var ytParams = 'operation=' + op + 
              		'&maxResults=' + maxResults +
               	'&startIndex=' + startIndex + 
               	'&searchTerm=' + searchTerm;
	/*			
	$.ajax({type: "post", url: filePath, data: ytParams, success: 
		function(data){ 		
			//alert(data);
			$(resultsDiv).html(data);
		}
	});
	*/
}


function presentVideoThumbnail(videoId, videoThumbnailDiv) 
{ 
   var ytParams = 'operation=show_video_thumbnail' + 
						'&videoId=' + videoId;
	
	$.ajax({
		type: "post", 
		url: filePath, 
		data: ytParams, 
		success: function(data){ 		
			$(videoThumbnailDiv).html(data);
		}
	});
}


function presentVideo(videoId, viewType, videoPlayerDiv) 
{ 
   var ytParams = 'operation=show_video' + 
						'&videoId=' + videoId + 
						'&viewType=' + viewType;
	
	$.ajax({
		type: "post", 
		url: filePath, 
		data: ytParams, 
		success: function(data){ 		
			$(videoPlayerDiv).html(data);
		}
	});
}


function deleteVideo(videoId, videoGuid, confMessage) 
{  
   var ytParams = 'operation=delete_video' +
              	 	'&videoId=' + videoId;
						
	var answer = confirm(confMessage);
	if (answer){
		$.ajax({
			type: "post", 
			url: filePath, 
			data: ytParams, 
			success: function(data){	
				$('body').html('');		
				window.location = actionPath + 'video/delete?videoGuid=' + videoGuid;				
			}
		});	
		return false;
		
	} else {
	}
}

/** 
 * Check videos upload status.
 * 
 * @param {String} videoId The id of the video to check
 * @param {String} resultsDiv The output element
 */

function checkUploadStatus(videoId, resultsDiv) 
{  
   var ytParams = 'operation=check_upload_status&videoId=' + videoId;
					
	$.ajax({
		type: "post", 
		url: filePath, 
		data: ytParams, 
		success: function(data){	
			$(resultsDiv).html(data);				
		}
	});	

}

