$(document).ready(function() {
  
/* CACHE IMAGES
 var images = [ 'image1.jpg', 'image2.png', 'image3.gif' ];
  jQuery.each(images, function(i) {
    images[i] = new Image();
    images[i].src = this;
  });
*/
  
  
//SLIDE-DOWN-PANEL
  $("#open").click(function(){
    $("div#panel").slideDown("slow");
  });  
  $("#close").click(function(){
    $("div#panel").slideUp("slow");  
  });    
  $("#toggle a").click(function () {
    $("#toggle a").toggle();
  });
  
  
  $("#jsddm > li:has(ul)").addClass("hasSubNav");
  $('#slideshow').cycle({ fx: 'fade', random: 1, pause: 1 });
  

 //tweet
  $("#tweet").tweet({
  username: twitterName,
  count: 2,
  intro_text: null,
  outro_text: null,
  join_text:  null,
  loading_text: "Loading tweets..."
});
  
jQuery.validator.addMethod("phoneUS",  function(phone_number, element) {
  phone_number  = phone_number.replace(/\s+/g, "");
  return  this.optional(element) || phone_number.length > 9 &&  phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);}, "Invalid Phone number");
  $("#cForm").validate({
    invalidHandler: function(e, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
        var message = errors == 1
          ? '</strong>Oops!</strong> there is <strong>1</strong> error. It has been highlighted above.'
          : '<strong>Oops!</strong> there are <strong>' + errors + '</strong> errors. They have been highlighted above';
        $("div#errorContainer").html(message);
        $("div#errorCOntainer").show();
      } else {
        $("div#errorContainer").hide();
      }
    },
    rules:{ phone:{ 
        required:true,
         phoneUS:true
    }}
});
    
jQuery.validator.addMethod("sbBt", function(field,element){if(element.value!==""){window.location = "http://"+window.location.host+"/thanks/";return false;}else{return true;}},"Thank You");

  
});
