jQuery(document).ready(function($) {
	$('#navigation li:last-child, #sidebar .widget:last').addClass('last');
	$('ul.sub-menu').hide();
	
	$('#navigation ul li').hover(function() {
		$(this).find('ul.sub-menu:eq(0)').stop(true,true).show();
		$(this).find('a:eq(0)').addClass('hover');
	},
	function() {
		$(this).find('ul.sub-menu').stop(true,true).hide();
		$(this).find('a:eq(0)').removeClass('hover');
	});

	// Bottom boxes eaqualize height
	(function() {
		var bottomBoxes = $('#main .bottom-boxes');
		var boxLeft = bottomBoxes.find('.left');
		var boxRight = bottomBoxes.find('.right');
		
		$(window).load(function() {
			if (boxLeft.height() > boxRight.height()) {
				boxRight.height(boxLeft.height());
			} else if (boxRight.height() > boxLeft.height()) {
				boxLeft.height(boxRight.height());
			}
		});
	})();
	
	//Fader
	$('#fader').innerfade({
		speed: 'slow',
		timeout: 4000,
		type: 'sequence',
		containerheight: '220px'
	});
	
	//PNG FIX for IE6
	if($.browser.msie && $.browser.version.substr(0,1) == 6 ){
		DD_belatedPNG.fix('#main.home-b .intro-box, #main.home-b .intro-box ul.check li, #main.home-b .intro-box p.tell-me-more a')
	}
	
	$('.validate').submit(function() {
		var valid = true;
		var errors = '';
		
		$(this).find('.required').each(function() {
			if ($(this).val() == '') {
				$(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 + '\n ');
			return false;
		}
		
		return cr_submit(this, 1);
	});
});

