// JavaScript Document
$(document).ready(function() {
		//Preload all background images referenced in the CSS
		$.preloadCssImages();
		var subForm = 0;
	
		//Fade in login tab and welcome message when document is ready
		$('#loginTabIn').fadeIn(500);
		$('#loginTabOut').fadeIn(500);
		$('#welcome').fadeIn(500);
		
		if (showMembers == "True") {
			$('#membersArea').fadeIn(500);
		}
		
		//If server returns a denied authentication message, write jquery to display message box, and unset session variable
		if (msgDenied != "") {
		$("#disablePage").css("width", $(document).width() + "px");
		$("#disablePage").css("height", $(document).height() + "px");
		$("#disablePage").css("filter", "alpha(opacity=50)");
		$("#messageBox").css("left", ($(document).width() / 2) - 150 + "px");
		$("#disablePage").fadeIn();
		$("#messageBox").fadeIn(1000);
		}
		
		//If server returns a message from the Reset Password Form, display message box, that contains no option to close, and unset session variable
		if (msgNoClose != "") {
		$("#disablePage").css("width", $(document).width() + "px");
		$("#disablePage").css("height", $(document).height() + "px");
		$("#disablePage").css("filter", "alpha(opacity=50)");
		$("#messageBox2").css("left", ($(document).width() / 2) - 150 + "px");
		$("#disablePage").fadeIn();
		$("#messageBox2").fadeIn(1000);
		}
		
		//If server returns a flag, write jquery to display the reset password form
		if (Flag == "True") {
		subForm = 3;
		$("#disablePage").css("width", $(document).width() + "px");
		$("#disablePage").css("height", $(document).height() + "px");
		$("#disablePage").css("filter", "alpha(opacity=50)");
		$("#changePass").css("left", ($(document).width() / 2) - 150 + "px");
		$("#disablePage").fadeIn();
		$("#changePass").fadeIn(1000);
		}
		
		//Set positioning of form windows
		$("#forgotPass").css("left", ($(document).width() / 2) - 150 + "px");
		$("#changePass").css("left", ($(document).width() / 2) - 150 + "px");
		
		
		//------------------------------------Event Triggers & Methods--------------------------------
		
		//When login form is submitted, remove the submit image and replace with loading image
		//The loading image is a background image hidden at startup.
		$('#frmLogin').submit(function() {
			$('#btnSubmitImage').remove();
			$('#btnSubmit').show();
		});
		
		$('#btnSubmitImage').click(function() {
			$('#btnSubmitImage').remove();
			$('#btnSubmit').show();
		});
		
		
		//When forgot password form is submitted, remove the submit image and replace with loading image
		//The loading image is a background image hidden at startup.
		$('#frmPass').submit(function() {
			$('#btnSubmitPassImage').remove();
			$('#btnSubmitPass').show();
		});
		
		$('#btnSubmitPassImage').click(function() {
			$('#btnSubmitPassImage').remove();
			$('#btnSubmitPass').show();
		});
		
		
		//When change password form is submitted, remove the submit image and replace with loading image
		//The loading image is a background image hidden at startup.
		$('#frmPWChange').submit(function() {
			$('#btnSubmitPWCImage').remove();
			$('#btnSubmitPWC').show();
		});
		
		$('#btnSubmitPWCImage').click(function() {
			$('#btnSubmitPWCImage').remove();
			$('#btnSubmitPWC').show();
		});
		
		
		//When the login tab, or tab link, is clicked, toggle the login menu to be shown and hidden
		$("#loginTabIn->a#login").click(function() {
			subForm = 1;
			$("#loginMenu").slideToggle();
		});
		
		$("#loginTabIn").click(function() {
			subForm = 1;
			$("#loginMenu").slideToggle();
		});
		
		
		//When the close button is clicked in the message box, fade out message system and show the login menu.
		$('a#messageClose').click(function() {
			subForm = 1;
			$('#disablePage').fadeOut(1000);
			$('#messageBox').fadeOut();
			$("#loginMenu").slideToggle();
		});
		
		
		//When the close button is clicked in the forgot password box, fade out message system and show the login menu.
		$('a#forgotPassClose').click(function() {
			subForm = 1;
			$('#disablePage').fadeOut(1000);
			$('#forgotPass').fadeOut();
			$("#loginMenu").slideToggle();
		});
		
		
		//When the close button is clicked in the reset password box, fade out message system.
		$('a#changePassClose').click(function() {
			$('#disablePage').fadeOut(1000);
			$('#changePass').fadeOut();
			//$("#loginMenu").slideToggle();
		});
		
		
		$('#btnOK').click(function() {
			//$('#disablePage').fadeOut(1000);
			subForm = 2;
			$('#messageBox').fadeOut();
			$('#forgotPass').fadeIn();
			//$("#loginMenu").slideToggle();
		});
		
		
		$('#btnOKSubmit').click(function() {
			$('#disablePage').fadeOut(1000);
			$('#messageBox').fadeOut();
			//$('#forgotPass').fadeIn();
			//$("#loginMenu").slideToggle();
		});
		
		
		$('#btnOKReset').click(function() {
			//$('#disablePage').fadeOut(1000);
			subForm = 3;
			$('#messageBox').fadeOut();
			$('#changePass').fadeIn();
			//$("#loginMenu").slideToggle();
		});
		
		
		$('#btnOKToggle').click(function() {
			subForm = 1;
			$('#disablePage').fadeOut(1000);
			$('#messageBox').fadeOut();
			$("#loginMenu").slideToggle();
		});
		
		
		//When enter key is used, submit the login form and return false to omit error beep in IE
		//This is mainly a work around for IE
		$(document).keydown(function(event) { 
        	if (event.keyCode == 13) { 
				if (subForm == 1) {
					$("#frmLogin").submit();
					return false; 
				}
				if (subForm == 2) {
					$("#frmPass").submit();
					return false; 
				}
				if (subForm == 3) {
					$("#frmPWChange").submit();
					return false; 
				}
        	} 
        }); 
		
		
		//When the forgot password button is clicked on the login menu, display forgot password message box
		$('#btnPassImage').click(function() {
			subForm = 2;
			$("#disablePage").css("width", $(document).width() + "px");
			$("#disablePage").css("height", $(document).height() + "px");
			$("#disablePage").css("filter", "alpha(opacity=50)");
			$("#forgotPass").css("left", ($(document).width() / 2) - 150 + "px");
			$("#disablePage").fadeIn();
			$("#forgotPass").fadeIn(1000);
			$("#loginMenu").slideToggle();
		});
		
		
 

    	$('#fileTree').fileTree({ root: 'members/', script: 'jquery/jqueryFileTree/connectors/jqueryFileTree.php' }, function(file) {  
        	//alert(file);
			//openFile(file);
			window.open(file);
    	});  
		
		function openFile(file) {  
    		window.open(this.href);
			return false; 
		}  
	
		/*var $status = $('<div id="status"><span></span></div>').hide();
		var $statusText = $status.find("span");
		$("#status_container").append($status);
	
		$("#frmLogin").jCryption({
			collectionSpeed:300, 
			encryptionSpeed:300,
			submitTrigger:"#btnSubmitImage",
			//submitEvent:"click"
			beforeEncryption:function() {
				$statusText.text("Loading Keys ...").parent().show();
				return true;
			},
			inputCollectorCallback:function(counter,objectLength) {
				$statusText.text("Collecting Input: "+(counter+1)+" of "+objectLength);
			},
			encryptionCallback:function(counter,objectLength) {
				$statusText.text("Encrytion Status: "+Math.round((counter/objectLength)*100)+"%");
			},
			encryptionFinished:function(encryptedString, objectLength) {
				$statusText.text("Completed! submitting form");
				return true;
			}
		});//.find("fieldset").fillInForm();
	
		//$("input,select,textarea").removeAttr("disabled");*/
		//--------------------------------------------------
	
});
