// goroharumi.com

$(document).ready(function(){
  
  
  // // XHTML-complaint target="_blank" substitute for external links
  // $("a[href^='http://']").not("a[href^='http://gorosaur.us']").click(function(event){
  //   window.open( $(this).attr('href') );
  //   event.preventDefault();
  // });
  
  
  // Prefill form elements
  function prefill(selector, defValue) {
     $(selector).each(function() {
       if($.trim(this.value) == "" || $.trim(this.value) == defValue) {
         this.value = defValue;
         $(this).addClass('prefill');
       }
     });

     $(selector).focus(function() {
       if(this.value == defValue) {
         this.value = "";
         $(this).removeClass('prefill');
       }
     });

     $(selector).blur(function() {
       if($.trim(this.value) == "") {
         this.value = defValue;
         $(this).addClass('prefill');
       }
     });
  }
  
  // Form default values and hide default label
  $('label').hide();
  prefill('input#contact_name', 'Name');
  prefill('input#contact_email', 'Email Address');
  prefill('textarea#contact_message', 'Message');
  
  // Reset values on submit
  $('div#footer_inner form').submit(function(){
    if ($('input#contact_name').val() == 'Name') {
      $('input#contact_name').val('');
    }
    if ($('input#contact_email').val() == 'Email Address') {
      $('input#contact_email').val('');
    }
    if ($('textarea#contact_message').val() == 'Message') {
      $('textarea#contact_message').val('');
    }
  });
  
  
  // Scroll to hash
  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body').animate({scrollTop: targetOffset}, 1000);
       return false;
      }
    }
  });
  
  
  // Code sample animation
  $('li#code_home a').click(function(event) {
    moveCodeSample('0');
    event.preventDefault();
  });
  
  $("ul#code_thumbs li").each(function(){
    var link = $(this).attr("id");
    link = link.replace(/design_link_/, '');
    $(this).find('a').click(function(event) {
      moveCodeSample(link);
      event.preventDefault();
    });
  });
  
  function moveCodeSample(thisFar) {
    var sections = thisFar;
    var width = 680; // distance to move
    var distanceToMove = sections * width;
    distanceToMove = distanceToMove - (distanceToMove * 2); // make negative number
    $('div#code ul#code_descriptions').animate(
      { left: distanceToMove }, 1500
    );
  }
  
});

