(function($) {
/**
 * **********************************************************************
 * **********************************************************************
 * jQuery scroll to named anchor
 *
 * @author: stefan kloiber, <hello@09.fresh-flava.net>
 * @date: 2009-01
 *
 * @version: 0.1.0
 *
 * @dependencies: jquery
 *
 * @usage pattern:
 *      jQuery('a[href*=#]').scrollTo();
 *
 * @arguments:
 *      appendHash (Boolean) switches how to deal with the browser history
 *                           true: write the state to the history session,
 *                                 add the hash to the url and scroll to
 *                                 the named anchor or element
 *
 * @hint:
 *      if you use the ie cols hack for identical col heights you can't
 *      work with appendHash = true!
 *
 * **********************************************************************
 * **********************************************************************
 */
 
$.fn.scrollTo = function(appendHash) {
    var anchorLinks = this;
    this.click(function(event) {
        event.preventDefault();
        var namedAnchor = $(event.target)[0].hash,
            anchorOffset = $(namedAnchor).offset() || $('*[name=' +namedAnchor.slice(namedAnchor.lastIndexOf('#')+1)+ ']').offset();
        (appendHash === true)
            ? window.location.hash = namedAnchor
            : window.scrollTo(anchorOffset.left,anchorOffset.top);
    });

    return this;
}
})(jQuery);
