    $(document).ready(function(){ 
    
		// open external links in new window - class="external"
		$('a[rel="external"]').click(function(){
			window.open(this.href);
			return false;
		}).attr('title', 'Opens in New Window or Tab');


		// fix PNGs for IE6
        $(document).pngFix(); 
		
		// add sliding doors SPAN tag for buttons
		$("a.gray_button").wrapInner("<span class='button_bkg'></span>");
		$("a.yellow_button").wrapInner("<span class='button_bkg'></span>");
		$("a.yellow_round_button").wrapInner("<span class='button_bkg'></span>");
		$("a.yellow_button_small").wrapInner("<span class='button_bkg'></span>");
		
		// make A tag function as the submit button for forms
		$("form a.submit_button").click( function() {
	        $(this).parents().filter("form").trigger("submit");
		});
		
		// make last nav element shorter, to emulate right-justification
//		$("ul.sf-menu li:last a").css({"width":"80px"});
//		$("ul.sf-menu li:last a span").css({"width":"80px"});
		
		// hover states for side nav
		$("#sub_sidebar ul.sideNav li a").mouseover(function(){
      		$("span",this).html("&nbsp;&rsaquo;");
    	}).mouseout(function(){
      		$("span:not([class*='current'])",this).empty();
    	});

		
		// validate forms
    	$("#getintouch_form").validate({
   			submitHandler: function(form) {
   				$(form).ajaxSubmit({
   					target: "#getintouch_form_message",
   					success: function() {
   						$("#getintouch_form_message").hide().show("fast");
   						$("#getintouch_form .form_content").hide("fast");
   					}
				});

   			}
		});
    	$("#newsletter_form").validate({
   			submitHandler: function(form) {
   				$(form).ajaxSubmit({
   					target: "#newsletter_form_message",
   					success: function() {
   						$("#newsletter_form_message").hide().show("fast");
   						$("#newsletter_form .form_content").hide("fast");
   					}
				});

   			}
		});
    	$("#contact_form").validate({
			errorLabelContainer: "#contact_form .js_message",
//			wrapper: "div",
   			groups: {
   				allfields : "Name Email Message"
   			},
   			messages: {
   				Name : "Please enter the required information.",
   				Email : "Please enter the required information.",
   				Message : "Please enter the required information."
   			},
   			submitHandler: function(form) {
   				$(form).ajaxSubmit({
   					target: "#contact_form_message",
   					success: function() {
   						$("#contact_form_message").hide();
   						$("#contact_thanks").hide().show("fast");
   						$("#contact_form .form_content").hide("fast");
   					}
				});
   			}
		});
		
		// create cookie for CAPTCHA alternative security
//		$.get("token.php",function(txt){
//  			$(".js_secure").append('<input type="hidden" name="ts" value="'+txt+'" />');
//		});

		// remove Javascript warning paragraph in form
		$('.js_warning').remove();
		
    }); 
    

function stripEOLN(formElement) {
   for(i=0; i<formElement.elements.length; i++) {
	  formElement.elements[i].value = formElement.elements[i].value.replace(/[\r\n]/g," ");
   }
}
