/**
 * $Id: delayedpopupinterface.js 64367 2009-02-20 01:56:36Z kchiu $
 * $Author: kchiu $
 * $Revision: 64367 $
 * $Name$
 * $Date: 2009-02-19 17:56:36 -0800 (Thu, 19 Feb 2009) $
 *
 * @jsRequire interfaces.Interface
 * @jsRequire interfaces.PopupInterface
 *
 *
 * @version    $Revision: 64367 $
 * @author     Philip Snyder <philip@pricegrabber.com>
 * @copyright  Copyright &copy; 2006, Philip Snyder, PriceGrabber.com
 * @see        interfaces.Interface
 */

/**
 * DelayedPopupInterface Constructor / Definition
 *
 * This interface is built on top of the Interface object
 * and is NOT intended to be instantiated directly. See
 * documentation on interfaces.Interface for a complete
 * explanation.
 *
 * @access public
 * @since  v1.1
 * @return DelayedPopupInterface
 */
function DelayedPopupInterface() {
    this.elemId      = null;
    this.visible     = false;
    this.linked      = new Array;
    this.timer       = null;
    this.delay       = null;
    this.hide        = DelayedPopupInterface_Hide;
    this.show        = DelayedPopupInterface_Show;
    this.toggle      = PopupInterface_Toggle;
    this.cancelTimer = DelayedPopupInterface_CancelTimer;
    this.implement(PopupInterface);
    return this;
}

// Setup DelayedPopupInterface prototype chain
DelayedPopupInterface.prototype             = new PopupInterface;
DelayedPopupInterface.prototype.constructor = DelayedPopupInterface;
DelayedPopupInterface.superclass            = PopupInterface.prototype;

/**
 * Calls PopupInterface_Hide after timer runs out.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function DelayedPopupInterface_Hide() {
    this.cancelTimer();
    var obj = this;
    this.timer = setTimeout(function() {
        PopupInterface_Hide.call(obj);
        obj.timer = null;
    }, this.delay);
    return true;
}

/**
 * Calls PopupInterface_Show after timer runs out.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function DelayedPopupInterface_Show() {
    this.cancelTimer();
    var obj = this;
    this.timer = setTimeout(function() {
        PopupInterface_Show.call(obj);
        obj.timer = null;
    }, this.delay);
    return true;
}

/**
 * Cancels any currently running timers.
 *
 * This effectively stops the show / hide / toggle
 * functions in their tracks, allowing us to cancel
 * them at any time.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function DelayedPopupInterface_CancelTimer() {
    if (this.timer) {
        clearTimeout(this.timer);
        this.timer = null;
    }
    return true;
}
