jQuery(function($) {
	$('p').each(function() {
		if ($(this).text() == '') {
			$(this).remove();
		}
	});
	
	$('#navigation ul li:last-child, .intro ul li:last-child').addClass('last');
	
	$('.gallery dl dt a').attr('rel', 'gallery_item').fancybox({ titlePosition: 'over', cyclic: true });
	
	$('.blink').find('input, textarea')
		.focus(function() {
			if(this.title==this.value) {
				this.value = '';
			}
		})
		.blur(function(){
			if(this.value=='') {
				this.value = this.title;
			}
		});
	
	//PNG FIX for IE6
	if($.browser.msie && $.browser.version.substr(0,1) == 6) {
		DD_belatedPNG.fix('#wrapper, .shell, .inner-page #main .main-head .box-l, .inner-page #main .main-head .box-r');
	}

	$('.validate').submit(function() {
		var valid = true;
		var errors = '';
		
		$(this).find('.required').each(function() {
			if ($(this).val() == '' || $(this).val() == $(this).attr('title')) {
				$(this).addClass('field-error');
				errors += 'The "' + $(this).attr('title') + '" field is required\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		$(this).find('.email').each(function() {
			var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
			
			if (!pattern.test($(this).val())) {
				$(this).addClass('field-error');
				errors += 'The email address you entered is not valid\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		if (!valid) {
			alert(errors);
		}
		
		return valid;
	});
});
