var ddsmoothmenu={arrowimages:{down:["downarrowclass","/graphics/down.gif",23],right:["rightarrowclass","right.gif"]},transition:{overtime:300,outtime:300},shadow:{enable:true,offsetx:5,offsety:5},showhidedelay:{showdelay:100,hidedelay:200},detectwebkit:navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1,detectie6:document.all&&!window.XMLHttpRequest,css3support:window.msPerformance||(!document.all&&document.querySelector),getajaxmenu:function($,setting){var $menucontainer=$("#"+setting.contentsource[0]);$menucontainer.html("Loading Menu...");$.ajax({url:setting.contentsource[1],async:true,error:function(ajaxrequest){$menucontainer.html("Error fetching content. Server Response: "+ajaxrequest.responseText)},success:function(content){$menucontainer.html(content);ddsmoothmenu.buildmenu($,setting)}})},buildmenu:function($,setting){var smoothmenu=ddsmoothmenu;var $mainmenu=$("#"+setting.mainmenuid+">ul");$mainmenu.parent().get(0).className=setting.classname||"ddsmoothmenu";var $headers=$mainmenu.find("ul").parent();$headers.hover(function(e){$(this).children("a:eq(0)").addClass("selected")},function(e){$(this).children("a:eq(0)").removeClass("selected")});$headers.each(function(i){var $curobj=$(this).css({zIndex:100-i});var $subul=$(this).find("ul:eq(0)").css({display:"block"});$subul.data("timers",{});this._dimensions={w:this.offsetWidth,h:this.offsetHeight,subulw:$subul.outerWidth(),subulh:$subul.outerHeight()};this.istopheader=$curobj.parents("ul").length==1?true:false;$subul.css({top:this.istopheader&&setting.orientation!="v"?this._dimensions.h+"px":0});$curobj.children("a:eq(0)").css(this.istopheader?{paddingRight:smoothmenu.arrowimages.down[2]}:{}).append('<img src="'+(this.istopheader&&setting.orientation!="v"?smoothmenu.arrowimages.down[1]:smoothmenu.arrowimages.right[1])+'" class="'+(this.istopheader&&setting.orientation!="v"?smoothmenu.arrowimages.down[0]:smoothmenu.arrowimages.right[0])+'" style="border:0;">');if(smoothmenu.shadow.enable&&!smoothmenu.css3support){this._shadowoffset={x:(this.istopheader?$subul.offset().left+smoothmenu.shadow.offsetx:this._dimensions.w),y:(this.istopheader?$subul.offset().top+smoothmenu.shadow.offsety:$curobj.position().top)};if(this.istopheader){$parentshadow=$(document.body)}else{var $parentLi=$curobj.parents("li:eq(0)");$parentshadow=$parentLi.get(0).$shadow}this.$shadow=$('<div class="ddshadow'+(this.istopheader?" toplevelshadow":"")+'"></div>').prependTo($parentshadow).css({left:this._shadowoffset.x+"px",top:this._shadowoffset.y+"px"})}$curobj.hover(function(e){var $targetul=$subul;var header=$curobj.get(0);clearTimeout($targetul.data("timers").hidetimer);$targetul.data("timers").showtimer=setTimeout(function(){header._offsets={left:$curobj.offset().left,top:$curobj.offset().top};var menuleft=header.istopheader&&setting.orientation!="v"?0:header._dimensions.w;menuleft=(header._offsets.left+menuleft+header._dimensions.subulw>$(window).width())?(header.istopheader&&setting.orientation!="v"?-header._dimensions.subulw+header._dimensions.w:-header._dimensions.w):menuleft;if($targetul.queue().length<=1){$targetul.css({left:menuleft+"px",width:header._dimensions.subulw+"px"}).animate({height:"show",opacity:"show"},ddsmoothmenu.transition.overtime);if(smoothmenu.shadow.enable&&!smoothmenu.css3support){var shadowleft=header.istopheader?$targetul.offset().left+ddsmoothmenu.shadow.offsetx:menuleft;var shadowtop=header.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety:header._shadowoffset.y;if(!header.istopheader&&ddsmoothmenu.detectwebkit){header.$shadow.css({opacity:1})}header.$shadow.css({overflow:"",width:header._dimensions.subulw+"px",left:shadowleft+"px",top:shadowtop+"px"}).animate({height:header._dimensions.subulh+"px"},ddsmoothmenu.transition.overtime)}}},ddsmoothmenu.showhidedelay.showdelay)},function(e){var $targetul=$subul;var header=$curobj.get(0);clearTimeout($targetul.data("timers").showtimer);$targetul.data("timers").hidetimer=setTimeout(function(){$targetul.animate({height:"hide",opacity:"hide"},ddsmoothmenu.transition.outtime);if(smoothmenu.shadow.enable&&!smoothmenu.css3support){if(ddsmoothmenu.detectwebkit){header.$shadow.children("div:eq(0)").css({opacity:0})}header.$shadow.css({overflow:"hidden"}).animate({height:0},ddsmoothmenu.transition.outtime)}},ddsmoothmenu.showhidedelay.hidedelay)})});if(smoothmenu.shadow.enable&&smoothmenu.css3support){var $toplevelul=$("#"+setting.mainmenuid+" ul li ul");var css3shadow=parseInt(smoothmenu.shadow.offsetx)+"px "+parseInt(smoothmenu.shadow.offsety)+"px 5px #aaa";var shadowprop=["boxShadow","MozBoxShadow","WebkitBoxShadow","MsBoxShadow"];for(var i=0;i<shadowprop.length;i++){$toplevelul.css(shadowprop[i],css3shadow)}}$mainmenu.find("ul").css({display:"none",visibility:"visible"})},init:function(setting){if(typeof setting.customtheme=="object"&&setting.customtheme.length==2){var mainmenuid="#"+setting.mainmenuid;var mainselector=(setting.orientation=="v")?mainmenuid:mainmenuid+", "+mainmenuid;document.write('<style type="text/css">\n'+mainselector+" ul li a {background:"+setting.customtheme[0]+";}\n"+mainmenuid+" ul li a:hover {background:"+setting.customtheme[1]+";}\n</style>")}this.shadow.enable=(document.all&&!window.XMLHttpRequest)?false:this.shadow.enable;jQuery(document).ready(function($){if(typeof setting.contentsource=="object"){ddsmoothmenu.getajaxmenu($,setting)}else{ddsmoothmenu.buildmenu($,setting)}})}};
(function(a){a.fn.tabSlideOut=function(k){var e=a.extend({tabHandle:".handle",speed:300,action:"click",tabLocation:"left",topPos:"200px",leftPos:"20px",fixedPosition:false,positioning:"absolute",pathToTabImage:null,imageHeight:null,imageWidth:null,onLoadSlideOut:false},k||{});e.tabHandle=a(e.tabHandle);var f=this;if(e.fixedPosition===true){e.positioning="fixed"}else{e.positioning="absolute"}if(document.all&&!window.opera&&!window.XMLHttpRequest){e.positioning="absolute"}if(e.pathToTabImage!=null){e.tabHandle.css({background:"url("+e.pathToTabImage+") no-repeat",width:e.imageWidth,height:e.imageHeight})}e.tabHandle.css({display:"block",textIndent:"-99999px",outline:"none",position:"absolute"});f.css({"line-height":"1",position:e.positioning});var i={containerWidth:parseInt(f.outerWidth(),10)+"px",containerHeight:parseInt(f.outerHeight(),10)+"px",tabWidth:parseInt(e.tabHandle.outerWidth(),10)+"px",tabHeight:parseInt(e.tabHandle.outerHeight(),10)+"px"};if(e.tabLocation==="top"||e.tabLocation==="bottom"){f.css({left:e.leftPos});e.tabHandle.css({right:0})}if(e.tabLocation==="top"){f.css({top:"-"+i.containerHeight});e.tabHandle.css({bottom:"-"+i.tabHeight})}if(e.tabLocation==="bottom"){f.css({bottom:"-"+i.containerHeight,position:"fixed"});e.tabHandle.css({top:"-"+i.tabHeight})}if(e.tabLocation==="left"||e.tabLocation==="right"){f.css({height:i.containerHeight,top:e.topPos});e.tabHandle.css({top:0})}if(e.tabLocation==="left"){f.css({left:"-"+i.containerWidth});e.tabHandle.css({right:"-"+i.tabWidth})}if(e.tabLocation==="right"){f.css({right:"-"+i.containerWidth});e.tabHandle.css({left:"-"+i.tabWidth});a("html").css("overflow-x","hidden")}e.tabHandle.click(function(l){l.preventDefault()});var d=function(){if(e.tabLocation==="top"){f.animate({top:"-"+i.containerHeight},e.speed).removeClass("open")}else{if(e.tabLocation==="left"){f.animate({left:"-"+i.containerWidth},e.speed).removeClass("open")}else{if(e.tabLocation==="right"){f.animate({right:"-"+i.containerWidth},e.speed).removeClass("open")}else{if(e.tabLocation==="bottom"){f.animate({bottom:"-"+i.containerHeight},e.speed).removeClass("open")}}}}};var g=function(){if(e.tabLocation=="top"){f.animate({top:"-3px"},e.speed).addClass("open")}else{if(e.tabLocation=="left"){f.animate({left:"-3px"},e.speed).addClass("open")}else{if(e.tabLocation=="right"){f.animate({right:"-3px"},e.speed).addClass("open")}else{if(e.tabLocation=="bottom"){f.animate({bottom:"-3px"},e.speed).addClass("open")}}}}};var c=function(){f.click(function(l){l.stopPropagation()});a(document).click(function(){d()})};var j=function(){e.tabHandle.click(function(l){if(f.hasClass("open")){d()}else{g()}});c()};var h=function(){f.hover(function(){g()},function(){d()});e.tabHandle.click(function(l){if(f.hasClass("open")){d()}});c()};var b=function(){d();setTimeout(g,500)};if(e.action==="click"){j()}if(e.action==="hover"){h()}if(e.onLoadSlideOut){b()}}})(jQuery);

