$(document).ready(function() {

	//if loggined, the name should be printed to show the number of messages
	//for a researcher or number of researchers for an establishment. When the
	//name is too long, the size should be re-adjusted.
	var $name = $('#message a');
	if($name.text().length > 50) {
		$name.addClass('small');
	}
	$name.show();

	var first = true;
	$('#nl_mail').click(function() {
		if(first) {
			$(this).val('').css('color', '#000');
			first = false;
		}
	});

	$('#nl_submit').click(function(event) {
		$this = $(this);
		$this.prev().attr('disabled', 'disabled');
		$.post(
			$this.parent().attr('action'),
			{mail: $this.prev().val()},
			function(responseText) {
				$this.prev().attr('disabled', '');
				if(responseText.indexOf('ok') != -1) {
					$this.prev().val('');
					$('p.ok', $this.parent()).fadeIn();
				}else if(responseText.indexOf('format') != -1) {
					$('p.error', $this.parent()).eq(0).fadeIn();
				}else {
					$('p.error', $this.parent()).eq(1).fadeIn();
				}
				setTimeout("$('p', $this.parent()).fadeOut();", 3000);
			}
		);

		event.preventDefault();
	});

	//for a IE 6 bug
	if($.browser.msie && $.browser.version == '6.0') {
		$('#container').css('height', '1615px');
		$('#content').css('height', '1515px');
	}

	//this page is the only one that is long, so everytime the window is scrolled up or down,
	//the search, domain and partner elements should be moved accordingly to be shown in the browser.
	$('#search').scrollFollow();
	$('#domain').scrollFollow({offset:50});
	$('#partner').scrollFollow({offset:335});
	$('#consulate').scrollFollow({offset:500});


	//in the message zone, add another link if there is one
	var $link_message = $('#message p a');
	if ($link_message.length) {
		$('<a></a>')
		.attr('href', $link_message.attr('href'))
		.css({
			'width': '90px',
			'height': '54px',
			'position': 'absolute',
			'top': '26px',
			'right': '18px'
		})
		.appendTo('#message');
	}
});

