var tType = Tween.regularEaseInOut;
var tTime = 0.3;
(MIT.WNDW = {
  CONST_CLOSED    : 0,
  CONST_MINIMIZED : 1,
  CONST_MAXIMIZED : 2,
  zIndex          : 1000,
  windows         : [],
  init : function(theme)
  {
    MIT.WNDW.images = '/images/' + theme + '/';
  },
  add : function(name, title, content, w, h, target, state, x, y, from)
  {
    x = x ? x : parseInt(_('zone_main').offsetWidth / 2) - parseInt(w / 2);
    y = y ? y : parseInt(_('zone_main').offsetHeight / 2) - parseInt(h / 2);
    state = state ? state : MIT.WNDW.CONST_MAXIMIZED;
    if(typeof(MIT.WNDW.windows[name]) == 'undefined')
    {
      MIT.WNDW.zIndex++;
      MIT.WNDW.windows[name] = {
        name    : name,
        zIndex  : MIT.WNDW.zIndex,
        target  : target,
        title   : title,
        state   : state,
        x       : x,
        y       : y
      }
    }
    else
    {
      MIT.WNDW.maximize(name);
      return false;
    }

    ch = h - 22;
    var body = $n('body')[0];
    var div_main = $c('div');
    div_main.id = 'wndw_window_' + name;
    div_main.className = 'wndw_window';
    $s(div_main, 'width', w + 'px');
    $s(div_main, 'height', h + 'px');
    $s(div_main, 'z-index', MIT.WNDW.windows[name].zIndex);
    MIT.EVNT.add(div_main, 'click', function(){
      MIT.WNDW._onClick(div_main);
    });
    div_main['window_name'] = name;

    opacity = 1;
    var table_main = $c('table');
    table_main.border = '0';
    table_main.width = '100%';
    table_main.height = '100%';
    $s(table_main ,'height', '100%');
    table_main.cellPadding = '0';
    table_main.cellSpacing = '0';
    var table_tbody = $c('tbody');
    table_main.appendChild(table_tbody);
    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.height = '32';
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'tl.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'tl.png)');
      table_tr1.appendChild(table_td1);

      var table_td2 = $c('td');
      $s(table_td2, 'background-image', 'url(' + MIT.WNDW.images + 'tc.png)');
      if (isIE) $s(table_td2, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'tc.png)');
      table_tr1.appendChild(table_td2);

      var div_title = $c('div');
      div_title.id = 'wndw_title_' + name;
      div_title.className = 'wndw_title';
        div_table = $c('table');
        //$s(div_table, 'background-image', 'url(' + MIT.WNDW.images + 'wndw_title_back.png)');
        div_table.width = '100%';
        div_table.height = '100%';
        div_table.cellSpacing = '0';
        div_table.cellPadding = '1';
          div_tbody = $c('tbody');
            div_tr = $c('tr');
              div_td1 = $c('td');
              div_td1.id = 'wndw_caption_' + name;
              div_td1.className = 'wndw_caption';
              div_td1.innerHTML = title;
              div_td2 = $c('td');
              div_td2.id = 'wndw_close_' + name;
              div_td2.className = 'wndw_close';
              div_td2.innerHTML = '<img class="opacity50" align="absmiddle" onclick="MIT.WNDW.close(\'' + name + '\')" src="' + MIT.WNDW.images + 'close.png" onmouseover="$s(this, \'opacity\', \'1\');" onmouseout="$s(this, \'opacity\', \'.5\');">';

              if (target)
              {
                div_td3 = $c('td');
                div_td3.id = 'wndw_minimize_' + name;
                div_td3.className = 'wndw_minimize';
                div_td3.innerHTML = '<img class="opacity50" align="absmiddle" onclick="MIT.WNDW._switch(\'' + name + '\')" src="' + MIT.WNDW.images + 'minimize.png" onmouseover="$s(this, \'opacity\', \'1\');" onmouseout="$s(this, \'opacity\', \'.5\');">';
              }

            div_tr.appendChild(div_td1);

            if (target)
            {
              div_tr.appendChild(div_td3);
            }
            div_tr.appendChild(div_td2);
          div_tbody.appendChild(div_tr);
        div_table.appendChild(div_tbody);
      div_title.appendChild(div_table);
    table_td2.appendChild(div_title);

      var table_td3 = $c('td');
      table_td3.height = '32';
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'tr.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'tr.png)');
      table_tr1.appendChild(table_td3);
    table_tbody.appendChild(table_tr1);
    if(opacity > 0 && opacity < 1) $s(table_tr1, 'opacity', opacity);

    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'l.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'l.png)');
      table_tr1.appendChild(table_td1);
      if(opacity > 0 && opacity < 1) $s(table_td1, 'opacity', opacity);

      var table_td_main = $c('td');
      table_td_main.vAlign = 'top';
      table_td_main.bgColor = 'white';
      table_tr1.appendChild(table_td_main);

      var table_td3 = $c('td');
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'r.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'r.png)');
      table_tr1.appendChild(table_td3);
      if(opacity > 0 && opacity < 1) $s(table_td3, 'opacity', opacity);
    table_tbody.appendChild(table_tr1);

    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.height = '16';
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'bl.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'bl.png)');
      table_tr1.appendChild(table_td1);

      var table_td2 = $c('td');
      $s(table_td2, 'background-image', 'url(' + MIT.WNDW.images + 'bc.png)');
      if (isIE) $s(table_td2, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'bc.png)');
      table_tr1.appendChild(table_td2);

      var table_td3 = $c('td');
      table_td3.height = '16';
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'br.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'br.png)');
//      $s(table_td3, 'cursor', 'se-resize');
      table_tr1.appendChild(table_td3);
    table_tbody.appendChild(table_tr1);
    if(opacity > 0 && opacity < 1) $s(table_tr1, 'opacity', opacity);

    div_main.appendChild(table_main);
    var div_content = $c('div');
    div_content.id = 'wndw_content_' + name;
    div_content.className = 'wndw_content';
    $s(div_content, 'width', '92%');
    $s(div_content, 'height', '82%');
    $s(div_content, 'overflow', 'auto');
    $s(div_content, 'position', 'absolute');
