$(document).ready(function() {

	$('.login').click(function() {
 		$('.login-box').slideToggle(500);
		return false;
	});

	$('.edit').click(
      		function () {
			$('.edit').css({'display':'none'});
			$('.close-edit').css({'display':'inline'});
			$('.editor').slideDown(500);
			$.cookie('.editor', 'open');
     		}
    	);

	$('.close-edit').click(
      		function () {
			$('.edit').css({'display':'inline'});
			$('.close-edit').css({'display':'none'});
			$('.editor').slideUp(500);
			$.cookie('.editor', 'null');
			return false;
      		}
    	);

   	var editor = $.cookie('.editor');
    		if (editor == 'open') {
			$('.edit').css({'display':'none'});
			$('.close-edit').css({'display':'inline'});
			$('.editor').slideDown(500);
    	};

	$('.page-manager').click(
      		function () {
			$('.page-manager').css({'display':'none'});
			$('.close-page-manager').css({'display':'inline'});
 			$('.page-manager-container').slideDown(500);
			$.cookie('.page-manager-container', 'open');
     		}
    	);

	$('.close-page-manager').click(
      		function () {
			$('.page-manager').css({'display':'inline'});
			$('.close-page-manager').css({'display':'none'});
 			$('.page-manager-container').slideUp(500);
			$.cookie('.page-manager-container', 'null');
			return false;
      		}
    	);

   	var pagemanagercontainer = $.cookie('.page-manager-container');
    		if (pagemanagercontainer == 'open') {
			$('.page-manager').css({'display':'none'});
			$('.close-page-manager').css({'display':'inline'});
			$('.page-manager-container').slideDown(500);
    	};

	$('.file-manager').click(
      		function () {
			$('.file-manager').css({'display':'none'});
			$('.close-file-manager').css({'display':'inline'});
 			$('.file-manager-container').slideDown(500);
			$.cookie('.file-manager-container', 'open');
     		}
    	);

	$('.close-file-manager').click(
      		function () {
			$('.file-manager').css({'display':'inline'});
			$('.close-file-manager').css({'display':'none'});
 			$('.file-manager-container').slideUp(500);
			$.cookie('.file-manager-container', 'null');
			return false;
      		}
    	);

   	var filemanagercontainer = $.cookie('.file-manager-container');
    		if (filemanagercontainer == 'open') {
			$('.file-manager').css({'display':'none'});
			$('.close-file-manager').css({'display':'inline'});
			$('.file-manager-container').slideDown(500);
    	};

	$('.file-manager-more-img').click(function() {
 		$('.file-manager-info').slideToggle(500);
	});

	$('.template-manager').click(
      		function () {
			$('.template-manager').css({'display':'none'});
			$('.close-template-manager').css({'display':'inline'});
			$('.template-manager-bar').css({'visibility':'visible'});
 			$('.template-manager-container').slideDown(500);
			$.cookie('.template-manager-container', 'open');
     		}
    	);

	$('.close-template-manager').click(
      		function () {
			$('.template-manager').css({'display':'inline'});
			$('.close-template-manager').css({'display':'none'});
			$('.template-manager-bar').css({'visibility':'hidden'});
 			$('.template-manager-container').slideUp(500);
			$.cookie('.template-manager-container', 'null');
			return false;
      		}
    	);

   	var templatemanagercontainer = $.cookie('.template-manager-container');
    		if (templatemanagercontainer == 'open') {
			$('.template-manager').css({'display':'none'});
			$('.close-template-manager').css({'display':'inline'});
			$('.template-manager-container').slideDown(500);
    	};

	$("#page-list")
	.tablesorter( {sortList: [[0,0], [1,0]]} ) // sort on the first column and second column, order ascending
	.tablesorterPager({container: $("#pager"), positionFixed: false
	}); 

});


function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete this web page?")) {
    document.location = delUrl;
  }
}


function confirmBackup(resUrl) {
  if (confirm("Overwrite previous backup file?")) {
    document.location = resUrl;
  }
}


function confirmRestore(resUrl) {
  if (confirm("Restore this web page from previous backup file?")) {
    document.location = resUrl;
  }
}


function confirmBackupTemplate(resUrl) {
  if (confirm("Overwrite previous backup template if one exists?")) {
    document.location = resUrl;
  }
}


function confirmRestoreTemplate(resUrl) {
  if (confirm("Restore this template from previous backup template?")) {
    document.location = resUrl;
  }
}
