clicky.init(186971);

google.load('jquery', '1.3.2');
google.setOnLoadCallback(function() {
  
  var activesection = null;
  
  $('#logo').click(function() {
    $('.header').slideDown();
    $('.content').slideUp();
    activesection = null;
    document.location = '#'
  });
  
  $('.header').click(function() {
    triggersection(this.id);
  });
  
  $('#nav li a').click(function() {
    var hash = this.getAttribute('href');
    if (activesection == hash || !activesection) {
      $(hash).click();
    }
    else {
      document.location = hash;
      $(hash + '_content, ' + activesection + '_content, ' + hash + ', ' + activesection).slideToggle()
      activesection = hash;
    }
    return false;
  });
  
  var firstload = true;
  var hash = window.location.hash;
  if (hash) {
    $(hash).click();
  }
  firstload = false;
    
  function triggersection(id) {
    var content;
    if (activesection) {
      document.location = '#'
      content = activesection;
      activesection = null;
    }
    else {
      document.location = content = activesection = '#' + id;
    }
    $('.header[id != ' + id + '], ' + content + '_content').slideToggle(firstload ? 1 : undefined);
  }
  
  $('#quote_content input[type=text], #quote_content textarea').one('focus', function() {
    this.value = '';
  });
  
  email_regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  
  quote_fullname = $('#quote_fullname');
  quote_email = $('#quote_email');
  quote_brief = $('#quote_brief');
  $('#quote_form').submit(function() {
    brief = quote_brief.attr('value')
    valid = true;
    if (quote_fullname.attr('value')) {
      quote_fullname.removeClass('invalid');
    } else {
      quote_fullname.addClass('invalid');
      valid = false;
    }
    if (quote_email.attr('value').match(email_regex)) {
      quote_email.removeClass('invalid');
    } else {
      quote_email.addClass('invalid');
      valid = false;
    }
    if (quote_brief.attr('value')) {
      quote_brief.removeClass('invalid');
    } else {
      quote_brief.addClass('invalid');
      valid = false;
    }
    return valid;
  });
});
