﻿
$.ajaxSetup({
    cache: false
});

Array.prototype.indexOf = function (obj, fromIndex, predicate) {
    if (fromIndex == null) {
        fromIndex = 0;
    } else if (fromIndex < 0) {
        fromIndex = Math.max(0, this.length + fromIndex);
    }

    if ($.isFunction(obj)) {
        predicate = obj;
    }

    for (var i = fromIndex, j = this.length; i < j; i++) {
        if ((predicate && predicate(this[i])) || this[i] === obj) {
            return i;
        }
    }
    return -1;
};

Array.prototype.find = function (predicate) {

    if (!$.isFunction(predicate)) {
        return undefined;
    }

    var idx = this.indexOf(predicate);

    if (idx < 0) return undefined;

    return this[idx];
};

Array.prototype.select = function (predicate) {

    if (!$.isFunction(predicate)) {
        return undefined;
    }

    var result = [];

    for (var i = 0, j = this.length; i < j; i++) {
        if (predicate && predicate(this[i])) {
            result.push(this[i]);
        }
    }

    return result;
};


if (typeof (NPI) === "undefined") var NPI = {};

(function($) {

    NPI.MasterPage = new function() {

        var self = this;

        self.init = function() {

            $(".datePicker").filter(":not(.maxDateNow)").datepicker({
                onClose: function() {if($(this).valid) $(this).valid();},
                dateFormat: 'mm/dd/yy'
            });	  

            $(".datePicker").filter(".maxDateNow").datepicker({
                onClose: function() {if($(this).valid) $(this).valid();},
                maxDate: '0',
                dateFormat: 'mm/dd/yy'
            });	  

            NPI.MasterPage.refreshStats();
            setInterval("NPI.MasterPage.refreshStats()", 1000*15);

            $("#showHideOnlineStudents").live('click',function(){
                $("#onlineStudents").slideToggle('slow');
            });

            if ($.cookie('cookieExpandOptions') === "hide") {
					$(".collapsable").hide();
					$('img[id$=imgExpandOptions]').attr('src', '/departmentportal/images/expand.png');
					$('img[id$=imgExpandOptions]').data('state', 'closed');
				}
				else if ($.cookie('cookieExpandOptions') === "show") {
					$(".collapsable").show();
					$('img[id$=imgExpandOptions]').attr('src', '/departmentportal/images/collapse.png');
					$('img[id$=imgExpandOptions]').data('state', 'expanded');
				}

				$('img[id$=imgExpandOptions]').click(function () {

					var state = $('img[id$=imgExpandOptions]').data('state');

					if (state == 'closed') {
						$.cookie('cookieExpandOptions', 'show');
						var img = this;
						var subMenu = $(this).parents('li:eq(0)').next();
						$(subMenu).slideDown();
						$(img).attr('src', '/departmentportal/images/collapse.png')
						$('img[id$=imgExpandOptions]').data('state', 'expanded');
					} else {
						$.cookie('cookieExpandOptions', 'hide');
						var img = this;
						var subMenu = $(this).parents('li:eq(0)').next();
						$(subMenu).slideUp();
						$(img).attr('src', '/departmentportal/images/expand.png')
						$('img[id$=imgExpandOptions]').data('state', 'closed');
					}
			});
        };

        self.refreshStats = function(){
             $("#siteStatsContent").load("/websitestats/getstats");
        };
    };

})(jQuery);

jQuery(document).ready(function() {
    NPI.MasterPage.init(); 
});




