$(document).ready(function()
{
		
	var hash = '';

	$('#acl_msg').delay(12500).fadeOut(1000);
	
	$("#close_msg").click(function() {	
			$(this).parent().addClass('hidden');
		return false;
	}); 

	$('p.successful_login').delay(1500).animate({ opacity: 'toggle', top: '-=250', left: '+=620', width: 'toggle', height: 'toggle' }, 150 );
	
	$('p.rqst_pswrd_success').delay(12500).fadeOut(1000);
	$('p.failed_login').delay(12500).fadeOut(1000);
	
	if ( $("[name=display_login]").val() == 1 )
	{
		$("#login_button_dv").addClass('hidden');
		$("#site_login_dv").fadeIn(50, function() {
			$("#site_login_dv > a.close_dv")	.animate({ opacity: 'toggle', top: '+=250' }, 150 );
		});
	}
	
	
	$("#login_button").click(function() {	
		hash = $(this).attr('rel');
		location.hash = hash;
//		$("#login_button_dv").fadeOut(50, function() {
//				$("#site_login_dv").fadeIn(150, function() { 
//					$("#site_login_dv > a.close_dv")	.animate({ opacity: 'toggle', top: '+=250' }, 150 );
//				});
//			});
		return false;
	}); 

  $("#site_login_dv > a.close_dv").click(function () {
			location.hash = '';																								
//    $("#site_login_dv").fadeOut(250, function() {
//				$("#login_button_dv").fadeIn(250	);																	
//				$("#site_login_dv > a.close_dv").css({ display: 'none',  top: -250 });
//			});
	  return false;
	});
	
	
	
	$("#rqst_new_password").click(function() {	
		hash = $(this).attr('rel');
		location.hash = hash;
//			$("#rqst_pswrd_dv > a.close_dv")	.css({ display: 'none',  top: -250 });
//				$("#rqst_pswrd_dv").fadeIn(150, function() { 
//					$("#rqst_pswrd_dv > a.close_dv")	.animate({ opacity: 'toggle', top: '+=250' }, 150 );
//					$("#site_login_dv").fadeOut(1);
//			});
		return false;
	}); 

  $("#rqst_pswrd_dv > a.close_dv").click(function () {
			location.hash = '';																								
//    $("#rqst_pswrd_dv").fadeOut(250, function() {
//				$("#login_button_dv").fadeIn(250	);																	
//				$("#site_login_dv > a.close_dv").css({ display: 'none',  top: -250 });
//			});
	  return false;
	});
	
	
	
	
	if ( $("#site_login_dv").html() )
	{
	
		$("#login_form").validate({
			rules: {
					user_name: {
										required: true,
										minlength: 5,
										maxlength: 18
									},
					user_password: {
										required: true,
										minlength: 6,
										maxlength: 18
									}
								},
			messages: {
					username: {
										required: "Please enter your username",
										minlength: "The username field must be at least 5 characters in length"
									},
					password: {
										required: "Please enter your password",
										minlength: "The Password field must be at least 6 characters in length"
									}
								},
				errorClass: "login_error",
				errorElement: "p",
				errorPlacement: function(error, element) {
						error.insertBefore( element.parent("div") );
					}
		});
	
		
		$("#password_form").validate({
				errorClass: "login_error",
				errorElement: "p",
				errorPlacement: function(error, element) {
					 error.insertBefore( element.parent("div") );
				 }
			 });
	
	}
		
	
		$(window).hashchange( function(){
																	 
			var hash = location.hash;
			var overlay = $("#open_overlay").html();
			
			if ( overlay )
			{
				$(overlay).fadeOut(250, function() {
						$("#login_button_dv").fadeIn(250	);																	
						$("#site_login_dv > a.close_dv").css({ display: 'none',  top: -250 });
					});
				document.title = currentPage;
			}

			if ( hash == '#login' )
			{
				$("#open_overlay").html('#site_login_dv');
				$("#login_button_dv").fadeOut(50, function() {
						$("#site_login_dv").fadeIn(150, function() { 
							$("#site_login_dv > a.close_dv")	.animate({ opacity: 'toggle', top: '+=250' }, 150 );
						});
					});
				document.title = hash;
			}
			else if ( hash == '#request-new-password' )
			{
				$('#open_overlay').html('#rqst_pswrd_dv');
				$("#rqst_pswrd_dv > a.close_dv")	.css({ display: 'none',  top: -250 });
					$("#rqst_pswrd_dv").fadeIn(150, function() { 
						$("#rqst_pswrd_dv > a.close_dv")	.animate({ opacity: 'toggle', top: '+=250' }, 150 );
						$("#site_login_dv").fadeOut(1);
				});
				document.title = hash;
			}
	})
	
	$(window).hashchange();

	
	
});


