$(function() {

  $('.nav a[href*=#], .hdrInner a[href*=#], .about a[href*=#]').click(function(event) {

    var $target = $(this.hash);
    var targetOffset = $target.offset().top;
    $('html, body').animate({scrollTop: targetOffset},
                      {duration: 1100,
                      easing: 'easeInOutCubic'}
                      );
    
    return false;
  });
  
  var workDur = 700;
  var workEase = 'easeInOutCubic';
  
  $('#ctrls a').toggle(
    function() {
      $('#row1').animate({left: -789},{duration: workDur, easing: workEase});
      setTimeout(function() { $('#row2').animate({left: -789},{duration: workDur, easing: workEase});}, 100);
      $(this).empty().append('&laquo; Previous');
      return false;                         
    },
    function() {
      $('#row1').animate({left: 0},{duration: workDur, easing: workEase});
      setTimeout(function() { $('#row2').animate({left: 0},{duration: workDur, easing: workEase});}, 100);
      $(this).empty().append('Next &raquo;');
      return false;
    }
  );
  
  $('.item a[href*="/client/"], .item a[href*="popup.php"]').colorbox({iframe:true, 
                         transitionSpeed: 550, 
                         fixedWidth: 950, 
                         fixedHeight: 550, 
                         initialWidth: 200
                        });

  $(".email:contains('(at)'), .email:contains('(dot)')").each(function() {
    var $this = $(this);
    var t = $this.text();
    $this.text(t.replace('(at)','@').replace('(dot)','.'));  
  });
  
  $("a[href^='http://']").addClass('linkout');
  
  $("#ctrls").css('display', 'block');
  
/*******************************************************************************
 * AJAX Contact Form
 ******************************************************************************/   
  if ($('#cf').attr('method')) {
    $('#cf').submit(function() {

      var inputs = [];
      $(':input', this).each(function() {
        inputs.push(this.name + '=' + escape(this.value));
        //alert('hi');
      });
      
      jQuery.ajax({
        data: inputs.join('&'),
        url: this.action,
        timeout: 2000,
        
        beforeSend: function() {
          $('input#sender').attr('value', 'Sending...');          
          $('.msg').fadeOut('fast');
        },
        success: function(r) {
          if (r == 'Your message was successfully sent') {        
            $('input#sender').attr('value', 'Sent');
            $('#emailf').attr('value', '');
          } else {
            $('input#sender').attr('value', 'Send Message');
          }
          
          $('#txtmsg').empty().append(r);
          $('.msg').css('display', 'block').fadeIn('slow');
        }
      });
      
      return false;
    })
  }
  

});
