﻿/// <reference name="MicrosoftAjax.js"/>
// var tabsObject = $create(Soft202.Tabs, { titleCSS: "title", titleHoverCSS: "titleHover", titleCheckedCSS: "titleChecked", contentShowCSS: "Conten", contentHideCSS: "ContenHide" }, null, null, $get(tabs[i]));
Type.registerNamespace("Soft202");

Soft202.Tabs = function(element) {
    Soft202.Tabs.initializeBase(this, [element]);
    this.titles = null;
    this.contents = null;
    this.links = null;
    this.titleCSS = "title";
    this.titleHoverCSS = "titleHover";
    this.titleCheckedCSS = "titleChecked";
    this.contentShowCSS = "contentShow";
    this.contentHideCSS = "contentHide";
    this.index = 0;
    this._titlecClickDelegate = null;
    this._titleHoverDelegate = null;
    this._titleOutDelegate = null;
}

Soft202.Tabs.prototype = {
    initialize: function() {
        Soft202.Tabs.callBaseMethod(this, 'initialize');
        this.titles = new Array();
        this.contents = new Array();
        this.links = new Array();
        this.initDelegate();

        // 在此处添加自定义初始化
    },
    //初始化委托
    initDelegate: function() {
        if (this._titlecClickDelegate === null) {
            this._titlecClickDelegate = Function.createDelegate(this, this.titleClickHandler);
        }
        if (this._titleHoverDelegate === null) {
            this._titleHoverDelegate = Function.createDelegate(this, this.titleHoverHandler);
        }
        if (this._titleOutDelegate === null) {
            this._titleOutDelegate = Function.createDelegate(this, this.titleOutHandler);
        }
    }
    ,
    set_contentShowCSS: function(value) {
        this.contentShowCSS = value;
    },
    set_contentHideCSS: function(value) {
        this.contentHideCSS = value;
    },
    set_index: function(value) {
        this.index = value;
    },
    set_titleCSS: function(value) {
        this.titleCSS = value;
    },
    set_titleHoverCSS: function(value) {
        this.titleHoverCSS = value;
    },
    set_titleCheckedCSS: function(value) {
        this.titleCheckedCSS = value;
    },
    AddTab: function(titleID, contentID, linkPath) {

        var title = $get(titleID);
        var content = $get(contentID);
        title.className = this.titleCSS;
        Array.add(this.titles, title);
        Array.add(this.contents, content);
        if (linkPath != "") {
            Array.add(this.links, linkPath);
            $addHandler(title, "click", this._titlecClickDelegate);
        }
        $addHandler(title, "mouseover", this._titleHoverDelegate);
        $addHandler(title, "mouseout", this._titleOutDelegate);
        this.SetState(0);
    },
    titleHoverHandler: function(e) {
        //e.target.className = this.titleHoverCSS;
        this.index = Array.indexOf(this.titles, e.target);
        this.SetState(this.index);
    },
    titleClickHandler: function(e) {

        this.index = Array.indexOf(this.titles, e.target);
        // this.SetState(this.index);

        window.open(this.links[this.index]);
    },
    titleOutHandler: function(e) {
        var myIndex = Array.indexOf(this.titles, e.target);
        if (this.index == myIndex) {
            e.target.className = this.titleCheckedCSS;
        }
        else {
            e.target.className = this.titleCSS;
        }

    },
    SetState: function(index) {
        var tab = this.titles[index];
        var content = this.contents[index];
        for (var i = 0; i < this.titles.length; i++) {
            this.contents[i].className = this.contentHideCSS;
            this.titles[i].className = this.titleCSS;
        }

        tab.className = this.titleCheckedCSS;
        content.className = this.contentShowCSS;
        // content.style.backgroundColor = "#ff0000";
    },
    dispose: function() {
        //在此处添加自定义释放操作
        Soft202.Tabs.callBaseMethod(this, 'dispose');
    }
}
Soft202.Tabs.registerClass('Soft202.Tabs', Sys.UI.Behavior);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
