﻿tabControl = function() { };

tabControl.prototype.cancelLoad = false;
tabControl.prototype.o_tabcontrol = null;
tabControl.prototype.o_tablist = null;
tabControl.prototype.v_current = null;

tabControl.prototype.init = function() {
    this.o_tabcontrol = $('.tab_control');
    var s = this, iload = null;
    if (this.o_tabcontrol.length > 0) {
        this.o_tablist = $('.tab_control > ul.tabs');
        this.o_tablist.find('li').each(function() {
            var index = arguments[0],
                o = $(this).find('a'),
                h = o.attr('href').replace('#', '');
            o.bind('click', function() { s.load(s, h); return false; });
            o.bind('mouseover', function() {
                if (h != s.v_current) {
                    $(this).css('background', 'url(/_common/img/tabcontrol_sprite_on.gif)')
                        .find('span').css('background', 'url(/_common/img/tabcontrol_sprite_on.gif)');
                }
            });
            o.bind('mouseout', function() {
                if (h != s.v_current) {
                    $(this).css('background', 'url(/_common/img/tabcontrol_sprite_off.gif)')
                        .find('span').css('background', 'url(/_common/img/tabcontrol_sprite_off.gif)');
                }
            });
            if (index == 0) iload = o.attr('href');
        });
        this.load(this, iload);
    }
};

tabControl.prototype.load = function() {
    var s = arguments[0], tab = $('div#' + arguments[1].replace('#', '')), h = arguments[1];
    if (s.v_current != null) {
        $('div#' + s.v_current).css({ display: 'none' });
        try {
            $("a[href$='" + s.v_current + "']").css('background', 'url(/_common/img/tabcontrol_sprite_off.gif) top right')
            .find('span').css('background', 'url(/_common/img/tabcontrol_sprite_off.gif');
        } catch (ovc) { }
    }
    if (tab.length > 0) { tab.css({ display: 'block' }); s.v_current = arguments[1].replace('#', ''); }
    try {
        $("a[href$='" + h + "']").css('background', 'url(/_common/img/tabcontrol_sprite_on.gif) top right')
            .find('span').css('background', 'url(/_common/img/tabcontrol_sprite_on.gif');
    }
    catch (oec) {
    }
};

$(document).ready(function() {
    tc = new tabControl();
    if (!tc.cancelLoad) {
        tc.init();
    }
});
