var verticalAdjuster = 0.3;
var horizontalAdjuster = 0.15;
var lavaSpeed = 0.1;
var fixedMenu = false;
var section = false;

$(function() {
  $('#contact_name').watermark('What\'s your name?', {color: '#fff', top: 2, left: 4 });
  $('#contact_email').watermark('What\'s your email?', {color: '#fff', top: 2, left: 4 });
  $('#contact_message').watermark('Your message', {color: '#fff', top: -1, left: 4 });
  
  $('#things_we_do_link').addClass('active');
  $('.project').click(function() {
    window.location = $(this).find('a').attr('href');
  });

  // Control scrollTo links
  $('a.hash').click(function() {
    var hash = this.hash;

    if (typeof _gaq !== "undefined")
    {
      _gaq.push(['_trackEvent', 'Contacts', 'Hide']);
    }

    $('.menu #contacts_link.active').removeClass('active');

    $('.contacts').slideUp('fast', function() {
      jump(hash);
    });
  });

  $("#projects .project").hover(
    function () {
      $(".project").stop(true, true);

      $(this).children(".image").fadeOut(100);
      $(this).children(".description").fadeIn(500);
    },
    function () {
      $(".project").stop(true, true);

      $(this).children(".description").fadeOut(100);
      $(this).children(".image").fadeIn(500);
    }
  );

  $("#project .pager li").hover(
    function () {
      $(".preview").stop(true, true);

      $(this).children(".preview").fadeIn(500);
    },
    function () {
      $(".preview").stop(true, true);

      $(this).children(".preview").fadeOut(200);
    }
  );

  $("form.jqtransform").jqTransform();

  if (window.location.hash && (window.location.hash == '#contacts')) {
    showContacts();
  };
});

$(window).scroll(function() {
  classify();
});

function classify() {
  var scroll = $(this).scrollTop();

  if (!$('.menu #contacts_link.active').length) {
    if (scroll <= 997) {
      if (section != 'things_we_do') {
        section = 'things_we_do';
        $('.menu .active').removeClass('active');
        $('#things_we_do_link').addClass('active');
      };
    } else if (scroll <= 1800) {
      if (section != 'portfolio') {
        section = 'portfolio';
        $('.menu .active').removeClass('active');
        $('#portfolio_link').addClass('active');
      };
    } else if (section) {
      if (section != 'the_team') {
        section = 'the_team';
        $('.menu .active').removeClass('active');
        $('#the_team_link').addClass('active');
      };
    }
  };

  if (scroll >= 216 && !fixedMenu) {
    $('#menu').css({
      'position': 'fixed',
      'top': '0'
    });

    $('#we_are_seegno').css({ 'margin-bottom': '60px' });

    fixedMenu = true;
  } else if (scroll < 216) {
    $('#menu').css({'position': 'static', 'top': '0'});

    $('#we_are_seegno').css({'margin-bottom': '0px'});

    fixedMenu = false;
  };
}

function validateContact() {
  if ($('#contact_name').val() && $('#contact_email').val() && $('#contact_message').val()) {
    return true;
  };

  return false;
}

function contact(data) {
  if (!validateContact()) {
    alert('Please provide your contact information.');

    return false;
  };

  if (data) {
    if (typeof _gaq !== "undefined")
    {
      _gaq.push(['_trackEvent', 'Contacts', 'Sent']);
    }
    alert("Thank you for your message! We'll be in touch!");
  };

  hideContacts();
}

function jump(hash) {
  $.scrollTo(hash, 1500, function() {
    window.location.hash = hash;
  });

  if (typeof _gaq !== "undefined")
  {
    _gaq.push(['_trackEvent', 'Home', 'Jump', hash]);
  }
}

function showContacts() {
  section = false;

  if ($('.contacts').css('display') == 'none') {
    $('html,body').animate({scrollTop:0}, 800);
    if (typeof _gaq !== "undefined")
    {
      _gaq.push(['_trackEvent', 'Contacts', 'Show']);
    }

    $('.contacts').delay(800).slideDown('slow');
    $('.menu .active').removeClass('active');
    $('.menu #contacts_link').addClass('active');
  } else {
    hideContacts();
  }

  return false;
}

function hideContacts() {
  if (typeof _gaq !== "undefined")
  {
    _gaq.push(['_trackEvent', 'Contacts', 'Hide']);
  }

  $('.contacts').slideUp('fast');

  $('.menu #contacts_link.active').removeClass('active');
  classify();
}