ddsmoothmenu.init({
  mainmenuid: "menu", //menu DIV id
  orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
  classname: 'ddsmoothmenu', //class added to menu's outer DIV
  //customtheme: ["#1c5a80", "#18374a"],
  contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
});

$slide = $('.slide-out-div');
$slide.tabSlideOut({
  tabHandle: '.handle',                              //class of the element that will be your tab
  pathToTabImage: '/images/contact_us.png',          //path to the image for the tab *required*
  imageHeight: '130px',                               //height of tab image *required*
  imageWidth: '40px',                               //width of tab image *required*
  tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
  speed: 300,                                        //speed of animation
  action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
  topPos: 250 + 'px',                                   //position from the top
  fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
});

function clearForm($form) {
  $form.find(':input').each(function() {
    switch(this.type) {
        case 'password':
        case 'select-multiple':
        case 'select-one':
        case 'text':
        case 'textarea':
        case 'email':
        case 'tel':
            $(this).val('');
            break;
        case 'checkbox':
        case 'radio':
            this.checked = false;
    }
  });
}

var formErrors = false;

function showError($elem) {
  $error = $('#' + $elem.attr('error-elem'));
  $elem.addClass('error');
  $error.html($elem.attr('title'));
  $error.width($elem.width());
  $error.show();
  //console.log($('#' . $elem.attr('error-elem')));
}

