// remap jQuery to $
(function($){})(window.jQuery);


/* MENU FLOAT - adapted from: http://jqueryfordesigners.com/fixed-floating-elements */
$(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
    var top = $('#floated').offset().top - parseFloat($('#floated').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#floated').addClass('fixed');
      } else {
        // otherwise remove it
        $('#floated').removeClass('fixed');
      }
    });
  }  
});



/* SMOOTH SCROLL - from:http://blog.medianotions.de/en/articles/2009/smoothscroll-for-jquery */
$(document).ready(function() {
	
	// jQuery SmoothScroll | Version 11-06-11
	$('a[href*=#]').click(function() {

		// skip SmoothScroll on links inside sliders or scroll boxes also using anchors or if there is a javascript call
		if($(this).parent().attr('class')=='scrollable_navigation' || $(this).attr('href').indexOf('javascript')>-1) return;

		// duration in ms
		var duration=1600;

		// easing values: swing | linear
		var easing='swing';

		// get / set parameters
		var newHash=this.hash;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;
		
		// make sure it's the same location		
		if(oldLocation+newHash==newLocation)
		{
			// get target
			var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;

			// adjust target for anchors near the bottom of the page
			if(target > $(document).height()-$(window).height()) target=$(document).height()-$(window).height();			
			
			// set selector
			if($.browser.safari) var animationSelector='body:not(:animated)';
			else var animationSelector='html:not(:animated)';
			
			// animate to target and set the hash to the window.location after the animation
			$(animationSelector).animate({ scrollTop: target }, duration, easing, function() {

				// add new hash to the browser location
				window.location.href=newLocation;
			});

			// cancel default click action
			return false;
		}
	});
		
});


/* SCROLL NAVIGATION - adapted from: http://jqueryfordesigners.com/scroll-linked-navigation */

$(window).scroll(function () {
  var inview = '#' + $("body > section > h1:in-viewport:first").parent().attr('id'),
      $link = $('nav a').filter('[hash=' + inview + ']');
 
  if ($link.length && !$link.is('.active')) {
    $('nav a').removeClass('active');
    $link.addClass('active');
  }
});

/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/
