<?php
defined('ROOT_DIR') or die(__FILE__.' requires egConfig.inc.php');

include_once(ROOT_DIR.'egList.class.php');
include_once(ROOT_DIR.'egMenuItem.class.php');

class egContextMenu extends egList{

	function egContextMenu($id, $posX = 0, $posY = 0, $width = 0, $height = 0) {
		parent::egList($id, '', $posX, $posY, $width, $height);
	}

	function getClassName() {
		return "egContextMenu";
	}

	function addMenuItem(&$item) {
		$this->addListItem($item);
	}

	function addSeparator() {
		$item = -1;
		$this->addListItem($item);
	}

	function getHTML($container = null) {
		$html = "var contextMenu_{$this->id} = new egContextMenu('{$this->id}', '{$this->posX}', '{$this->posY}', '{$this->width}', '{$this->height}', '{$container}');";

		for($i = 0; $i < count($this->itemsList); ++$i) {
			if($this->itemsList[$i] == -1) {
					$html .= "contextMenu_{$this->id}.addSeparator();";
			}
			else {
					$html .= "contextMenu_{$this->id}.addMenuItem('".$this->itemsList[$i]->getText()."','".$this->itemsList[$i]->getIcon()."','".$this->itemsList[$i]->getAction()."');";
			}
		}
		return $html;
	}

	/**
 	 *
	 *  @static
	 */
  function getScriptsFiles() {
    $scriptsArray = array();
    $scriptsArray[ALL] = "egContextMenu_default.js";
    return $scriptsArray;
  }

	/**
 	 *
	 *  @static
	 */
  function getStylesFiles() {
    $stylesArray = array();
    $stylesArray[ALL] = "egContextMenu_default.css";

    $stylesArray[INTERNET_EXPLORER] = array();

    $stylesArray[INTERNET_EXPLORER][ALL] = "egContextMenu_default.css";

    $stylesArray[INTERNET_EXPLORER]['6'] = array();
    $stylesArray[INTERNET_EXPLORER]['6'][ALL] = "egContextMenu_ie60.css";

    $stylesArray[INTERNET_EXPLORER]['7'] = array();
    $stylesArray[INTERNET_EXPLORER]['7'][ALL] = "egContextMenu_ie70.css";


    $stylesArray[FIREFOX] = array();

    $stylesArray[FIREFOX][ALL] = "egContextMenu_ff15.css";

    $stylesArray[FIREFOX]['1'] = array();
    $stylesArray[FIREFOX]['1'][ALL] = "egContextMenu_ff15.css";
    $stylesArray[FIREFOX]['1']['5'] = "egContextMenu_ff15.css";

    $stylesArray[FIREFOX]['2'] = array();
    $stylesArray[FIREFOX]['2'][ALL] = "egContextMenu_ff15.css";

    $stylesArray[SAFARI] = array();

    $stylesArray[SAFARI][ALL] = "egContextMenu_ff15.css";

    return $stylesArray;
  }
}

?>