$('document').ready(function() {
	$('.LightBox a').lightBox();
	$('div.form .errors').hide();

	/*
	* Set up form submissions
	*/

	$('.form form').submit(function(e) {
		e.preventDefault()
		/*
		* Generate a random class to identify the form
		*/
		$(this).addClass('ActiveForm');
		$('div.form .errors').fadeOut(100);
		$.post($(this).attr('action'),
			$(this).serialize(),
			function (json) {
				if(json.success == true) {
					$('form.ActiveForm').fadeOut(1000, function() {
						$('form.ActiveForm').empty().html("<div class='errors'>Thanks</div>").fadeIn(1000);
					});

				}
				else {
					$('form.ActiveForm .errors').empty().fadeIn(1000);
					for(x in json.errors) {
						$('form.ActiveForm div.errors').append("<p>" + json.errors[x] + "</p>");
					}
				}
				$('form.ActiveForm div.errors')
			},'json'
		);
	})
	$('#tln a').button();
	$('#tln li').css('margin','0px');
	$('#tln ul').buttonset();
	var h = '0';
	$('.Caption a').each(function () {
		$(this).children('img').css('margin','0px 0px 4px 0px');
		$('<div></div>').appendTo('.Caption').append(this).css({
			'float': 'left',
			'padding': '8px 8px 8px 8px',
			'margin': '5px',
			'background': '#eff',
			'width': '142px'
		}).mouseenter(function () {
			$(this).css({
				'background': '#bcc'
			});
		}).mouseleave(function () {
			$(this).css({
				'background': '#eff'
			})
		}).append($('<p></p>').text($(this).attr('title')));
		if(h < $(this).parent().height()) h = $(this).parent().height();
	});
	$('.Caption div').css('height', h +'px');
});


