// JavaScript Document
$(document).ready(function() {	
		       




		// Keep the word "search" in the search box when not in use		       
		$('input[type="text"]').addClass("idleField");
    		$('input[type="text"]').focus(function() {
    			$(this).removeClass("idleField").addClass("focusField");
 		    if (this.value == this.defaultValue){ 
 		    	this.value = '';
			}
			if(this.value != this.defaultValue){
    			this.select();
    		}
 		});
 		$('input[type="text"]').blur(function() {
 			$(this).removeClass("focusField").addClass("idleField");
 		    if ($.trim(this.value) == ''){
		    	this.value = (this.defaultValue ? this.defaultValue : '');
			}
 		});		


    // This does a little scroll down when the page loads, that's it
    $('#home').animate({ marginTop: "-40px" }, 0);

    // This function is used to set the onstate of the left nav, nothing else
	
    $("#wrapper").mousemove(function(e){
	
		// Get the Y axis page coordinate (of the mouse)
		var pageCoords = e.pageY;
		 
		 
		// Set home left nav as current
		if (pageCoords > 0 && pageCoords <= 615 )
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.home').addClass("current");
		}
		
		// Set who we are left nav as current
		if (pageCoords >= 615 && pageCoords <= 1039)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.news').addClass("current");
		}
		
		// Set what we do left nav as current
		if (pageCoords >= 1039 && pageCoords <= 3217)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.who-we-are').addClass("current");
		}
	
		
		// Set what we do left nav as current
		if (pageCoords >= 3217 && pageCoords <= 5043)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.what-we-do').addClass("current");
		}	
	
		// Set what we do left nav as current
		if (pageCoords >= 5043 && pageCoords <= 5785)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.how-we-do-it').addClass("current");
		}
	
	
	
		// Set what we do left nav as current
		if (pageCoords >= 5785 && pageCoords <= 7013)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.our-clients').addClass("current");
		}
		
		
		// Set what we do left nav as current
		if (pageCoords >= 7013 && pageCoords <= 8939)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.contact').addClass("current");
		}
	
	
	
		// Set what we do left nav as current
		if (pageCoords >= 8939 && pageCoords <= 9519)	
		{
		$('#leftnav ul li').removeClass('current');
		$('#leftnav ul li.ulab').addClass("current");
		}
	
	
	
			
      });
		

      // This makes it so that the left nav does not flicker after something is clicked
	  
      $('a[href*=#]').live('click', function() {
	
			$("#wrapper").unbind('mousemove');
			$.bbq.pushState( '#/' + this.hash.slice(1) );       
			return false;
			
		  });
	  
	  // This is the function that makes the page scroll
	        
      $(window).bind('hashchange', function(event) {
        
        if (location.hash) {
		  
          var tgt = location.hash.replace(/#\//,'');
		
		if (tgt != '') {
		$('#leftnav ul li').removeClass('current');
			  $('#leftnav ul li.' + tgt).addClass('current');
			  }
			
			} else {
			  var tgt = '#top';
	
			}
			
        $.smoothScroll({scrollTarget: '#' + tgt , afterScroll: function() { $("#wrapper").mousemove(function(e){
	

	// Get the Y axis page coordinate (of the mouse)
	var pageCoords = e.pageY;
	 
	 
	// Set home left nav as current
	if (pageCoords > 0 && pageCoords <= 615 )
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.home').addClass("current");
	}
	
	// Set who we are left nav as current
	if (pageCoords >= 615 && pageCoords <= 1039)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.news').addClass("current");
	}
	
	// Set what we do left nav as current
	if (pageCoords >= 1039 && pageCoords <= 3217)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.who-we-are').addClass("current");
	}

	
	// Set what we do left nav as current
	if (pageCoords >= 3217 && pageCoords <= 5043)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.what-we-do').addClass("current");
	}	

	// Set what we do left nav as current
	if (pageCoords >= 5043 && pageCoords <= 5785)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.how-we-do-it').addClass("current");
	}



	// Set what we do left nav as current
	if (pageCoords >= 5785 && pageCoords <= 7013)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.our-clients').addClass("current");
	}
	
	
	// Set what we do left nav as current
	if (pageCoords >= 7013 && pageCoords <= 8939)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.contact').addClass("current");
	}



	// Set what we do left nav as current
	if (pageCoords >= 8939 && pageCoords <= 9519)	
	{
	$('#leftnav ul li').removeClass('current');
	$('#leftnav ul li.ulab').addClass("current");
	}
	

      }); }
        });
	
      });
      
	  // This keeps the trigger from happening until the window and its descendants are fully loaded
      $(window).load(function() {	
	  
		  // This starts the scrolling when the page is loaded 
		  $(window).trigger('hashchange');
		  
	  });
      
 
 
 // Show recaptcha on load
 
 showRecaptcha('recaptcha_div');
 
 
  // End doc.ready
  
  });


