/**
 * $Id: popupinterface.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
 */

/**
 * PopupInterface 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 PopupInterface
 */
function PopupInterface() {
    this.elemId  = null;
    this.visible = false;
    this.linked  = new Array;
    this.hide    = PopupInterface_Hide;
    this.show    = PopupInterface_Show;
    this.toggle  = PopupInterface_Toggle;
}

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

/**
 * Makes the object's element invisible.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function PopupInterface_Hide() {
    this.visible = false;
    var elem = document.getElementById(this.elemId);
    if (!elem) throw new Error('Unable to find element: '+this.elemId);
    elem.style.visibility = 'hidden';
    elem.style.left       = '0px';
    elem.style.top        = '0px';
    for (var i=0; i<this.linked.length; i++) {
        var elem = document.getElementById(this.linked[i]);
        elem.style.visibility = 'hidden';
        elem.style.left       = '0px';
        elem.style.top        = '0px';
    }
    return true;
}

/**
 * Makes the object's element visibile.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function PopupInterface_Show() {
    this.visible = true;
    if (document.getElementById(this.elemId)) document.getElementById(this.elemId).style.visibility = 'visible';
    for (var i=0; i<this.linked.length; i++) document.getElementById(this.linked[i]).style.visibility = 'visible';
    return true;
}

/**
 * Toggles the object's visibility.
 *
 * @access public
 * @since  v1.1
 * @return boolean
 */
function PopupInterface_Toggle() {
    if (this.visible) return this.hide();
    else              return this.show();
}
