// JavaScript Document
var tick = 0;
var scrollStop;


	//jQuery Easing Plugin  
	// t: current time, b: begInnIng value, c: change In value, d: duration
	jQuery.easing['jswing'] = jQuery.easing['swing'];
	
	jQuery.extend( jQuery.easing,
	{
		easeInOutQuart: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
			return -c/2 * ((t-=2)*t*t*t - 2) + b;
		},
		easeInOutCirc: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
			return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
		}
	}); //end jQuery Easing Plugin

$(document).ready(function(){


	$('#nav_home').click(function(){
			$.scrollTo( '#top', 1000, { easing: 'easeInOutQuart', offset:{ top:-180,left:0 } });
			//active_top();
			return false;
	});
	$('#nav_about').click(function(){
			$.scrollTo( '#about', 1000, { easing: 'easeInOutQuart', offset:{ top:10,left:0 } });
			//active_about();
			return false;
	});
	$('#nav_hire').click(function(){
			$.scrollTo( '#hire', 1000, { easing: 'easeInOutQuart', offset:{ top:140,left:0 } });
			//active_hire();
			return false;
	});
	$('#nav_read').click(function(){
			$.scrollTo( '#read', 1000, { easing: 'easeInOutQuart', offset:{ top:15,left:0 } });
			//active_read();
			return false;
	});
		$('#go_about').click(function(){
			$.scrollTo( '#about', 1000, { easing: 'easeInOutQuart', offset:{ top:10,left:0 } });
			//active_top();
			return false;
	});
		$('#go_hire').click(function(){
			$.scrollTo( '#hire', 1000, { easing: 'easeInOutQuart', offset:{ top:140,left:0 } });
			//active_hire();
			return false;
	});
		$('#go_read').click(function(){
			$.scrollTo( '#read', 1000, { easing: 'easeInOutQuart', offset:{ top:15,left:0 } });
			//active_read();
			return false;
	});
		$('a.hiretag').click(function(){
			$.scrollTo( '#hire', 1000, { easing: 'easeInOutQuart', offset:{ top:140,left:0 } });
			//active_hire();
			return false;
	});
	
	//Nav UL bg animation
	
	function active_top() {
		$('#navlist').stop().animate({backgroundPosition: '200px 40px'},{duration: 150});
        $('.cur').removeClass('cur');
        $(this).addClass('cur');
	}
	
	function active_about() {
		$('#navlist').stop().animate({backgroundPosition: '305px 40px'},{duration: 150});
        $('.cur').removeClass('cur');
        $(this).addClass('cur');
	}
	
	function active_hire() {
		$('#navlist').stop().animate({backgroundPosition: '428px 40px'},{duration: 150});
        $('.cur').removeClass('cur');
        $(this).addClass('cur');
	}
	
	function active_read() {
		$('#navlist').stop().animate({backgroundPosition: '550px 40px'},{duration: 150});
        $('.cur').removeClass('cur');
        $(this).addClass('cur');
	}
		

 // Scroll Position Actions
    var top = $("#top");
    var about = $("#about");
    var hire = $("#hire");
    var read = $("#read");
    scrollStop = setTimeout(updateScrollInfo, 100);

  
    $(window).scroll(function(){ 
      tick++;
      clearTimeout(scrollStop);
      scrollStop = setTimeout(updateScrollInfo, 100);
      if (tick > 10)
      {
        updateScrollInfo();
      }
    });
  
    function updateScrollInfo()
    {
      tick = 0;
      if(isTop()){
        active_top();
      } else if (isAbout()){
        active_about();
      }  else if (isHire()){
        active_hire();
      } else if (isRead()){
        active_read();
      }
    }
  
    function isTop() {
        var docViewTop = $(window).scrollTop(),
            docViewBottom = docViewTop + $(window).height(),
            elemTop = $(top).offset().top,
         elemBottom = elemTop + $(top).height();
       //Is more than half of the element visible
       return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
    }
  
    function isAbout() {
        var docViewTop = $(window).scrollTop(),
            docViewBottom = docViewTop + $(window).height(),
            elemTop = $(about).offset().top,
         elemBottom = elemTop + $(about).height();
       //Is more than half of the element visible
       return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
    }
  
    function isHire() {
        var docViewTop = $(window).scrollTop(),
            docViewBottom = docViewTop + $(window).height(),
            elemTop = $(hire).offset().top,
         elemBottom = elemTop + $(hire).height();
       //Is more than half of the element visible
       return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
    }
  
    function isRead() {
        var docViewTop = $(window).scrollTop(),
            docViewBottom = docViewTop + $(window).height(),
            elemTop = $(read).offset().top,
         elemBottom = elemTop + $(read).height();
       //Is more than half of the element visible
        return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
    }
	$("#contact label").inFieldLabels();
	
	$("#contact form").validate({
		  rules: {
			email: {
			  email: true
			}
		  }
	});

});
