//******************************************
// FaceBox For Portfolio
//******************************************
jQuery(document).ready(function($) {
	      $('a[rel*=facebox]').facebox({
	        loading_image : '/images/facebox/loading.gif',
	        close_image   : '/images/facebox/x.png'
	      }) 
	    })

//******************************************
// Added Code for Phone Validation
//******************************************
	$.validator.addMethod("phone", function(ph, element) {
		if (ph == null) {
			return false;
				}
					var stripped = ph.replace(/[\s()+-\.]|ext\.?/gi, "");
					// 10 is the minimum number of numbers required
					return ((/\d{10,}/i).test(stripped));
			});	
//******************************************
// Masking Input Fields.
//******************************************
jQuery(function($){   
	$("#date").mask("99/99/9999");   
	$("#PhoneNumber").mask("(999) 999-9999");   
	$("#tin").mask("99-9999999");   
	$("#ssn").mask("999-99-9999");
});

//******************************************
// AutoGrow TextArea
//******************************************
$(document).ready (function() {		$('textarea.expanding').autogrow({
		maxHeight: 800,
		minHeight: 30,
		lineHeight: 24
	});							
});

//******************************************
// Port Accordion & Body Rounders
//******************************************
jQuery().ready(function(){
							jQuery('#list1b').accordion({
								autoheight: false,
								alwaysOpen:false
							});
							
							$('#list1b').activate(false);
							//$("#list1b").activate("a:SolPerS")
							//$('#enable').click(function() {
							//	accordions.accordion("enable");
							//});
							//$("#mainBody").corner("round tr cc:#000 8px");
							//$("#mainBody").corner("round tl cc:#000 8px");
					        $("#footer").corner("dog bl cc:#fff 15px");
							$("#footer").corner("round br cc:#fff 8px");
						});

//******************************************
// AJax Stuff
//******************************************
	jQuery(function() {
		// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="/images/tooltip/loader.gif" alt="loading..." /></div>')
			.css({position: "relative", top: "0", left: "0"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		});
//******************************************
// Validation Starts Here
//******************************************	
	$().ready(function() {
		var validator = $("#texttests").bind("invalid-form.validate", function() {
		}).validate({
			//debug: true,
			errorElement: "em",
			errorPlacement: function(error, element) {
			error.appendTo( element.parent("div").next("div") );
			},
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#CFormMain"
				});
			},
			success: function(label) {
				label.text("ok!").addClass("success");
			},
			rules: {
				fullname: {
				required: true
				},
				
				Budget: {
				required: true
				},
				
				PhoneNumber: {
				required: true,
				phone:true
				},
				
				TimeFrame : {
				required: true
				},
				
				comments: {
				required: true,
				minlength:3
				},
				
				email: {
				required: true,
				email: true
				}
			}
		});
		
	});
