/*------------------
 * HOMEGROWN PLUGINS 
--------------------*/
(function($) {
	
	$.fn.turnIntoLink = function () {
		if(!this || !this[0]){return false;}
		
		var path = window.location.pathname;
			path = (path.charAt(path.length-1) != "/") ? path + "/" : path;
		
		$(this).each(function(i, val) {
			var link = $(this),
				href = $(this).attr('data-href');
			
			if (href == path) {
				link.addClass('noLink');
			} else {
				link.unbind("click.turnIntoLink");
				link.bind("click.turnIntoLink", function() {
					window.location.href = href;
				});
			}
		});
	
		return this;
	};
	
	// example: /disclaimers/
	$.fn.floatingMenu = function (content, footer, adjustment) {
		if(!this || !this[0]){return false;}
		
		var win        = $(window),
			wTop       = 0,
			menu       = $(this),
			menuHeight = menu.height(),
			footerPos  = footer.position(),
			fTop       = footerPos.top,
			fHeight    = footer.height(),
			dHeight    = content.height(),
			limitTop   = (dHeight - menuHeight) + 50,
			scrollTO,
			scrollMe;
			
		scrollMe = function() {
			//console.log("top: "+wTop+" limit top: "+limitTop+" footer top:"+fTop);
			adjustment = (wTop <= adjustment) ? 0 : adjustment;
			
			if (wTop > limitTop) {
				menu.animate({'top':limitTop - adjustment}, "fast");
			} else {
				menu.animate({'top':wTop - adjustment}, "fast");
			}
		}
		
		windowScroll = function() {
			clearTimeout(scrollTO);
			wTop     = win.scrollTop();
		    scrollTO = setTimeout(scrollMe, 200);
		}
		
		win.scroll(function(){
			windowScroll();
	    });
		
		windowScroll();
	
		return this;
	};
	
})(jQuery);
