$(document).ready(function() {
  var msg_div = $("#video_check_message");
  msg_div.hide();
  var speed = "";
  if($.browser.msie) 
	speed = "";
  else
  	speed = "fast";
  $('#VideoChecker').click( function() { 
   
    $('#VideoChecker').attr("disabled", "true");
	if( $(':input:checkbox:checked').length > 0 && $(':input:checkbox:checked').length < 32)
	{
		msg_div.text( "" );
		msg_div.hide( speed );
		var video_id = 0;
		var i = 0;
		var checkedItems = $.makeArray($(':input:checkbox:checked'));
		var buffItem;
		var ajaxManager = $.manageAjax.create('vscheck', {queue: true, maxRequests: 1}); 
		
		for (i = 0; i <= checkedItems.length; i++)
		{
			buffItem = checkedItems[i];
			
			if ($(buffItem).attr('ID')) 
			{
				video_id = parseInt($(buffItem).attr('ID'));
				
				$("#status_" + video_id).attr("src", "images/status_loading.gif");
					
				$.manageAjax.add( 'vscheck' , { 
					  type: "POST",
					  url: "vscheck.php",
					  data: ({ vid_id: video_id, job_type: 1}),
					  success: 
						 function(data){
							if (data.message != "") 
							{
								msg_div.append(data.message + "<br />").show(speed);
							}
							$("#status_" + data.video_id).attr("src", data.status_img);
						  },
					  dataType: "json" 
				});
			}
			else 
			{
				if ($(buffItem).attr('VALUE')) 
				{
					msg_div.append("It's impossible to check Video ID " + $(buffItem).attr('VALUE') + "<br />").show(speed);
				}
			}
		}
	}
	else
	{
		msg_div.text("Please use the checkboxes on the left to select the videos you want to check.").show( speed );
	}
	if( msg_div.text().length > 0)
	{
		msg_div.show( speed );
	}
	$('#VideoChecker').attr("disabled", "");
  });
});