﻿(function ($) {
    $.fn.customFadeIn = function (speed, callback) {
        $(this).fadeIn(speed, function () {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function (speed, callback) {
        $(this).fadeOut(speed, function () {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };


})(jQuery);

fader = function (id, _in) {
    if (_in) $('#' + id).customFadeIn('fast');
    if (!_in) $('#' + id).customFadeOut('fast');
}





jQuery.fn.tabs = function (t, i) {

    var formArea = $(this[0]);

    if (t == 'select') {
        var p = 0;
        // i is the index we want to show

        formArea.find('li').each(function () { $(this).removeClass('active'); });

        formArea.find('li').each(function () {
            var li = $(this);
            var a = $($(this).find('a')[0]);
            if (i == p) {
                li.addClass('active');
                $(a.attr('href')).css('display', 'block');
            } else {
                li.removeClass('active');
                $(a.attr('href')).css('display', 'none');
            }
            p += 1;
        });

        var g = {};
        g.index = i;

        formArea.trigger('tabsselect', g);
        return;
    }




    formArea.find('ul').addClass('safeTabs');

    $($(formArea.find('ul')[0]).find('li')[0]).addClass('active');

    formArea.find('li').each(function () {

        var a = $($(this).find('a')[0]);
        $(a.attr('href')).addClass('safeTabsDiv');
        if (!$(this).hasClass('active')) {
            $(a.attr('href')).css('display', 'none');

        }

        a.click(function () {
            var p = $(this).parent().parent(); p.find('li').removeClass('active'); $(this).parent().addClass('active');

            p.find('li').each(function () {

                var a = $($(this).find('a')[0]);

                if (!$(this).hasClass('active')) {
                    $(a.attr('href')).css('display', 'none');
                } else { $(a.attr('href')).css('display', 'block'); }


            });
            return false;
        });

    });

}

