(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], function($) {
            root = factory(root, $);
        });
    } else {
        root = factory(root, root.jQuery);
    }
}(this, function(root, $) {

    $.fn.setCount = function ($data) {
        "use strict";
        return this.text(
            $data.fnSettings().asDataSearch.length
        );
    }

    $.fn.fauxEmpty = function () {
        "use strict";
        var $this = $(this);
        if (this.id === "content-primary") {
            $this.children.not('#slide-btn').remove();
        } else { $this.empty() }
        return this;
    };

    root.getDateDifferenceInDays = function (date1, date2) {
        var diff = Math.abs(date1.getTime() - date2.getTime()),
            diffDays = Math.floor(diff / (1000 * 3600 * 24));

        return diffDays;
    }

    root.addToDate = function (month, day, year, hours, minutes, seconds, milliseconds, date) {
        'use strict';
        month = date.getMonth() + parseInt(month);
        day = date.getDate() + parseInt(day);
        year = date.getFullYear() + parseInt(year);
        hours = date.getHours() + parseInt(hours);
        minutes = date.getMinutes() + parseInt(minutes);
        seconds = date.getSeconds() + parseInt(seconds);
        milliseconds = date.getMilliseconds() + parseInt(milliseconds);

        return new Date(year, month, day, hours, minutes, seconds, milliseconds);
    }

    root.getDataTableHeader = function ($this) {
        "use strict";
        var containerId = $this.attr('id');

        containerId = containerId.slice(0, containerId.length - 6);

        return $('#' + containerId).find('.ctn-count').eq(0).setCount($this);
    }

    root.getInfo = function (patient) {
        "use strict";

        if ($.isFunction(patient.get)) {
            patient = patient.toJSON();
        }

        return patient.ssn ? patient.lastName + " (" + patient.ssn.substr(-4) + ")" : "";
    }

    root.addLeadingZero = function (number) {
        var string = "";

        if (number > -1 && number < 10) {
            string += "0";
        }

        return string + number;
    }

    root.setTimeToZero = function (date) {
        date.setHours(0);
        date.setMinutes(0);
        date.setSeconds(0);
        date.setMilliseconds(0);

        return date;
    }

    root.getPage = function () {
        return $('#main');
    }

    root.getContent = function () {
        return $('#inner-content');
    }

    root.getSubHeader = function () {
        return $('#sub-header');
    }

    root.getSubHeaderLeft = function () {
        return getSubHeader().find('.ui-block-sidebar');
    }

    root.getSubHeaderRight= function () {
        return getSubHeader().find('.ui-block-content');
    }

    root.getSidebarContent = function () {
        return getContent().find('.ui-block-sidebar .ui-inner-block');
    }

    root.getMainContent = function () {
        return getContent().find('.ui-block-content .ui-inner-block');
    }

}));