/*********************
//* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
//* "minified"
*********************/
var arrowimages={down:["",""],right:["",""]};var jqueryslidemenu={animateduration:{over:200,out:25},buildmenu:function(a,b){jQuery(document).ready(function(b){b(" #main_navigation a").removeAttr("title");var c=b("#"+a+">ul");var d=c.find("ul").parent();d.each(function(a){var c=b(this);var d=b(this).find("ul:eq(0)");this._dimensions={w:this.offsetWidth,h:this.offsetHeight,subulw:d.outerWidth(),subulh:d.outerHeight()};this.istopheader=c.parents("ul").length==1?true:false;d.css({top:this.istopheader?this._dimensions.h+"px":0});c.hover(function(a){var c=b(this).children("ul:eq(0)");this._offsets={left:b(this).offset().left,top:b(this).offset().top};if(jQuery.browser.msie){var d=this.istopheader?0:this._dimensions.w+2;d=this._offsets.left+d+this._dimensions.subulw>b(window).width()?(this.istopheader?-this._dimensions.subulw+this._dimensions.w:-this._dimensions.w)-4:d}if(!jQuery.browser.msie){var d=this.istopheader?0:this._dimensions.w;d=this._offsets.left+d+this._dimensions.subulw>b(window).width()?this.istopheader?-this._dimensions.subulw+this._dimensions.w:-this._dimensions.w:d}if(c.queue().length<=1)c.css({left:d+"px",width:this._dimensions.subulw+"px"}).slideDown(jqueryslidemenu.animateduration.over)},function(a){var c=b(this).children("ul:eq(0)");c.slideUp(jqueryslidemenu.animateduration.out)});c.click(function(){b(this).children("ul:eq(0)").hide()})});c.find("ul").css({display:"none",visibility:"visible"})})}}

function toggle_trigger(t) {
	$(t).toggleClass("active").next().slideToggle("slow");
}

function toggle_jumpto(t) {
	$(t).toggleClass("active").next().toggle();
}

function validateLength($field) {
   if($field.val().length < 1) {
      return false;
   }
   
   return true;
}

function validateEmail($field) { 
   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 
   return $field.val().match(re);
}

function errorOutBorder($field) {
   $field.attr('old-style', $field.attr('style'));
   $field.attr('style', 'border-color: #5E300D #5E300D #5E300D; border-style: solid; border-width: 2px; color: #666;');
}

function clearOutBorder($field) {
   if($field.attr('old-style') && $field.attr('old-style').length > 0) {
      $field.attr('style', $field.attr('old-style'));
   }
   else {
      $field.attr('style', '');
   }
}

function initContactForm() {
   $("form.vitel-contact").submit(function() {
      var s = true;
      var $test;

      //check name, email, & comments
      $test = $(this).find('[name=contactName]:first');
      if(!validateLength($test)) {
         s = false;
         errorOutBorder($test);
      }
      else {
         clearOutBorder($test);
      }
   
      $test = $(this).find('[name=email]:first');
      if(!validateLength($test)) {
         s = false;
         errorOutBorder($test);
      }
      else {
         clearOutBorder($test);
      }

      $test = $(this).find('[name=comments]:first');
      if(!validateLength($test)) {
         s = false;
         errorOutBorder($test);
      }
      else {
         clearOutBorder($test);
      }
      
      //if there's a phone field, check that too
      $test = $(this).find('[name=phone]:first');
      if($test.length) {
         if(!validateLength($test)) {
            s = false;
            errorOutBorder($test);
         }
         else {
            clearOutBorder($test);
         }
      }

      //did our fields pass?
      if(!s) {
         return false;
      }

      //perform ajax
      $.ajax($(this).attr('action'), {
            type: 'POST',
        dataType: "json",
            data: $(this).serialize(),
         success: function(d, t, jqx) {
            if(d && d[0] == 0) {
               window.location = '/email_success';
            }
            else {
               $("#vitelFormOutput:first").html('<p>' + d[1] + '</p>');
            }
            
        },
        error: function(jqx, s, t) {
            $("#vitelFormOutput:first").text('<p>Your browser reported an error trying to send the message: ' + t + '</p>');
        }
      });
      return false;
   });   
}


$(document).ready(function() {
	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h2.trigger").click(function(){
		toggle_trigger(this);
		return false; //Prevent the browser jump to the link anchor
	});

	$("h2.trigger.defopen").each(function(){
		toggle_trigger(this);
	});

	if(window.location.hash.length > 0) {
		$("h2.trigger.triglink-" + window.location.hash.substring(1)).each(function(){
			$('body').animate({ scrollTop: $(this).offset().top }, 0);
			toggle_jumpto(this);
		});
	}

	jqueryslidemenu.buildmenu("myslidemenu", arrowimages);	

});



