// JavaScript Document

if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
	
 $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };	
	
var invalidValues = [];	

$(document).ready( function() {

	$('#content img').each( function() { if($(this).width() > 450) { $(this).attr('width','450').css({display: 'block',position: 'relative',float: 'left'}); $(this).closest('table').find('td').each( function() { $('#content').append( $(this).html() ); $(this).hide(); } ); } });
	
	jQuery.validator.addMethod("notdefault", function(value, element) {
		var idx = invalidValues.indexOf(value);
		if(idx == -1) {
			return true;
		}
		else {
			return false;
		}
	}, "This field is required.");  
	
	
	
	$('#haveAQuestion label').each( function() {
		$(this).hide();
		var text = $(this).html();
		if(text.match(/.*/)) {
			invalidValues.push(text);
		}
		
		$(this).parent().find('input').each( function() {
			$(this).val(text);
			
			$(this).blur( function() {
				if($(this).val() == "") {
					$(this).val(text);	
				}
			});
			
			$(this).focus( function() {
				var val = $(this).val()
				if(val == text) {
					$(this).val('');	
				}
			});
		});
		
	    $(this).parent().find('textarea').each( function() {
			$(this).html(text);
			
			$(this).blur( function() {
				var currenthtml = $(this).val() || $(this).html();
				if(currenthtml == "") {
					$(this).html(text);	
				}
			});
			
			$(this).focus( function() {
				var val =  $(this).val() || $(this).html();
				if(val == text) {
					$(this).html('');	
				}
			});
		});		
		
	});
	
	$("#haveAQuestion").validate({submitHandler: function(form) {
			if($('#haveAQuestion').valid()) {
				$.ajax({
				  type: 'POST',
				  url: '/contact/contact_us.asp',
				  data: $("#haveAQuestion").serialize(),
				  success: function(message) {
					  //_gaq.push(['_trackPageview',"/contact/"+window.location.pathname]);
					  urchinTracker("/contact/"+window.location.pathname);
					  $('#haveAQuestion').slideUp("slow", function() {
					$("#haveAQuestion").html('<div>Thanks for contacting us!</div>'); 
					$('#haveAQuestion').slideDown("slow");
					  });
				  }
				});	
			}
			return false;
	 }});
});
