(function($){
	$.fn.youAreHere = function(opts){
		var options = $.extend({}, $.fn.youAreHere.defaultOptions, opts);
		
		return this.each(function(){
			var locs = window.location.pathname.replace('//','/').replace(/(^\/|\/$)/g,'').toLowerCase(),
					paths = [],
					$links = $(this).find('a[href^=/]');
			
			if(options.exactLinkOnly){
				paths.push(locs);
			} else {
				locs = locs.split('/')
				for(var i = 0; i < locs.length; i++){
					var path = locs[i];

					if(i > 0) path = paths[i - 1] + '/' + path;

					paths.push(path);
				}
			}
			
			var reg = new RegExp('^\/?' + paths.join('\/?$|^\/?') + '\/?$');
			$links.each(function(){
				if(this.pathname.match(reg)){
					if(options.applyToParent)
						$(this).parent().addClass(options.currentClass);
					else
						$(this).addClass(options.currentClass);
				}
			});
		});
	};
	
	$.fn.youAreHere.defaultOptions = {
		applyToParent: true,     // If set, the 'current' class is added to the parent of the link
		currentClass: 'current', // The class that will be applied to current elements
		exactLinkOnly: true
	}
})(jQuery);