function hideError($elem) {
  $elem.removeClass('error');
  $error = $('#' + $elem.attr('error-elem'));
  $error.hide();
}

function validateEmail($form) {
  email = /((([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?/;
  $form.find('input[type=email]').each(function() {
    $this = $(this);
    hideError($this);
    if (!email.test($this.val())) {
      showError($this);
      formErrors = true;
    }
  });
}

function validateTel($form) {
  phone = /([\+][0-9]{1,3}([ \.\-])?)?([\(]{1}[0-9]{3}[\)])?([0-9A-Z \.\-]{1,32})((x|ext|extension)?[0-9]{1,4}?)/;
  $form.find('input[type=tel]').each(function() {
    $this = $(this);
    hideError($this);
    if (!phone.test($this.val())) {
      showError($this);
      formErrors = true;
    }
  });
}

function validateText($form) {
  $form.find('textarea,input[type=text],input[type=password]').each(function() {
    $this = $(this);
    hideError($this);
    if (!$this.val()) {
      showError($this);
      formErrors = true;
    }
  });
}

$(document).ready(function() {
  $form2 = $("#contactForm2");
  $slide.click(function() {
    $form2.find('input,textarea').each(function() {
      hideError($(this));
    });
  });
  if (document.QuestionEntry) {
    document.QuestionEntry.JavaScript.value = true;
    $support = $("form[name=QuestionEntry]");
    $support.submit(function() {
      formErrors = false;
      validateText($support);
      if (formErrors) {
        return false;
      }
      return true;
    });
  }

  $form2.submit(function() {
    formErrors = false;
    validateText($form2);
    validateEmail($form2);
    validateTel($form2);
    if (formErrors) {
      $('.slide-out-div').height('auto');
      return false;
    }
    dataString = $form2.serialize();
    $.post('/scripts/ajax_mail.php', dataString, function(data) {
      if (data.success) {
        $('#messages').removeClass('woops').addClass('success').html(data.message);
        clearForm($form2);
        $('a.handle').click();
      }
      else {
        $('#messages').removeClass('success').addClass('woops').html(data.message);
      }
    });
    return false;
  });
  $form = $("#contactForm");
  $form.submit(function() {
    formErrors = false;
    validateText($form);
    validateEmail($form);
    validateTel($form);
    if (formErrors) {
      return false;
    }
    dataString = $form.serialize();
    $.post('/scripts/ajax_mail.php', dataString, function(data) {
      if (data.success) {
        $('#messages').removeClass('woops').addClass('success').html(data.message);
        clearForm($form);
      }
      else {
        $('#messages').removeClass('success').addClass('woops').html(data.message);
      }
    });
    return false;
  });
});

