(function($){
	$(document).ready(function(){

		$('#delete-dialog').dialog({
			title:'Delete Site Builder Wizard?',
			autoOpen:false,
			modal:true,
			resizable:false,
			closeOnEscape:false,
			//height:180,
			width:320,
			dialogClass:'sb-dialog-container delete-dialog-container shadow-dark',
			create:function(){
				$('#btnYes').click(function(){
					//set hidden instanceid field with the corresponding instance id
					$('#instanceid').val($(this).closest('tr').attr('id').replace(/instance_/,''));
					$('#instanceid').closest('form').submit();

					$('#delete-dialog').dialog('close');
				});
				$('#btnNo').click(function(){
					$('#delete-dialog').dialog('close');
				});
			},
			open:function(){
				$('#btnNo').focus();
			}
		});

		$('button[name=btnDelete]').click(function() {
			$('#delete-dialog #sb-wizard-name').text($(this).closest('tr').find('td:first').text());
			$('#delete-dialog').dialog('open');
			return false;
		});

		$('button[name=btnContinue]').click(function() {
			//redirect based on the corresponding data-last-step-url custom row attribute
			var url = $(this).closest('tr').attr('data-last-step-url');
			url += ((url.indexOf('?') != -1) ? '&':'?') + 'instanceid=' + $(this).closest('tr').attr('id').replace(/instance_/,'');
			location.href = url;
		});

	});
})(jQuery);