function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
  var r = obj.attachEvent("on"+evType, fn);
  return r;
  } else {
    return false;
  }
}

function isValid(type, str) {
  if (type.toLowerCase() == "email") {
    if ((str == null) || (str == "")) return false;
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1) return false;
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
    if (str.indexOf(at,(lat+1))!=-1) return false;
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
    if (str.indexOf(dot,(lat+2))==-1) return false;
    if (str.indexOf(" ")!=-1) return false;
    return true;
  }
};

(function($) {
  $(function() {
    $("input[type=text][title]").each(function() { $(this).val($(this).attr("title")); if($.trim($(this).val()) == "") $(this).val($(this).attr("title")); $(this).focus(function() { if($(this).val() == $(this).attr("title")) $(this).val(""); }).blur(function() { if($.trim($(this).val()) == "") $(this).val($(this).attr("title")); }); });
    $("a[href][rel*=external]").each(function() { $(this).attr("target", "_blank"); });
    
    $("form#email-marketing-form").submit(function() {
      if(!isValid("email", this.email.value)) { alert("Please enter a valid email"); return false; }
      this.event.value = "emailmarketing.contact.add.ajax";
      jQuery.post("index.cfm", $(this).serializeArray(), function(data){
        $(data).find("success").each(function() {
          $("#email-marketing-message").text($(this).text());
        });
      });
      return false;
    });
  });
})(jQuery);

$(document).ready(function(){  

	var config = {
		sensitivity: 3,
		interval: 150,
		over: makeTall,
		timeout: 0,
		out: makeShort
	}
	
	$("div.menu").hoverIntent(config);
	
	function makeTall() 
	{ //When list item is hovered over ... 
		$(this).find("ul.subnav").fadeIn('fast').show()
	}

	function makeShort()
	{
		$(this).parent().find("ul.subnav").fadeOut('slow'); //When the mouse hovers out of the subnav, move it back up  
	}
})