/*
     **************************************************************************************
     *                                                               menuopcgraf_clas.js  *
     *  LLIBRERIA DE CLASES                                                               *
     *  Xavi Agut - maig de 2010                                                          *
     *  Clases per als menus basats en opcions gràfiques                                  *
     **************************************************************************************
*/

/*
   -----------------------------
   Clase per a gestionar el menu
   -----------------------------
*/

function clas_menuopcgraf(capamenu)
{
 this.capamenu = capamenu;
 this.arropcsmnu = new Array();
 this.opcactiva = "";
 this.numopcs = 0;

 this.vismenu = vismenu;
 this.vismenurapit = vismenurapit;
 this.novismenu = novismenu;
 /* Asignacio de les opcions del menu */
 this.opcsmnu = opcsmnu;
 /* Establecer la opcion activa inicial */
 this.opcactinimnu = opcactinimnu;
 /* Visualizar la opcion activa del menu */
 this.visopcactmnu = visopcactmnu;
 /* Establecer la nueva opcion activa */
 this.esopcactmnu = esopcactmnu;
 /* Restaurar situacio menu - Deixar sols la opcio activa */
 this.restmnu = restmnu;
 /* Restaurar situacio menu - Deixar sols la opcio activa */
 this.inimnu = inimnu;

}

/* Variable global */
var opc = "";

/*
   ================================
   Visualitzar Menu de forma rapida
   ================================
*/

function vismenurapit()
{
 $("#"+this.capamenu).fadeIn("slow");
 for (x=0;x<this.numopcs;x++)
     {
      opc = this.arropcsmnu[x];
      opc.visopcnor();
     }
 return true;
}

/*
   ================================
   Visualitzar Menu opcio per opcio
   ================================
*/

var glbopc = 0;
var glbnumopcs = 0;
var glbopcsmnu;

function vismenu()
{
 $("#"+this.capamenu).fadeIn("slow");
 glbopcsmnu = this.arropcsmnu;
 glbnumopcs = this.numopcs;
 recursiva_vismenu();
 glbopc=0;
}

function recursiva_vismenu()
{
 opc = glbopcsmnu[glbopc];
 opc.visopcnor();
 glbopc = glbopc + 1;
 if (glbopc < glbnumopcs)
    {
     setTimeout('recursiva_vismenu()',200);
    }
 else
    {
     return true;
    }
}


/*
   ==============
   Amagar el menu
   ==============
*/

function novismenu()
{
 $("#"+this.capamenu).fadeOut("slow");
 return true;
}

/*
   =======================
   Llevar la transparencia
   =======================
*/

function resmenu()
{
 $("#"+this.capamenu).css("filter",'alpha(opacity=100)');
 $("#"+this.capamenu).css("opacity",'1');
 return true;
}

/*
   ====================
   Fons semitransparent
   ====================
*/

function noresmenu()
{
 $("#"+this.capamenu).css("filter",'alpha(opacity=60)');
 $("#"+this.capamenu).css("opacity",'.6');
 return true;
}

/*
   ============================
   Asociar les opcions del menu
   ============================
*/

function opcsmnu(arropcs)
{
 this.arropcsmnu = arropcs;
 this.numopcs = this.arropcsmnu.length;
 return true;
}

/*
   =============================
   Establir opcio activa inicial
   =============================
*/

function opcactinimnu(opcactini)
{
 this.opcactiva = opcactini;
 return true;
}

/*
   ========================
   Visualitzar opcio activa
   ========================
*/

function visopcactmnu()
{
 opc = this.opcactiva;
 opc.visopcact();
 return true;
}

/*
   ============================
   Establir opcio activa actual
   ============================
*/

function esopcactmnu(newopcact)
{
 if (this.opcactiva != "")
    {
     opc = this.opcactiva;
     opc.novisopcact();
    }
 this.opcactiva = newopcact;
 opc = this.opcactiva;
 opc.visopcact();
 this.restmnu();
 return true;
}

/*
   ==============================
   Restaurar la situacio del menu
   ==============================
*/

function restmnu()
{
 for (x=0;x<this.numopcs;x++)
     {
      opc = this.arropcsmnu[x];
      opc.novisopcres();
     }
  return true;
}

/*
   ====================
   Inicialitzar el menú
   ====================
*/

function inimnu()
{
 for (x=0;x<this.numopcs;x++)
     {
      opc = this.arropcsmnu[x];
      opc.novisopcres();
      opc.novisopcact();
     }
  return true;
}


/*

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*/


/*
   ----------------------------------------
   Clase per a gestionar una opció del menu
   ----------------------------------------
*/

function clas_opcgraf(capaopcnor,capaopcres,capaopcact,descopc)
{
 this.capaopcnor = capaopcnor;
 this.capaopcres = capaopcres;
 this.capaopcact = capaopcact;
 this.descopc = descopc;
 this.esnor = false;
 this.esres = false;
 this.esact = false;

 this.novisopc = novisopc;
 this.visopcnor = visopcnor;
 this.novisopcnor = novisopcnor;
 this.visopcres = visopcres;
 this.novisopcres = novisopcres;
 this.visopcact = visopcact;
 this.novisopcact = novisopcact;
 this.novisdesc = novisdesc;
}

/*
   ========================
   NO VISUALITZAR UNA OPCIO
   ========================
*/

function novisopc()
{
 this.novisopcnor();
 this.novisopcres();
 this.novisopcact();
 return true;
}


/*
   ===========
   N O R M A L
   ===========
*/

/* Visualitzar */
function visopcnor()
{
 $("#"+this.capaopcnor).fadeIn("slow");
 this.esnor = true;
 return true;
}

/* Amagar Normal */
function novisopcnor()
{
 $("#"+this.capaopcnor).fadeOut("slow");
 this.esnor = false;
 return true;
}

/*
   =================
   R E S A L T A D A
   =================
*/

/* Visualitzar */
function visopcres()
{
 $("#"+this.capaopcres).fadeIn("slow");
 this.esres = true;
 if (this.descopc != "")
    {
     var pos = $("#"+this.capaopcnor).offset();
     var posx = pos.left;
     var posy = pos.top;
     var capa = this.capaopcnor;
     var ancho = $("#" + this.capaopcnor).outerWidth();
     var alto = $("#" + this.capaopcnor).outerHeight();

     posx = posx + ancho + 10;
     posy = posy + (alto/3);

     $("#cpamnudescopc").html(this.descopc);
     $("#cpamnudescopc").css("top",posy);
     $("#cpamnudescopc").css("left",posx);

     setTimeout('visdescopc()',1000);
    }
 return true;
}

/* Visualitzar descripción de la opción */
function visdescopc()
{
 $("#cpamnudescopc").fadeIn("slow");

 return true;
}

/* Amagar */
function novisopcres()
{
 this.novisdesc();
 $("#cpamnudescopc").html(" ");
 $("#"+this.capaopcres).fadeOut("slow");
 this.esres = false;
 return true;
}

/*
   ==============================================
   DEIXA DE VISUALITZAR LA DESCRIPCIO DE LA OPCIO
   ==============================================
*/

/* Visualitzar */
function novisdesc()
{
 $("#cpamnudescopc").fadeOut("slow");
 return true;
}

/*
   ===========
   A C T I V A
   ===========
*/

/* Visualitzar */
function visopcact()
{
 $("#"+this.capaopcact).fadeIn("slow");
 this.esact = true;
 return true;
}

/* Amagar */
function novisopcact()
{
 $("#"+this.capaopcact).fadeOut("slow");
 this.esact = false;
 return true;
}

