/*
  jQuery anchor handler - 0.4
  http://code.google.com/p/jquery-utils/

  (c) Maxime Haineault <haineault@gmail.com>
  http://haineault.com   

  MIT License (http://www.opensource.org/licenses/mit-license.php)

  Changelog
  =========
  - made onload check more robust
  - removed handler stack, useless now
  - added setHash function with scrollfix
  - fixed bug in IE
  - added handleClick argument (default to false)
  - added stronger typecheck for the regexp variable
  - fixed variable scope of "handlers"
  - now using builtin hash window.location.hash instead of full URL
*/

(function($){
    var hash = window.location.hash;
	$.extend({
		anchorHandler: {
            setHash: function(newhash) {
                var x = window.pageXOffset;
                var y = window.pageYOffset;
                window.location.hash = newhash;
                window.scrollTo(x, y);
            },
			add: function(regexp, callback, handleClick) {
                if (handleClick) $('a[href~=#]').each(function(i,a){
                    if (a.href.match(regexp)) $(a).click(callback); });

                var match = hash.match(regexp) && hash.match(regexp)[0] || false;
                if (match) callback.apply($('a[href~='+hash+']').get(0), [match, (hash || false)]); 
                return $.anchorHandler;
			}
        }
    });
})(jQuery);
