var numArrows = 3;
$(document).ready(
	function () {
		$('form.validate').bind('submit',
			function (e) {
				message = $(this).attr('rel');
				labels = $(this).find('label.mandatory');
				len = labels.length;
				for(i = 0; i < len; i++) {
					id = $(labels[i]).attr('for');
					field = $(labels[i]).html();
					if ($('#' + id).val().length < 1) {
						alert(message + ' ' + field);
						return false;
					}
				}
			}
		);


		$('input.submit').each(
			function (e) {
				var rand = Math.round(Math.random()* 999999);
				$(this).replaceWith('<div class="button small" id="button-' + rand + '"><a href="#">' + $(this).val() + '</a></div>');
				$('#button-' + rand).click(function (e) {$('#button-' + rand).parent('form').submit()});
			}
		);
		if ($.browser.msie && $.browser.version == 6) {
			$('.column').css('position', 'relative');
			$('#topListHolder').css('left', '0px');
			$('.side-menu-holder').css('left', '0px');
		}
		$('ul.bordered li:first').css('padding-top', '0');
		$('ul.bordered li:last').css('padding-bottom', '0');
		$('div.bodyText p ~ ul').css('margin-top', '-20px');
		$('.box p:last-child').css('padding-bottom', '0');
		$('div.menu-item:not(.selected)').hover(
				function (e) {
					$(this).addClass('hovered');
				},
				function (e) {
					$(this).removeClass('hovered');
				}
		);
		setTimeout("fadeArrow(1);", 3000);
		$('#topListBorder').height($('.topList').height() - 10);
	}
);
function fadeArrow(arrow) {
	if (arrow == numArrows) {
		var nextCode = 'resetArrowLoop();';
	} else {
		var next = arrow + 1;
		var nextCode = 'fadeArrow(' + next + ');';
	}
	$('#arrow' + arrow).fadeIn(800,
		function () {
			setTimeout(nextCode, 800);
		}
	);
}
function resetArrowLoop() {
	$('.arrow').fadeOut(1600);
	setTimeout('fadeArrow(1)', 2400);
}
