/*
 * Copyright (c) 2008 FIZON GmbH
 * All rights reserved.
 *
 * $Id: pmenu.js 1739 2008-08-04 07:50:26Z as $
 */
PMenu = function()
{

	/**
	 * construct()
	 */
	this.construct = function()
	{
		if (typeof PMenu.SingletonObj != 'undefined')
			return;

		PMenu.SingletonObj = this;
		this.page = PPage.Get();
		this.toolbar = PToolbar.Get();

		/* Box fuer die Menues */
		this.menuDiv = document.createElement('div');
		this.menuDiv.id = 'pmenu';
		this.menuDiv.style.position = 'fixed';
		this.menuDiv.style.zIndex = '10100';
		this.page.addObject(this.menuDiv);

		/* Box hinter den Menues */
		this.menuBackDiv = document.createElement('div');
		this.menuBackDiv.style.position = 'fixed';
		this.menuBackDiv.style.width = '100%';
		this.menuBackDiv.style.height = '100%';
		this.menuBackDiv.style.zIndex = '10000';
		this.menuBackDiv.setAttribute('onclick', 'PMenu.Click(0)');

		/* Menues */
		this.items = new PMenuItem;
		this.appItems = this.items.addItem('Programme');
	}


	/**
	 * addItem()
	 */
	this.addItem = function(title, onclick)
	{
		return this.items.addItem(title, onclick);
	}


	/**
	 * addApp()
	 */
	this.addApp = function(title, onclick)
	{
		return this.appItems.addItem(title, onclick);
	}


	/**
	 * getItem()
	 */
	this.getItem = function(id)
	{
		return PMenuItem.Get(id);
	}


	/**
	 * click()
	 */
	this.click = function(id)
	{
		var item = this.getItem(id);

		// wenn es um das oeffnen bzw.
		// schliessen des Menues geht.
		if (id == 0) {
			// muess geschlossen werden
			if (item.displayed) {
				this.page.removeObject(this.menuBackDiv);
				this.toolbar.html.menuA.className = '';
			}
			// muss geoefnet werden
			else {
				this.page.addObject(this.menuBackDiv);
				this.toolbar.html.menuA.className = 'active';
			}
		}
		return item.click();
	}


	this.construct();
}


/**
 * PMenu.Get()
 */
this.PMenu.Get = function()
{
	if (typeof PMenu.SingletonObj == 'undefined')
		new PMenu;
	return PMenu.SingletonObj;
}


/**
 * PMenu.Click()
 */
PMenu.Click = function(a1)
{
	return PMenu.Get().click(a1);
}
