/**
 * anchor plugin
 * ----------------------------------------------------------------------------------------------------
 * jquery.anchor-0.1.js || jquery.anchor-0.1.min.js
 * ----------------------------------------------------------------------------------------------------
 * version		: 0.1
 * author		: christopher t. morrissey
 * desciption	: modifies the default behavior of anchor tags to create a smooth scroll
 * usage		: $.anchor({speed: 500});
 * ----------------------------------------------------------------------------------------------------
 */

(function($) {
	jQuery.fn.anchor = function(options){ 
		
		// defaults
		var defaults = {speed: 1000};
		
		// options
		var options =  $.extend(defaults, options);
		
		$(this).find('a[href^=#]').bind('click', function(e){
	
			e.preventDefault();
			
			var anchor_href = $(this).attr('href');
			var anchor_name = anchor_href.substring(1);
		
			if(typeof anchor_name != "undefined"){
				try{
					$('body,html').animate({scrollTop: $('a[name='+anchor_name+']').offset().top}, options.speed, function(){
						window.location.hash = anchor_href;
					});
					return false;
				} catch(e){
					return true;
				}
			} else {
				return true;
			}
			
		});
					
	}
})(jQuery)
