
Scrollie = new Class({

    options: {
        wait: false,
        duration: 1700,
        transition: 'expo:out',
        completeAction: 'scrollendpoint'
    },

    initialize: function(options){
        this.setOptions(options);

        var scroll = new Fx.Scroll(window, options);
        var scrollingAnchors = this;

        if (location.hash != "") {
            var location_id = location.hash.split('/')[1];

            if (location_id) {
                scroll.toElement(location_id);

                if(this.options.completeAction) {
                    $(location_id).fireEvent(this.options.completeAction);
                }
            }
        }

        $$(document.links).each(function(link) {
            if (link.pathname.contains (location.pathname)) {
                var anchor = link.hash;
                anchor = anchor.split('/')[1];
            }

            if (anchor && $(anchor)) {
                link.addEvent('click', function(e) {
                    e = new Event(e).stop();

                    scroll.toElement(anchor);

                    if(this.options.completeAction) {
                        $(anchor).fireEvent(this.options.completeAction);
                    }

                    location.hash = "#/" + anchor;
                }.bind(this));
            }
        }.bind(this));
    },
});

Scrollie.implement(new Options);