var circlePositions, circles, columnizeGo, formerrors, hadPortfolioTip, init, loadShowcase, scrollvalue, setupPortfolio, setupWhatWeDo, showcase, showcaseGo, showcaseGoJS, showcaseGoNoCSS, showcaseLive;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
showcase = 0;
scrollvalue = 0;
circles = [];
showcaseLive = true;
formerrors = 0;
hadPortfolioTip = false;
/*
#	DOCUMENT READY!
*/
init = function() {
  columnizeGo();
  circlePositions();
  setupPortfolio();
  return setupWhatWeDo();
};
circlePositions = function() {
  var i;
  i = 0;
  return $('.circles').each(function() {
    circles[i] = parseInt($(this).css('bottom'));
    return i++;
  });
};
showcaseGo = function() {
  var THIS, showcaseNum, showcaseTimer;
  if (showcaseLive) {
    THIS = $('.showcase');
    $(THIS).removeClass('move' + showcase);
    showcaseNum = $('.image', THIS).length;
    if (showcase === showcaseNum - 1) {
      showcase = 0;
    } else {
      showcase = showcase + 1;
    }
    $(THIS).addClass('move' + showcase);
    $('.scale').cssanimation('zoomInOut0', 3000);
  }
  return showcaseTimer = setTimeout(showcaseGo, 6000);
};
showcaseGoNoCSS = function() {
  var showcaseTimer;
  $('.img2').rotate(90);
  $('.img3').rotate(20);
  $('.img4').rotate(-90);
  $('.move').rotate(20);
  return showcaseTimer = setTimeout(showcaseGoJS, 3000);
};
showcaseGoJS = function() {
  var THIS, showcaseNum, showcaseTimer;
  if (showcaseLive) {
    THIS = $('.showcase');
    showcaseNum = $('.image', THIS).length;
    switch (showcase) {
      case 0:
        $('.move').animate({
          left: '1110px',
          top: '160px'
        }, 3000, $.easing.ease);
        $('.move').rotate({
          angle: 20,
          animateTo: -100,
          duration: 3000,
          easing: $.easing.ease
        });
        break;
      case 1:
        $('.move').animate({
          left: '1400px',
          top: '650px'
        }, 3000, $.easing.ease);
        $('.move').rotate({
          angle: -100,
          animateTo: -50,
          duration: 3000,
          easing: $.easing.ease
        });
        break;
      case 2:
        $('.move').animate({
          left: '-1250px',
          top: '1350px'
        }, 3000, $.easing.ease);
        $('.move').rotate({
          angle: -50,
          animateTo: 60,
          duration: 3000,
          easing: $.easing.ease
        });
        break;
      case 3:
        $('.move').animate({
          left: '300px',
          top: '0px'
        }, 3000, $.easing.ease);
        $('.move').rotate({
          angle: 60,
          animateTo: 20,
          duration: 3000,
          easing: $.easing.ease
        });
    }
    if (showcase === showcaseNum - 1) {
      showcase = 0;
    } else {
      showcase = showcase + 1;
    }
  }
  return showcaseTimer = setTimeout(showcaseGoJS, 6000);
};
columnizeGo = function() {
  $('.columns-2').columnize({
    width: 200,
    lastNeverTallest: true
  });
  return $('.columns-2-full').columnize({
    lastNeverTallest: true
  });
};
this.scrollTo = __bind(function(id) {
  $('html,body').stop().animate({
    scrollTop: $(".page-" + id).offset().top
  }, 3000, 'easeInOutQuint');
  return false;
}, this);
this.isScrolledIntoView = function(elem) {
  var docViewBottom, docViewTop, elemBottom, elemTop;
  docViewTop = $(window).scrollTop();
  docViewBottom = docViewTop + $(window).height();
  elemTop = $(elem).offset().top;
  elemBottom = elemTop + $(elem).height();
  return (elemBottom >= docViewTop) && (elemTop <= docViewBottom);
};
loadShowcase = function() {
  var showcaseTimer;
  $('.showcase').removeClass('loading');
  $('.spinner').addClass('loaded');
  if ($('html.cssanimations').length > 0) {
    return showcaseTimer = setTimeout(showcaseGo, 3000);
  } else {
    return showcaseGoNoCSS();
  }
};
setupPortfolio = function() {
  $('.portfolio .project').each(function() {
    return $('.portfolio-nav').append('<a class="nav-item" href="#"></a>');
  });
  $('.portfolio-nav .nav-item:eq(0)').addClass('active');
  return $('.portfolio .project:eq(0)').addClass('active');
};
setupWhatWeDo = function() {
  $('.what-we-do .slide').each(function() {
    return $('.what-we-do-nav').append('<a class="nav-item" href="#"></a>');
  });
  $('.what-we-do-nav .nav-item:eq(0)').addClass('active');
  return $('.what-we-do .slide:eq(0)').addClass('active');
};
this.showPortfolioTip = function() {
  return setTimeout(function() {
    return $('.portfolio-tip').fadeIn(1500);
  }, 1000);
};
this.hidePortfolioTip = function() {
  return $('.portfolio-tip').fadeOut(500);
};
/*
#	DOCUMENT IS READY!!!
*/
$(function() {
  init();
  $('.portfolio-tip').css('left', $('.portfolio-nav').width() + 60);
  $(window).scroll(function(event) {
    var d, i, scroll, yOffset;
    showcaseLive = isScrolledIntoView($('.showcase'));
    if (isScrolledIntoView($('.portfolio-nav')) && hadPortfolioTip === false) {
      showPortfolioTip();
      hadPortfolioTip = true;
    }
    yOffset = $(window).scrollTop();
    d = $(document).height();
    scroll = (yOffset / d) * 100;
    i = 0;
    $('.circles').each(function() {
      $(this).css({
        bottom: Math.floor(circles[i] - (scroll * 15))
      });
      return i++;
    });
    $('.background').css({
      backgroundPosition: '0 ' + Math.floor(0 - (scroll * 8)) + 'px'
    });
    return scrollvalue = yOffset;
  });
  $('.showcase').waitForImages(function() {
    return loadShowcase();
  });
  $('.portfolio-nav .nav-item').live('click', function() {
    var NavCount, iNav;
    if (hadPortfolioTip) {
      hidePortfolioTip();
    }
    iNav = $(this).index();
    NavCount = $('.portfolio-nav .nav-item').length;
    $('.portfolio .project.active').removeClass('active');
    $('.portfolio-nav .nav-item.active').removeClass('active');
    $('.portfolio .project:eq(' + iNav + ')').addClass('active');
    $('.portfolio-nav .nav-item:eq(' + iNav + ')').addClass('active');
    return false;
  });
  $('.what-we-do-nav .nav-item').live('click', function() {
    var NavCount, iNav;
    iNav = $(this).index();
    NavCount = $('.what-we-do-nav .nav-item').length;
    $('.what-we-do .slide.active').removeClass('active');
    $('.what-we-do-nav .nav-item.active').removeClass('active');
    $('.what-we-do .slide:eq(' + iNav + ')').addClass('active');
    $('.what-we-do-nav .nav-item:eq(' + iNav + ')').addClass('active');
    return false;
  });
  $('.contact input:not(".submit"), .contact textarea').click(function() {
    return $('.contact').addClass('edit');
  });
  $('.contact input:not(".submit"), .contact textarea').focus(function() {
    return $('.contact').addClass('edit');
  });
  $('.contact input, .contact textarea').blur(function() {
    var i;
    i = 0;
    $('.contact input:not(".submit"), .contact textarea').each(function() {
      if ($(this).val() !== '') {
        return i = i + 1;
      }
    });
    if (i === 0) {
      return $('.contact').removeClass('edit');
    }
  });
  $('.contact input.submit').click(function() {
    var errors, leftpos, response;
    errors = 0;
    $('.contact input:not(:eq(1)):not(".submit"), .contact textarea').each(function() {
      if ($(this).val() === '') {
        $(this).addClass('invalid');
        return errors = errors + 1;
      } else {
        return $(this).removeClass('invalid');
      }
    });
    if (errors > 0) {
      $('.contact-error:eq(0)').hide();
      $('.contact-error:eq(' + formerrors + ')').show();
      if (formerrors === 0) {
        formerrors = 1;
      }
    }
    if (errors === 0) {
      $('.contact-error').hide();
      response = '';
      $('.contact').removeClass('edit');
      leftpos = $('.form form').css('left');
      $('.form form').stop().animate({
        left: '-500px'
      }, 200, function() {
        var cemail, cmessage, cname, cnumber;
        cname = $('.contact [name="name"]').val();
        cnumber = $('.contact [name="number"]').val();
        cemail = $('.contact [name="email"]').val();
        cmessage = $('.contact textarea').val();
        return setTimeout(function() {
          return $.post("getintouch.php", {
            name: cname,
            email: cemail,
            number: cnumber,
            message: cmessage
          }, function(data) {
            $('.contact').addClass('sent');
            if (data = 'sent') {
              response = '<div class="response"><h2>Thank you!</h2><p>Your message has been sent.</p><p>You will receive a reply as soon as possible.</p></div>';
            } else {
              response = '<div class="response"><h2>Ooops!</h2><p>Something went wrong.</p><p>Please try again later.</p></div>';
            }
            return $(' .form form').html(response).stop().animate({
              left: 0
            }, 200);
          });
        }, 500);
      });
    }
    return false;
  });
  return $('header a, .internal-link').click(function() {
    var anchor;
    anchor = $(this).attr('href');
    anchor = anchor.replace('#', '');
    $('html,body').stop().animate({
      scrollTop: $('a.anchor[name="' + anchor + '"]').offset().top
    }, 3000, 'easeInOutQuint');
    return false;
  });
});
