var ripple = {};

(ripple.Docs = function($, jQuery) {

    function _linksClickCallback() {
        $.Docs.navigate("views/" + this.attributes.href.nodeValue.replace("#", "") + ".html");
        $.Docs.hashChanged = false;
    }

    return {

        initialize: function() {

            if (window.addEventListener) {

                window.addEventListener("hashchange", function onHashChange(){

                    if (!$.Docs.hashChanged) {
                        $.Docs.navigate();
                    } else {
                        $.Docs.hashChanged = true;
                    }

                }, false);

            }

            this.navigate();

        },

        navigate: function navigate(page) {

            jQuery("#frame").hide();

            jQuery.ajax({
                type: "GET",
                url: page ? page : this.getCurrentView(),
                success: function(data){

                    jQuery("#frame").html(data);

                    jQuery(".links")
                            .unbind("click", _linksClickCallback)
                            .bind("click", _linksClickCallback);

                    window.prettyPrint();

                    jQuery("#frame").fadeIn("slow");

                },

                error: function (){
                    $.Docs.navigate("views/404.html");
                }});

        },

        getCurrentView: function() {
            return "views/" + (window.location.hash ? (window.location.hash.replace("#", "") + ".html") : "home.html");
        },

        scrollToId: function (id) {
            window.scrollTo(0, document.getElementById(id).scrollTop = document.getElementById(id).offsetTop);
        },

        hashChanged: false
    };

}(ripple, jQuery));



