$(function(){

  // gallery slideshows
  $('#gallery img').show()
  $('#gallery').cycle({ 
    fx:     'scrollLeft',
    //fx:     'fade',  
    speed:   300, 
    timeout: 6000, 
    next:   '#gallery',
    pause:   1 
  });
    
  // highlight current menu item
  $('#navigation a').each(function(i,el){
    target = $(el).attr('href')
    if( window.location.href.indexOf(target) >= 0 ){
      $('#navigation a').removeClass('current')
      $(el).addClass('current')
    }
  })

  // simple regex form validation
  $('form input[match], form textarea[match]').each(function(){
    this.valid = function(){
      return RegExp($(this).attr('match').replace(/\\/g,"\\")).test( $(this).val() )
    }
  }).keyup(function(){
    if( this.valid() ) {
      $(this).removeClass('invalid')
    }else{
      $(this).addClass('invalid')
    }
  })
  
  $('form').submit(function(){
    $('input[match], textarea[match]',this).each(function(){
      if ( ! this.valid() ) $(this).addClass('invalid')
    })
    $('input.invalid, textarea.invalid').eq(0).focus()
    return $('input.invalid').length == 0;
  })

})