
/*  =Behavior
    A toolbox of useful tools
----------------------------------------------- */
var Behavior = {

    /*  =Opens external hostnames in a new tab/window
    ----------------------------------------------- */
    init_external_links: function() {
        //  Open external links in new window
        $("a").filter(function() {
            return this.hostname && this.hostname !== location.hostname;
        }).each(function() {
            $(this).attr({
                target  : '_blank',
                title   : "Visit " + this.href + " (click to open in a new window)"
            }).addClass('external');
        });
    },

    /*  =Adds class 'selected' to current page nav link
    ----------------------------------------------- */
    init_nav_selection: function() {
        // Get rid of "http://Ó
        loc = location.href.substring(7);

        // Get rid of domain name
        loc = loc.substring(loc.indexOf("/"));
        loc = loc.substring(loc.indexOf("about"));
        loc = loc.substring(loc.indexOf("contact"));

        // apply class to current nav link
        //$("nav a[href='" + loc + "']").addClass('selected');

        //var dir = location.pathname.split('/')[1];
        $('nav').find('a[href*="' + loc + '"]').addClass('selected');
    },

    /*  =Adds class 'last-child' to remove last nav divider
    ----------------------------------------------- */
    init_last_nav_element: function() {
        $("nav li:last-child").addClass("last-child");
    },

    /*  =Initializes the tinyscrollbar library
    ----------------------------------------------- */
    init_tinyscrollbar: function() {
        function isTinyScrollBarPresent() {
            return !!(typeof jQuery.fn.tinyscrollbar == 'function');
        }
        if (isTinyScrollBarPresent()) {
            $('#content-scrollbar').tinyscrollbar();
        }
    },

    /*  =Initializes the tooltip
    ----------------------------------------------- */
    init_tooltip: function() {
        $(".tooltip").hover(function (e) {
            e.preventDefault();
            $(this).toggleClass("tooltip-hover");
        });
    }
}

