var quotes = {
	target: null,
	init: function(t){
		target = t;
		if (target.children().length > 1) {
			target.children(':first').toggleClass('current');
			setInterval('quotes.rotate()',5000);
		}

	},
	rotate: function(){
		current = target.children('.current');
		next = current.next();
		if (next.length == 0) next = $('#testimonials li:first');
		current.fadeOut(500,function(){
			next.fadeIn(500).toggleClass('current');
		}).toggleClass('current');
	}
};

$(function(){
	quotes.init($('#testimonials ul'));
	$('#carriers ul').slider({
		vertical: true
	});

	$('#quotesform button').click(function(event){
		event.preventDefault();
		var valid = true;
		$('#quotesform .req').each(function(){
	    var name = this.name;
	    var pattern = new RegExp($(this).attr('data-pattern'),"i");
	    var value = this.value;
	    if(pattern.test(value)) {
	    		$('[for='+name+'] .error').hide();
	        $(this).css('background','white');
		    } else {
	    		valid = false;
	        $('[for='+name+'] .error').show();
	        $(this).css('background','pink');
	    }
		});
		if (valid) $('#quotesform').submit();
	})
});
