/**
* Gestor del menú principal
*
* Funciones para manejar el menu y submenus
* @package SISTEMA
* @subpackage MENU
* @author Manuel Segura
* @version 1.0
* @copyright OVALUS
*/

function cMenu()
{
	// Rutas
	this.sPathSWF		= "";
	this.sPathPHP		= "";
	this.sPathNEW		= "";
	this.sPathPRO		= "";
	this.sPathACT		= "";
	this.sPathCON		= "";
	this.sLang			= "";

	// Menu activo
	this.idMenu			= 0;

	// Menus visibles SWF o PHP
	this.idMenuSWF		= -1;
	this.idMenuPHP		= -1;

	// Que visor esta activo
	this.sType			= "";

	// Temporizador
	this.idTimer		= 0;

	// Página PHP activa
	this.sPagePHP		= "";

	// Buffer de activación de menú
	this.sPagePHP		= "";

	// Procedimientos
	this.init 			= fMenu_Init;
	this.show 			= fMenu_Show;
	this.swap 			= fMenu_Swap;
	this.getID 			= fMenu_GetID;
	this.setOption		= fMenu_SetOption;
	this.setPagePHP		= fMenu_SetPagePHP;
	this.eventTimer		= fMenu_EventTimer;
	this.clearTimer		= fMenu_ClearTimer;
};

function fMenu_Init(idMenu,sPath,sPathSWF,sLang)
{
	this.sPathSWF = sPathSWF;
	this.sPathPHP = sPath+'view';
	this.sPathIMG = sPath+'media/images/';

	this.sLang = sLang;
	if (idMenu) this.show(idMenu,sLang);
};

function fMenu_Show(idMenu,sLang,sPage)
{
	var aPages		= new Array("","","where.php","catalog.php","news.php","members.php","actions.php","contact.php","","legal.php","privacy.php","conditions.php");
	var flashvars 	= {pLang:this.sLang};
	var params 		= {menu:"false",quality:"hight",scale:"showall",wmode:"opaque"};
	var attributes 	= {id:"swf",name:"swf"};

	this.idMenu = idMenu;
	switch(idMenu)
	{
					// HOME
		case 0: 	this.swap("SWF");
					flashvars = {pLang:this.sLang,pPath:this.sPathIMG};
					if (this.idMenuSWF!=idMenu) swfobject.embedSWF(this.sPathSWF+"home.swf", "swf", "840px", "505px", "9.0.0",this.sPathSWF+"expressInstall.swf", flashvars, params, attributes);
					this.idMenuSWF=idMenu;
					break;
					// PHILOSOPHY
		case 1: 	this.swap("SWF");
					if (this.idMenuSWF!=idMenu) swfobject.embedSWF(this.sPathSWF+"philosophy.swf", "swf", "840px", "505px", "9.0.0",this.sPathSWF+"expressInstall.swf", flashvars, params, attributes);
					this.idMenuSWF=idMenu;
					break;
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
		case 11:	this.swap("PHP");
					oFrame = gBrowser.findObj('build');
					if (this.idMenuPHP!=idMenu || this.sPagePHP!=aPages[idMenu] || sPage!='')
					{

						if (sPage==undefined || sPage=="")
						{
							oFrame.src = "/views/" + aPages[idMenu];
							this.sPagePHP = aPages[idMenu];
						}
						else
						{
							oFrame.src = "/views/" + sPage;
							this.sPagePHP = sPage;
						};
					};
					this.idMenuPHP=idMenu;
					break;
	};
};

function fMenu_Swap(sType)
{
	var oSWF	 	= gBrowser.findObj("contentswf");
	var oPHP	 	= gBrowser.findObj("contentphp");

	if (this.sType!=sType)
	{
		switch(sType)
		{
			case "SWF":	gBrowser.changeStyle(oPHP,"display","none");
					gBrowser.changeStyle(oSWF,"display","block");
					break;
			case "PHP":	gBrowser.changeStyle(oSWF,"display","none");
					gBrowser.changeStyle(oPHP,"display","block");
					break;
		};
		this.sType=sType;
	};
};

function fMenu_GetID()
{
	return this.idMenu;
};

function fMenu_SetPagePHP(sPage)
{
	this.sPagePHP = sPage;
};

function fMenu_SetOption(idMenu)
{
	var oMenuSWF	= gBrowser.findObj("menuswf");

	if (oMenuSWF)
	{
		this.clearTimer();
		if (this.idMenuPHP!=idMenu)
		{
			oMenuSWF.SetVariable("/:pMenu",idMenu);
			oMenuSWF.TGotoFrame("/",4);
			oMenuSWF.TPlay("/");
			this.idMenuPHP=idMenu;
		};
	}
	else this.idTimer = setInterval("gMenu.eventTimer("+idMenu+")",2000);
};

function fMenu_EventTimer(idMenu)
{
	var oMenuSWF	= gBrowser.findObj("menuswf");
	if (oMenuSWF)
	{
		this.clearTimer();
		this.setOption(idMenu);
	};
};

function fMenu_ClearTimer()
{
	if (this.idTimer) clearInterval(this.idTimer);
	this.idTimer = 0;
};


var gMenu = new cMenu();