$(document).ready(function(){ 


setInterval ( "update()", 5000 );


	$("#privacy_container").hide();
	$("#show_privacy").click(function(){
		$("#privacy_container").slideToggle();
	});
	
	$("#passrec_newpass").keyup(function(){
		if($(this).val().length >= 6)
			show_notification($(this), null);
		else
			show_notification($(this), $(this).siblings('input[name="passrec_notification"]').val());
		$("#passrec_retypepass").keyup();
	});
	
	$("#passrec_retypepass").keyup(function(){
		if($(this).val() == $("#passrec_newpass").val())
			show_notification($(this), null);
		else
			show_notification($(this), $(this).siblings('input[name="passrec_notification"]').val());
	});

	$("#login").focus();
	
	$('.registration-ships select').change(function(){
		$(this).parents('form:first').submit();
		$('.registration-ships .waiter').css('height', '100%');
	});
	
	$('.registration-ship a').hover(function(){
		$(this).find('img').css('opacity', '0.9');
	}, function(){
		$(this).find('img').css('opacity', '1');
	});
	
	$('.registration-ships .blinking-arrow').blink({delay:1000});

}); 

function show_notification(elem, error)
{
	var nast = $('<div class="registration-notification"></div>');
	$(elem).parents('td:first').find('.registration-notification').remove();
	$(elem).parents('td:first').append(nast);
	$(nast).css('font-weight', 'bold');
	$(nast).css('color', '#FFFFFF');
	if (error) {
		$(nast).html(error);
		$(nast).css('background-color', 'red');
	}
	else
	{
		$(nast).text("OK");
		$(nast).css('background-color', '#80c330');
	}
	
}

function update ( )
{
  $.ajax({
  url: '/main/get_sailors',
  success: function(data) {
        $('.mates h2').html("Mates "+data);
    }
  });

  $.ajax({
  url: '/main/get_time',
  success: function(data) {
        $('.footer-clock').html(data);
    }
  });

    $.ajax({
  url: '/main/get_date',
  success: function(data) {
        $('.footer-date').html(data);
    }
  });
}
