$(document).ready(function(){
   // hide accordions if there's more then one post visible
   var lis = $("#news-blog .stories").children("li");
   if (lis.length > 1) {
       lis.find(".accordion").hide();
   }
   else {
       lis.find(".morelink, .commentslink").hide();
       lis.find(".teaser").hide();
   }
   
   // expand posts
   $("#news-blog .morelink, #news-blog .commentslink").click(function(e){
       $("#news-blog .stories .accordion").hide();
       $(".teaser").show();
       $(".morelink, .commentslink").show();
       
       var post = $(this).closest("li");
       post.find(".morelink, .commentslink").hide();
       post.find(".accordion").show();
       post.find(".teaser").hide();
       
       e.preventDefault();
   });
   
   
   // comment form rollovers
   $(".stories .submit").live('mouseover', function(){
      $(this).css('background', "transparent url('/resources/site_images/btn-submitcomment-on.png') no-repeat left top"); 
   });
   $(".stories .submit").live('mouseout', function(){
      $(this).css('background', "transparent url('/resources/site_images/btn-submitcomment-reallyoff.png') no-repeat left top"); 
   });
   
   // validation
    $(".stories form").each(function(){
        $(this).validate({
              rules: {
                      name: {required: true},
                      email: {required: true, email: true},
                      comment: {required: true}
                  },
              messages:{
                      name: "!",
                      email: "!",
                      comment: ""
                  }
          });
   });
});