//    $s(div_content, 'opacity', '0');

    table_td_main.appendChild(div_content);

    $s(div_main, 'left', x + 'px');
    $s(div_main, 'top', y + 'px');

    body.appendChild(div_main);

    div_td1.innerHTML = title;
    if (content.indexOf('.php') > 0)
    {
      doReq({url:content, onLoadParam:div_content, onLoad:MIT.WNDW._onLoaded});
    }
    else
    {
      div_content.innerHTML = content;
    }

    Drag.init(div_td1,  div_main,  0, 30, getW() - div_main.offsetWidth, getH() - div_main.offsetHeight - 30);
    div_main.onDragStart = MIT.WNDW._onDragStart;
    div_main.onDragEnd = MIT.WNDW._onDragEnd;
    div_td1.dblclick('MIT.WNDW._switch("' + name + '")');
    if (target)
    {
      MIT.WNDW.addToBar(name);
    }

    t1 = new OpacityTween(div_main,tType, 0, 100, tTime);
//    t1.addListener({
//      onMotionStarted:function()
//      {
//        if (content.indexOf('.php') > 0)
//        {
//          doReq({url:content, onLoadParam:div_content, onLoad:MIT.WNDW._onLoaded});
//        }
//        else
//        {
//          div_content.innerHTML = content;
//        }
//      }
//    });
    t1.start();
    MIT.WNDW.saveWindowStates();
  },
  saveWindowStates : function()
  {
    var windows = [];
    for (wndw in this.windows)
    {
      windows.push(this.windows[wndw].name + ':' + this.windows[wndw].zIndex + ':' + this.windows[wndw].target + ':' + this.windows[wndw].title + ':' + this.windows[wndw].state + ':' + this.windows[wndw].x + ':' + this.windows[wndw].y);
    }
    doReq({url:'fesa.router.php?c=tw.savewindows', data:{windows:windows.join('|')}});
  },
  _onLoaded : function(to, data)
  {
    to.innerHTML = data;
  },
  _onDragStart : function(x, y, o)
  {
    MIT.WNDW.zIndex++;
    MIT.WNDW.windows[o.root.window_name].zIndex = MIT.WNDW.zIndex;
    o.root._exindex = MIT.WNDW.zIndex;
  },
  _onDragEnd : function(x, y, o)
  {
    MIT.WNDW.zIndex++;
    MIT.WNDW.windows[o.root.window_name].zIndex = MIT.WNDW.zIndex;
    MIT.WNDW.windows[o.root.window_name].x = x;
    MIT.WNDW.windows[o.root.window_name].y = y;
    o.root._exindex = MIT.WNDW.zIndex;
    //$s(o.root, 'opacity', 1);
    MIT.WNDW.saveWindowStates();
  },
  _onClick : function(o)
  {
    if (typeof(MIT.WNDW.windows[o.window_name]) == 'object')
    {
      MIT.WNDW.zIndex++;
      MIT.WNDW.windows[o.window_name].zIndex = MIT.WNDW.zIndex;
      $s(o, 'z-index', MIT.WNDW.zIndex);
      //$s(o, 'opacity', 1);
    }
  },
  close : function(name)
  {
    var wndw  = _('wndw_window_' + name);
    var body = $n('body')[0];
    t1 = new OpacityTween(wndw,tType, 100, 0, tTime);
    t1.addListener({onMotionFinished:function(){
      body.removeChild(wndw);
      if (MIT.WNDW.windows[name].target)
      {
        MIT.WNDW.removeFromBar(name);
      }
      delete MIT.WNDW.windows[name];
      MIT.WNDW.saveWindowStates();
    }});
    t1.start();
  },
  closeTo : function(name, to)
  {
    name = name.replace('wndw_window_', '');
    var wndw  = _('wndw_window_' + name);
    var body = $n('body')[0];
    var to = typeof(to) == 'string' ? _(to) : to;

    t1 = new Parallel();
    t1.addChild(new Tween(wndw.style,'width'  ,tType, wndw.offsetWidth,   to.offsetWidth, tTime,  'px'));
    t1.addChild(new Tween(wndw.style,'height' ,tType, wndw.offsetHeight,  to.offsetHeight,  tTime,  'px'));
    t1.addChild(new Tween(wndw.style,'left'   ,tType, wndw.offsetLeft,    to.offsetLeft,  tTime,  'px'));
    t1.addChild(new Tween(wndw.style,'top'    ,tType, wndw.offsetTop,     to.offsetTop, tTime,  'px'));
    t1.addChild(new OpacityTween(wndw ,tType, 100, 0, tTime));
    t1.addListener({onMotionFinished:function(){
      body.removeChild(wndw);
      if (MIT.WNDW.windows[name].target)
      {
        MIT.WNDW.removeFromBar(name);
      }
      delete MIT.WNDW.windows[name];
      MIT.WNDW.saveWindowStates();
    }});
    t1.start();
  },
  _switch : function(name)
  {
    if(MIT.WNDW.windows[name].state == MIT.WNDW.CONST_MINIMIZED)
    {
      MIT.WNDW.maximize(name);
    }
    else if(MIT.WNDW.windows[name].state == MIT.WNDW.CONST_MAXIMIZED)
    {
      MIT.WNDW.minimize(name);
    }
    MIT.WNDW.saveWindowStates();
  },
  minimize : function(name)
  {
    if(MIT.WNDW.windows[name].state == MIT.WNDW.CONST_MAXIMIZED)
    {
      MIT.WNDW.windows[name].state = MIT.WNDW.CONST_MINIMIZED;
      var wndw  = _('wndw_window_' + name);
      t1 = new Parallel();
//      alert(typeof(wndw.attr));
      wndw.setAttribute('tWidth', wndw.offsetWidth);
      wndw.setAttribute('tHeight', wndw.offsetHeight);
      wndw.setAttribute('tLeft', wndw.offsetLeft);
      wndw.setAttribute('tTop', wndw.offsetTop);
      t1.addChild(new Tween(wndw.style,'width'  ,tType, wndw.offsetWidth,   100, tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'height' ,tType, wndw.offsetHeight,  30,  tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'left'   ,tType, wndw.offsetLeft,    10,  tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'top'    ,tType, wndw.offsetTop,     _('zone_main').offsetHeight - 34, tTime,  'px'));
      t1.addChild(new OpacityTween(wndw ,tType, 100, 0, tTime));
      t1.start();
//      $s(wndw, 'display', 'none');
    }
  },
  maximize : function(name)
  {
    MIT.WNDW._onClick(MIT.WNDW.windows[name]);
    if(MIT.WNDW.windows[name].state == MIT.WNDW.CONST_MINIMIZED)
    {
      MIT.WNDW.windows[name].state = MIT.WNDW.CONST_MAXIMIZED;
      var wndw  = _('wndw_window_' + name);
//      $s(wndw, 'display', '');

      t1 = new Parallel();
      t1.addChild(new Tween(wndw.style,'width'  ,tType, wndw.offsetWidth,   wndw.getAttribute('tWidth'), tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'height' ,tType, wndw.offsetHeight,  wndw.getAttribute('tHeight'),  tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'left'   ,tType, wndw.offsetLeft,    wndw.getAttribute('tLeft'),  tTime,  'px'));
      t1.addChild(new Tween(wndw.style,'top'    ,tType, wndw.offsetTop,     wndw.getAttribute('tTop'), tTime,  'px'));
      t1.addChild(new OpacityTween(wndw ,tType, 0, 100, tTime));
      t1.start();
    }
  },
  addToBar : function(name, content, target)
  {
    content = content === undefined ? '' : content;
    if (content)
    {
      var bar   = _('wndw_bar_items_' + target);
      var d = $c('div');
      d.id = 'wndw_bar_item_' + name;
      $s(d, 'float', 'left');
      d.innerHTML = '<div class="wndw_bar_item" onmouseout="$s(this, \'border\', \'2px solid #FFFFFF\');" onmouseover="$s(this, \'border\', \'2px solid #FF9922\');">' + content + '</div>';
      bar.appendChild(d);
    }
    else
    {
      var wObj = MIT.WNDW.windows[name];
      if (wObj.target)
      {
        var bar   = _('wndw_bar_items_' + wObj.target);
        var d = $c('div');
        d.id = 'wndw_bar_item_' + name;
        $s(d, 'float', 'left');
        d.innerHTML = '<div class="wndw_bar_item" onmouseout="$s(this, \'border\', \'2px solid #FFFFFF\');" onmouseover="$s(this, \'border\', \'2px solid #FF9922\');" onclick="MIT.WNDW._switch(\'' + name + '\')">' + wObj.title + ' <img class="opacity50" align="absmiddle" onclick="MIT.WNDW.close(\'' + name + '\')" src="' + MIT.WNDW.images + 'close.png" style="" onmouseover="$s(this, \'opacity\', \'1\');" onmouseout="$s(this, \'opacity\', \'.5\');"></div>';
        bar.appendChild(d);
      }
    }
  },
  removeFromBar : function(name)
  {
    var wObj = MIT.WNDW.windows[name];
    var bar   = _('wndw_bar_items_' + wObj.target);

    bar.removeChild(_('wndw_bar_item_' + name));
  },
  removeBar : function(name)
  {
    var div_main = _('wndw_bar_' + name);
    if (div_main.to)
    {
      _(div_main.to).remove(div_main);
    }
    else
    {
      $n('body')[0].removeChild(div_main);
    }
  },
  addBar : function(to, name, title, d, w, h, x, y)
  {
    to = (to === undefined || to == '' || to == false) ? $n('body')[0] : (typeof(to) == 'string' ? _(to) : to);
    w = w ? w : 0;
    h = h ? h : 0;
    x = x ? x : 0;
    y = y ? y : 0;

    dArr = {
      'lt' : 1,
      'rt' : 1,
      'lb' : 1,
      'rb' : 1,
      'tl' : 1,
      'tr' : 1,
      'bl' : 1,
      'br' : 1,
      'bc' : 1,
      'cb' : 1,
      'tc' : 1,
      'ct' : 1
    };

    if(typeof(d) != 'string' || dArr[d] != 1)
    {
      return false;
    }

    var div_main = $c('div');
    div_main.className = 'wndw_bar';
    if(w)
    {
      $s(div_main, 'width', w + 'px');
    }
    else
    {
      $s(div_main, 'width', 'auto');
    }
    if(h)
    {
      $s(div_main, 'height', 'auto');
    }

    xl = -16;
    yt = -16;
    yb = -16;
    xr = -16;
    yt = -16;

    if(d == 'lt' || d == 'tl')
    {
      $s(div_main, 'left', '-100px');
      $s(div_main, 'top', '-100px');
    }
    else if(d == 'lb' || d == 'bl')
    {
      $s(div_main, 'left', '-100px');
      $s(div_main, 'bottom', '-100px');
    }
    else if(d == 'br' || d == 'rb')
    {
      $s(div_main, 'right', '-100px');
      $s(div_main, 'bottom', '-100px');
    }
    else if(d == 'tr' || d == 'rt')
    {
      $s(div_main, 'right', '-100px');
      $s(div_main, 'top', '-100px');
    }
    else if(d == 'bc' || d == 'cb')
    {
      $s(div_main, 'right', '50%');
      $s(div_main, 'bottom', '100px');
    }
    else if(d == 'tc' || d == 'ct')
    {
      $s(div_main, 'right', '50%');
      $s(div_main, 'top', '-100px');
    }

    $s(div_main, 'z-index', '32100');
    div_main['bar_name'] = name;

    opacity = 0.3;
    var table_main = $c('table');
    table_main.border = '0';
//    table_main.width = '100%';
//    table_main.height = '100%';
//    $s(table_main ,'height', '100%');
    table_main.cellPadding = '0';
    table_main.cellSpacing = '0';
    var table_tbody = $c('tbody');
    table_main.appendChild(table_tbody);
    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.height = '16';
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'ml.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'ml.png)');
      table_tr1.appendChild(table_td1);

      var table_td2 = $c('td');
      $s(table_td2, 'background-image', 'url(' + MIT.WNDW.images + 'mc.png)');
      if (isIE) $s(table_td2, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'mc.png)');
      table_tr1.appendChild(table_td2);

      var table_td3 = $c('td');
      table_td3.height = '16';
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'mr.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'mr.png)');
      table_tr1.appendChild(table_td3);
    table_tbody.appendChild(table_tr1);

    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'l.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'l.png)');
      table_tr1.appendChild(table_td1);

      var table_td_main = $c('td');
      table_td_main.vAlign = 'top';
      table_td_main.id = 'wndw_bar_items_' + name;
      table_tr1.appendChild(table_td_main);

      var table_td3 = $c('td');
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'r.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'r.png)');
      table_tr1.appendChild(table_td3);
    table_tbody.appendChild(table_tr1);

    var table_tr1 = $c('tr');
      var table_td1 = $c('td');
      table_td1.height = '16';
      table_td1.width = '16';
      $s(table_td1, 'background-image', 'url(' + MIT.WNDW.images + 'bl.png)');
      if (isIE) $s(table_td1, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'bl.png)');
      table_tr1.appendChild(table_td1);

      var table_td2 = $c('td');
      $s(table_td2, 'background-image', 'url(' + MIT.WNDW.images + 'bc.png)');
      if (isIE) $s(table_td2, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'bc.png)');
      table_tr1.appendChild(table_td2);

      var table_td3 = $c('td');
      table_td3.height = '16';
      table_td3.width = '16';
      $s(table_td3, 'background-image', 'url(' + MIT.WNDW.images + 'br.png)');
      if (isIE) $s(table_td3, 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' + MIT.WNDW.images + 'br.png)');
      table_tr1.appendChild(table_td3);
    table_tbody.appendChild(table_tr1);
    div_main.appendChild(table_main);
    to.appendChild(div_main);
    div_main.attr('to', to.id ? to.id : '');
    div_main.attr('id', 'wndw_bar_' + name);

    t1 = new Parallel();
    if(d == 'lt' || d == 'tl')
    {
      $s(div_main, 'left', xl + 'px');
      $s(div_main, 'top', yt + 'px');
      t1.addChild(new Tween(div_main.style,'left'    ,tType, -100,     xl, tTime,  'px'));
      t1.addChild(new Tween(div_main.style,'top'    ,tType, -100,     yt, tTime,  'px'));
    }
    else if(d == 'lb' || d == 'bl')
    {
      $s(div_main, 'left', xl + 'px');
      $s(div_main, 'bottom', yb + 'px');
      t1.addChild(new Tween(div_main.style,'left'    ,tType, -100,     xl, tTime,  'px'));
      t1.addChild(new Tween(div_main.style,'bottom'    ,tType, -100,     yb, tTime,  'px'));
    }
    else if(d == 'br' || d == 'rb')
    {
      $s(div_main, 'right', xr + 'px');
      $s(div_main, 'bottom', yb + 'px');
      t1.addChild(new Tween(div_main.style,'right'    ,tType, -100,     xr, tTime,  'px'));
      t1.addChild(new Tween(div_main.style,'bottom'    ,tType, -100,     yb, tTime,  'px'));
    }
    else if(d == 'tr' || d == 'rt')
    {
      $s(div_main, 'right', xr + 'px');
      $s(div_main, 'top', yt + 'px');
      t1.addChild(new Tween(div_main.style,'right'    ,tType, -100,     xr, tTime,  'px'));
      t1.addChild(new Tween(div_main.style,'top'    ,tType, -100,     yt, tTime,  'px'));
    }
    else if(d == 'bc' || d == 'cb')
    {
      $s(div_main, 'right', '50%');
      $s(div_main, 'bottom', yb + 'px');
      t1.addChild(new Tween(div_main.style,'top'    ,tType, 100,     yb, tTime,  'px'));
    }
    else if(d == 'tc' || d == 'ct')
    {
      $s(div_main, 'right', '50%');
      $s(div_main, 'top', yt + 'px');
      t1.addChild(new Tween(div_main.style,'top'    ,tType, -100,     yt, tTime,  'px'));
    }
    t1.start();
  },
  this_window : function(ths)
  {
    while(1)
    {
      if (ths.tagName.toLowerCase() == 'body') return false;
      if (typeof(ths.id) == 'string')
      {
        if (ths.id.indexOf('wndw_window_') >= 0)
        {
          return ths.id;
        }
      }
        ths = ths.offsetParent;
    }
  }
});