/*
Class: DocktabGrf


License:
  MIT-style license.

Author:
  Takashi Mizohata <beatak@nydd.org>

Copyright:
  2008 [nydd](http://code.nydd.org/).

Code & Documentation:
  [nydd jslib](http://code.nydd.org/).
*/

var DocktabGrf = function (favicon)
{
  this.PIX_FRAME_WIDTH    = 10;
  this.PIX_MINIMUM_WIDTH  = 350;
  this.PIX_MINIMUM_HEIGHT = 200;
  this.PIX_OFFSET_TOP     = 34;
  this.PIX_OFFSET_BOTTOM  = this.PIX_OFFSET_TOP + this.PIX_FRAME_WIDTH;
  this.PIX_PADDING_BOTTOM = 300;
  this.SEC_TAB_DISAPPEAR  = 1.3;
  this.SEC_TAB_APPEAR     = 1.5

  this.elm        = {};
  this.elm.icon   = favicon;
  this.elm.tab    = $('#docktab div.tab.grf').get(0);
  this.elm.close  = $('img.close', this.elm.tab).get(0);
  this.elm.ok     = $('button.ok', this.elm.tab).get(0);

  this.isInitialized  = false;
  this.isLocal        = false;

  this.fnCache = {};
  this.fnCache.onResize     = jQuery.scope(this, this.onResize);
  this.fnCache.onClose      = jQuery.scope(this, this.onClose);

  this.onResize();
  $(window).bind('resize', this.fnCache.onResize);
  $(this.elm.close).bind('click', this.fnCache.onClose);
  $(this.elm.ok).bind('click', this.fnCache.onClose);
}


// SCRATCH PADS
// _______________________________________________________________________


























// ANIMATION METHODS
// _______________________________________________________________________


DocktabGrf.prototype.show = function ()
{
  var self = this;
  var obj = this.elm.tab;

  var init_y = (-parseInt(obj.style.height));
  obj.style.bottom = init_y + 'px';
  obj.style.visibility = 'visible';
  obj._y  = init_y;
  JSTweener.addTween(
    obj,
    {
      'delay'       : 0,
      '_y'          : -(this.PIX_PADDING_BOTTOM),
      'time'        : this.SEC_TAB_APPEAR,
      'transition'  : 'easeOutElastic',
      'onUpdate'    : function () { obj.style.bottom  = obj._y + 'px'; },
      'onComplete'  : function () {}
    }
  );
}


DocktabGrf.prototype.hide = function ()
{
  var obj = this.elm.tab;

  var goal_y = (-parseInt(obj.style.height));
  obj._y  = -(this.PIX_PADDING_BOTTOM);
  JSTweener.addTween(
    obj,
    {
      'delay'       : 0,
      '_y'          : goal_y,
      'time'        : this.SEC_TAB_DISAPPEAR,
      'transition'  : 'easeInQuart',
      'onUpdate'    : function () { obj.style.bottom  = obj._y + 'px'; },
      'onComplete'  : function () 
                      {
                        obj.style.visibility = 'hidden';
                      }
    }
  );
}


// ACCESS METHODS
// _______________________________________________________________________



// CALLBACK METHODS
// _______________________________________________________________________




// EVENT METHODS
// _______________________________________________________________________


DocktabGrf.prototype.onClose = function ()
{
  this.hide();
  PinupController.getInstance().reintroduceIcons(this.SEC_TAB_DISAPPEAR);
}


DocktabGrf.prototype.onResize = function ()
{
  var max_w = $(document.body).width();
  var max_h = $(document.body).height();
  var w = this.PIX_MINIMUM_WIDTH;
  this.elm.tab.style.width = w + 'px';
  this.elm.tab.style.left = Math.floor((max_w - w) / 2) + 'px';

  var h = this.PIX_MINIMUM_HEIGHT;
  this.elm.tab.style.height = (h + this.PIX_PADDING_BOTTOM) + 'px';
}


// INSTANCE UTILITY METHODS
// _______________________________________________________________________




// STATIC UTILITY METHODS
// _______________________________________________________________________


