/**
 * ican - common - tools.js
 * 
 * 入力支援ツール集
 */
/********************
  初期化
********************/
    ICAN.namespace('Common.Wickey.Tip');
    ICAN.namespace('Common.Wickey.Module');
    ICAN.Common.Wickey.Tip._ready = false;
    YAHOO.util.Event.addListener(window, 'load', function(){ ICAN.Common.Wickey.Tip._ready = true; });
    
    
/********************
  TIP
********************/
    /**
     * TIPをオープン、もしくはクローズする
     * @access     public
     * @param      object  tool   ツールノード
     */
    ICAN.Common.Wickey.Tip._tips = [];
    ICAN.Common.Wickey.Tip.open = function(id, event)
    {
        if(!ICAN.Common.Wickey.Tip._ready) return;
        
        //既に表示されているものがあれば閉じる
        var Panel = null;
        this._tips.each(function(ele){
            if(ele.id == id){
                Panel = ele;
                if(Panel._display){
                    Panel.hide();
                } else {
                    Panel.show();
                }
            } else {
                ele.hide();
            }
        });
        
        //未作成の場合は作成
        if(!Panel){
            var event = event || window.event;
            var option = {
                width : '300px',
                x : Event.pointerX(event) + 10,
                y : Event.pointerY(event) - 20,
                fixedcenter : false,
                constraintoviewport : true,
                underlay : 'shadow',
                close : true,
                visible : false,
                draggable : false,
                modal : false,
                draggable : true
            };
            $(id).style.display = '';
            var Panel = new YAHOO.widget.Panel(id, option);
            ICAN.Common.Wickey._setStyle4Panel(Panel);
            Panel.render();
            Panel.old_show = Panel.show;
            Panel.old_hide = Panel.hide;
            Panel.show = function(){
                this.old_show();
                this._display = true;
            };
            Panel.hide = function(){
                this.old_hide();
                this._display = false;
            };
            Panel.show();
            this._tips.push(Panel);
        }
    };
    
    
    /**
     * パネルのデザインを整える
     * @access     public
     * @param      object  Panel
     */
    ICAN.Common.Wickey._setStyle4Panel = function(Panel)
    {
        //初期化
        if(!Panel) return;
        var header = Panel.header.style;
        var body   = Panel.body.style;
        //ヘッダー
        header.textAlign = 'left';
        header.fontSize = '12px';
        header.padding = '3px';
        //ボディ
        body.padding = '5px';
    };
    
    
    
    
    
/*====================
  MODULE
====================*/
    /**
     * コンテンツを切り替える
     * @access     public
     */
    ICAN.Common.Wickey.Module.swapTab = function(id, tab)
    {
        if(!$(id)) return false;
        //タブの切り替え
        $A($('module_menu').childNodes).each(function(ele){ ele.firstChild.setAttribute('className', ''); });
        tab.setAttribute('className', 'selected');
        //コンテンツの切り替え
        document.getElementsByClassName('module_content').each(function(ele){ ele.style.display = 'none'; });
        $(id).style.display = 'block';
    };
