(function (window){
	// This is our namespace.
	var docready = function (){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			opacity:0.25,
			theme: 'facebook',
			default_width: 808,
			default_height: 612,
			allowresize: false,
			flash_markup: ''+
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}">'+
					'<param name="wmode" value="{wmode}" />'+
					'<param name="allowfullscreen" value="true" />'+
					'<param name="allowscriptaccess" value="always" />'+
					'<param name="movie" value="{path}" />'+
					'<param name="salign" value="tl" />'+
					'<param name="scale" value="noorder" />'+
					'<embed src="{path}" salign="tl" scale="noorder" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed>'+
				'</object>'
		});

		$('form').each(function (){
			var form = $(this),
			required_text = $(this).children('input[name="required"]').attr('value'),
			required_fields = required_text.split(','),
			is_valid_input = function (){
				var ii, field, input, val, has_checked = false, valid = true;

				for (ii in required_fields){
					field = required_fields[ii];

					input = form.find('input[name="' + field + '"]');
					val = input.val();

					if (input.attr('type') === 'radio'){
						input.each(function (){
							if (this.checked){
								has_checked = true;
							}
						});
						if (!has_checked){
							input.siblings('.question-text').addClass('input-invalid');
							valid = false;
						}else{
							input.siblings('.question-text').removeClass('input-invalid');
						}
						// Reset for the next radio buttons.
						has_checked = false;
					} else {
						if (typeof(val) == 'undefined' || val == null || val == ''){
							input.addClass('input-invalid');
							valid = false;
						} else {
							input.removeClass('input-invalid');
						}
					}
				}

				return valid;
			};

			$(this).submit(function (){
				return is_valid_input();
			});
		});
	};

	window.docready = docready;
})(window);

