//fuggosegek: 
if (typeof BROWSERDETECT == "undefined") {
  alert("(MENU) BROWSERDETECT include missing");
}
//tobbszoros include:
if (typeof MENU != "undefined") {
  alert("MENU multiple insert!");
}
MENU=true;

/** Egy menu funkcioit megvalosito osztaly
  * @param config parameterek objektuma
  */
function Menu(config) {
  this.id="";
  this.state=0;                                         //0 (nem lathato), 1 (elobujik), 2 (kint van), 3 (visszamegy)
  this.ulti=null;                                       //ultimatemenu framework
  this.timerId=null;                                    //timer
  this.items=new Array();                               //menupontok items[index]=id
  this.renderItems=new Array();                         //menupontok + szeparatorok
  this.size={width: 0, height: 0};                      //content div merete, nem valtozik es a dinamikus cuccok miatt kell

  this.highlightedIndex=null;                           //kijelolt menupont indexe
  this.actAnimation="";                                 //aktualis animacio, egtajak
  this.actPosition="";                                  //aktualis pozicio, egtajak

  this.node=null;                                       //kulso div node
  this.content=null;                                    //tablazatot arnyekot hatteret tartalmazo belso node

  this.setDefaults();
  this.readConfig(config);

  if (this.parentId == "") {
    throw new Error("menu: parentid undefined");
  }
  if (this.level == null) {
    throw new Error("menu: level undefined");
  }

  if (this.ulti == null) {
    throw new Error("menu: ulti undefined");
  }

}

/** Alapertelmezett beallitasok beallitasa :)
  */
Menu.prototype.setDefaults = function () {
  this.parentId="";
  this.direction=0;
  this.position="S";
  this.animation="";
  this.animationType=0;
  this.animationInterval=10;
  this.animationDelta=15;
  this.level=null;
  this.shadowSize=0;
  this.opacityBackground=0;
  this.shadows="";  
}

/** Érvenyes ertekekkel irja felul az alapertelmezett beallitasokat
  * @param config
  */
Menu.prototype.readConfig = function (config) {
  if (typeof config.parentId == 'string' && config.parentId != "") {
    this.parentId=config.parentId;
  }
  if (typeof config.direction == 'number' && 0 <= config.direction && config.direction <= 1) {
    this.direction=config.direction;
  }
  if (typeof config.position == 'string' 
      && (config.position == "N" || config.position == "W" || config.position == "S" || config.position == "E" 
        || config.position == "NW" || config.position == "NE" || config.position == "SW" || config.position == "SE")) {
    this.position=config.position;
  }
  if (typeof config.animation == 'string' 
      && (config.animation == "N" || config.animation == "W" || config.animation == "S" || config.animation == "E" 
        || config.animation == "NW" || config.animation == "NE" || config.animation == "SW" || config.animation == "SE")) {
    this.animation=config.animation;
  }
  if (typeof config.animationType == 'number' && 0 <= config.animationType && config.animationType <= 1) {
    this.animationType=config.animationType;
  }

  if (typeof config.animationInterval == 'number' && 0 < config.animationInterval) {
    this.animationInterval=config.animationInterval;
  }

  if (typeof config.animationDelta == 'number' && 0 < config.animationDelta) {
    this.animationDelta=config.animationDelta;
  }
  
  if (typeof config.level == 'number' && 0 <= config.level) {
    this.level=config.level;
  }
  if (typeof config.ultimateMenu == 'object') {
    this.ulti=config.ultimateMenu;
  }
  if (typeof config.shadowSize == 'number' && 0 <= config.shadowSize) {
    this.shadowSize=config.shadowSize;
  }
  if (typeof config.opacityBackground == 'number' && 0 <= config.opacityBackground && config.opacityBackground <= 1) {
    this.opacityBackground=config.opacityBackground;
  }
  if (typeof config.shadows == 'string' 
      && (config.shadows == 'N-E-NE' || config.shadows == 'N-W-NW' 
       || config.shadows == 'S-W-SW' || config.shadows == 'S-E-SE')) {
      this.shadows=config.shadows;
  }

  this.id=config.id;
  
}

/** Egy menupontot ad a menuhoz
  * @param cfg menupont beallitasok objektuma
  */
Menu.prototype.addItem = function (cfg) {
  cfg.type=0;
  this.renderItems[this.renderItems.length]=copyObject(cfg);
  this.items[this.items.length]=cfg.id;
}

/** Egy szeparatort ad a menuhoz
  */
Menu.prototype.addSeparator = function () {
  this.renderItems[this.renderItems.length]={type: 1};

}

/** Egy menupontot ertesit arrol, hogy szulo lett, van hozzatartozo almenu
  * @param itemId a menupont ID-ja
  */
Menu.prototype.notifyParent = function (itemId) {
  for (var i in this.renderItems) {
    if (typeof this.renderItems[i] == "object") {
      if (this.renderItems[i].id == itemId) {
        this.renderItems[i].parent=1;
      }
    }
  }
}

Menu.prototype.getIndexById = function(id) {
  for(var i=0; i<this.items.length; ++i) {
    if (this.items[i] == id) {
      return i;
    }
  }
  return null;
}

/** Egy menupontot vizualisan kivalasztotta tesz
  * @param id a menupont ID-ja
  */
Menu.prototype.highlight = function (id) {
  this.dehighlight();

  var node=this.ulti.getElem(id);
  this.highlightedIndex=this.getIndexById(id);
  addClass(node,this.ulti.classes['menuItemOn']);
  if (ieDOM && nodeHasAttribute(node.firstChild,'href')) {
    addClass(node.firstChild,this.ulti.classes['menuItemLinkOnC']);
  } else {
    addClass(node.firstChild,this.ulti.classes['menuItemLinkOn']);
  }
//  node.className='menuItemOn';
//  node.firstChild.className='menuItemLinkOn';        
  
}

/** Torli az eddigi kivalasztast
  */
Menu.prototype.dehighlight = function () {
  if (this.highlightedIndex != null) {
    var node=this.ulti.getElem(this.items[this.highlightedIndex]);
    removeClass(node,this.ulti.classes['menuItemOn']);
    if (ieDOM && nodeHasAttribute(node.firstChild,'href')) {
      removeClass(node.firstChild,this.ulti.classes['menuItemLinkOnC']);
    } else {
      removeClass(node.firstChild,this.ulti.classes['menuItemLinkOn']);
    }
//    node.className='menuItem';
//    node.firstChild.className='menuItemLink';        

    this.highlightedIndex=null;
  }
}

/** Kezdemenyezi a menu megjeleniteset, animacio eseten idozitett animacio elinditasa 
  */
Menu.prototype.animatedShow = function () {
  if (this.animation == "") {
    this.show();
  } else {
    this.state=1;
    if (this.timerId == null) {
      //most kezdjuk a kirakast

      this.setSize(); //frissiteni kell a meretet, hatha kozben megvaltozott

      //actAnimation meghatarozasa
      this.actAnimation=this.animation;
      var originalPos=this.moveMenuToPosition();
      if (this.animation == "N") {
        if (originalPos == false && this.actPosition != "E" && this.actPosition != "W") {
          //ellentetes irany lesz
          this.actAnimation="S";
        }
      } else if (this.animation == "W") {
        if (originalPos == false && this.actPosition != "E" && this.actPosition != "W") {
          //ellentetes irany lesz
          this.actAnimation="E";
        }
      } else if (this.animation == "S") {
        if (originalPos == false && this.actPosition != "E" && this.actPosition != "W") {
          //ellentetes irany lesz
          this.actAnimation="N";
        }
      } else if (this.animation == "E") {
        if (originalPos == false && this.actPosition != "E" && this.actPosition != "W") {
          //ellentetes irany lesz
          this.actAnimation="W";
        }
      }

      //meretet be kell allitani, mert eltuneskor kicsi maradhat, vagy eltuneskor kellene visszaallitani eredeti meretre
      setSize(this.node,this.size);
      //hideselect  a div-et odarakta a helyere a moveMenuToPosition, az animacio legfeljebb majd allitja
      //ezt itt kell, mert az animacio elronthatja az indulo meretet
//      this.hideSelects();
      if (ieDOM) {
        this.ulti.notifyShow(this);
      }

      
      if (this.actAnimation == "S") {
        if (this.animationType == 0) {
          setPos(this.content,{top: -1*this.size.height, left:0},false,true);
        } else if (this.animationType == 1) {
          setSize(this.node,{width: this.size.width, height:0});
          setPos(this.content,{top: 0, left:0},false,true);
        }
      } else if (this.actAnimation == "E") {
        if (this.animationType == 0) {
          setPos(this.content,{top: 0, left: -1*this.size.width},false,true);
        } else if (this.animationType == 1) {
          setSize(this.node,{width: 0, height: this.size.height});
          setPos(this.content,{top: 0, left:0},false,true);
        }
      } else if (this.actAnimation == "N") {
        if (this.animationType == 0) {
          setPos(this.content,{top: this.size.height, left:0},false,true);
        } else if (this.animationType == 1) {
          var top=getStyle(this.node,"top",true);
          var left=getStyle(this.node,"left",true);
          setSize(this.node,{width: this.size.width, height:0});
          setPos(this.node,{top: top+this.size.height, left: left});
          setPos(this.content,{top: -1*this.size.height,left:0},false,true);
        }
      } else if (this.actAnimation == "W") {
        if (this.animationType == 0) {
          setPos(this.content,{top: 0, left: this.size.width},false,true);
        } else if (this.animationType == 1) {
          var top=getStyle(this.node,"top",true);
          var left=getStyle(this.node,"left",true);
          setSize(this.node,{width: 0, height: this.size.height});
          setPos(this.node,{top: top, left: left+this.size.width});
          setPos(this.content,{top: 0,left: -1*this.size.width},false,true);
        }
      }

      
      var menu=this;
 
      setTimeout(function() {
          menu.node.style.visibility='visible'; 
          menu.timerId=setInterval(function(){menu.animate();},menu.animationInterval);
          },10);

    }
  }
}

/** Kezdemenyezi a menu eltunteteset, animacio eseten idozitett animacio elinditasa
  */
Menu.prototype.animatedHide = function () {
  if (this.animation == "") {
    this.hide();
  } else {
    this.state=3;
    if (this.timerId == null) {
      //most kezdjuk a befejezest
      var menu=this;
      this.timerId=setInterval(function(){menu.animate();},this.animationInterval);
    }
  }
}

/** Animalja a menut, elobujast es eltunest is kezeli, ha veget er az animacio leallitja az idozitest es meghivja a megfelelo triggereket
  */
Menu.prototype.animate = function () {
  var done=false;
  if (this.state == 1) {
    //elobujik
    if (this.actAnimation == "S") {
      if (this.animationType == 0) {
        var top=getStyle(this.content,"top",true);
        if (-1*top <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          top+=this.animationDelta;
          setPos(this.content,{top: top,left: 0},false,true);          
        }
      } else if (this.animationType == 1) {
        var height=getStyle(this.node,"height",true);
        if (this.size.height - height <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: this.size.height});
        } else {
          height+=this.animationDelta;
          setSize(this.node,{width: this.size.width,height: height});          
        }
      }
    } else if (this.actAnimation == "E") {
      if (this.animationType == 0) {
        var left=getStyle(this.content,"left",true);
        if (-1*left <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          left+=this.animationDelta;
          setPos(this.content,{top: 0,left: left},false,true);          
        }
      } else if (this.animationType == 1) {
        var width=getStyle(this.node,"width",true);
        if (this.size.width - width <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: this.size.height});
        } else {
          width+=this.animationDelta;
          setSize(this.node,{width: width,height: this.size.height});          
        }
      }
    } else if (this.actAnimation == "N") {
      if (this.animationType == 0) {
        var top=getStyle(this.content,"top",true);
        if (top <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          top-=this.animationDelta;
          setPos(this.content,{top: top,left: 0},false,true);          
        }
      } else if (this.animationType == 1) {
        var top=getStyle(this.node,"top",true);
        var left=getStyle(this.node,"left",true);
        var height=getStyle(this.node,"height",true);

        var dist=this.size.height - height;

        
        if (dist <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: this.size.height});
          setPos(this.node,{top: top-dist,left: left});
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          height+=this.animationDelta;
          setSize(this.node,{width: this.size.width,height: height});          
          setPos(this.node,{top: top-this.animationDelta,left: left});
          setPos(this.content,{top: height-this.size.height,left: 0},false,true);
        }
      }
    } else if (this.actAnimation == "W") {
      if (this.animationType == 0) {
        var left=getStyle(this.content,"left",true);
        if (left <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          left-=this.animationDelta;
          setPos(this.content,{top: 0,left: left},false,true);          
        }
      } else if (this.animationType == 1) {
        var top=getStyle(this.node,"top",true);
        var left=getStyle(this.node,"left",true);
        var width=getStyle(this.node,"width",true);

        var dist=this.size.width - width;

        
        if (dist <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: this.size.height});
          setPos(this.node,{top: top,left: left-dist});
          setPos(this.content,{top: 0,left: 0},false,true);
        } else {
          width+=this.animationDelta;
          setSize(this.node,{width: width,height: this.size.height});          
          setPos(this.node,{top: top,left: left-this.animationDelta});
          setPos(this.content,{top: 0,left: width - this.size.width},false,true);
        }
      }
    }

    if (done) {
      this.state=2;
      clearInterval(this.timerId);
      this.timerId=null;

      //animacio vegen meg kell nezni, nem volt-e kozben elrejtett mas menu
      if (ieDOM) {
        this.ulti.notifyAnimateEnd(this);
      }
      this.ulti.processRecentEvent();
    }
  } else if (this.state == 3) {
    //eltunik
    if (this.actAnimation == "S") {
      if (this.animationType == 0) {
        var top=getStyle(this.content,"top",true);
        if (this.size.height + top <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: -1*this.size.height,left: 0},false,true);
        } else {
          top-=this.animationDelta;
          setPos(this.content,{top: top,left: 0},false,true);          
        }
      } else if (this.animationType == 1) {
        var height=getStyle(this.node,"height",true);
        if (height <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: 0});
        } else {
          height-=this.animationDelta;
          setSize(this.node,{width: this.size.width,height: height});          
        }
      }
    } else if (this.actAnimation == "E") {
      if (this.animationType == 0) {
        var left=getStyle(this.content,"left",true);
        if (this.size.width + left <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: -1*this.size.width},false,true);
        } else {
          left-=this.animationDelta;
          setPos(this.content,{top: 0,left: left},false,true);          
        }
      } else if (this.animationType == 1) {
        var width=getStyle(this.node,"width",true);
        if (width <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: 0,height: this.size.height});
        } else {
          width-=this.animationDelta;
          setSize(this.node,{width: width,height: this.size.height});          
        }
      }
    } else if (this.actAnimation == "N") {
      if (this.animationType == 0) {
        var top=getStyle(this.content,"top",true);
        if (this.size.height - top <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: this.size.height,left: 0},false,true);
        } else {
          top+=this.animationDelta;
          setPos(this.content,{top: top,left: 0},false,true);          
        }
      } else if (this.animationType == 1) {        
        var top=getStyle(this.node,"top",true);
        var left=getStyle(this.node,"left",true);
        var height=getStyle(this.node,"height",true);

        var dist=this.size.height - height;

        
        if (height <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: this.size.width,height: 0});
          setPos(this.node,{top: top+dist,left: left});
          setPos(this.content,{top: -1*this.size.height,left: 0},false,true);
        } else {
          height-=this.animationDelta;
          setSize(this.node,{width: this.size.width,height: height});          
          setPos(this.node,{top: top+this.animationDelta,left: left});
          setPos(this.content,{top: height-this.size.height,left: 0},false,true);
        }
      }
    } else if (this.actAnimation == "W") {
      if (this.animationType == 0) {
        var left=getStyle(this.content,"left",true);
        if (this.size.width - left <= this.animationDelta) {
          done=true;
          setPos(this.content,{top: 0,left: this.size.width},false,true);
        } else {
          left+=this.animationDelta;
          setPos(this.content,{top: 0,left: left},false,true);          
        }
      } else if (this.animationType == 1) {
        var top=getStyle(this.node,"top",true);
        var left=getStyle(this.node,"left",true);
        var width=getStyle(this.node,"width",true);

        var dist=this.size.width - width;

        
        if (width <= this.animationDelta) {
          done=true;
          setSize(this.node,{width: 0,height: this.size.height});
          setPos(this.node,{top: top,left: left+dist});
          setPos(this.content,{top: 0,left: -1*this.size.width},false,true);
        } else {
          width-=this.animationDelta;
          setSize(this.node,{width: width,height: this.size.height});          
          setPos(this.node,{top: top,left: left+this.animationDelta});
          setPos(this.content,{top: 0,left: width - this.size.width},false,true);
        }
      }
    }

    if (done) {

      clearInterval(this.timerId);
      this.timerId=null;

      this.hide();  //visibility, state, selectek, dehighlight
      
    }
  }
}

/** A menut a beallitott poziciora probalja helyezni, ha nem sikerul, akkor atellenben lesz
  * @return eredeti poziciora kerult-e a menu
  */
Menu.prototype.moveMenuToPosition = function () {
  var pos={top: 0, left: 0};
  var parent=this.ulti.getElem(this.parentId);
  var parentPos=getPosBorder(parent);
  var parentWidth=getContentBorderWidth(parent);
  var parentHeight=getContentBorderHeight(parent);
//  var width=getContentBorderWidth(node);
//  var height=getContentBorderHeight(node);
  var width=this.size.width;
  var height=this.size.height;
  


  var originalPos=true;
  this.actPosition=this.position;
  
  if (this.position == "S") {
    var dim={top: parentPos.top+parentHeight,left: parentPos.left,bottom: parentPos.top+parentHeight+height,right: parentPos.left+width};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="N";
      originalPos=false;
      pos.top=parentPos.top-height;
      pos.left=parentPos.left;
    }
  } else if (this.position == "N") {
    var dim={top: parentPos.top-height,left: parentPos.left,bottom: parentPos.top,right: parentPos.left+width};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="S";
      originalPos=false;
      pos.top=parentPos.top+parentHeight;
      pos.left=parentPos.left;
    }
  } else if (this.position == "E") {
    var dim={top: parentPos.top,left: parentPos.left+parentWidth,bottom: parentPos.top+height,right: parentPos.left+parentWidth+width};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="W";
      originalPos=false;
      pos.top=parentPos.top;
      pos.left=parentPos.left-width;
    }
  } else if (this.position == "W") {
    var dim={top: parentPos.top,left: parentPos.left-width,bottom: parentPos.top+height,right: parentPos.left};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="E";
      originalPos=false;
      pos.top=parentPos.top;
      pos.left=parentPos.left+parentWidth;
    }
  } else if (this.position == "NW") {
    var dim={top: parentPos.top-height+parentHeight,left: parentPos.left-width,bottom: parentPos.top,right: parentPos.left};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="SE";
      originalPos=false;
      pos.top=parentPos.top;
      pos.left=parentPos.left+parentWidth;
    }
  } else if (this.position == "NE") {
    var dim={top: parentPos.top-height+parentHeight,left: parentPos.left+parentWidth,bottom: parentPos.top,right: parentPos.left+parentWidth+width};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="SW";
      originalPos=false;
      pos.top=parentPos.top;
      pos.left=parentPos.left-width;
    }
  } else if (this.position == "SW") {
    var dim={top: parentPos.top,left: parentPos.left-width,bottom: parentPos.top+parentHeight+height,right: parentPos.left};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="NE";
      originalPos=false;
      pos.top=parentPos.top-height+parentHeight;
      pos.left=parentPos.left+parentWidth;
    }
  } else if (this.position == "SE") {
    var dim={top: parentPos.top,left: parentPos.left+parentWidth,bottom: parentPos.top+parentHeight+height,right: parentPos.left+parentWidth+width};
    if (true || viewportContainsDim(dim)) {
      //teljesen tartalmazza
      pos.top=dim.top;
      pos.left=dim.left;
    } else {
      //kilog a menu
      this.actPosition="NW";
      originalPos=false;
      pos.top=parentPos.top-height+parentHeight;
      pos.left=parentPos.left-width;
    }
  }
  
  setPos(this.node,pos); 

  return originalPos;
}

/** Lathato teszi a menut, beallitja a poziciojat
  */
Menu.prototype.show = function () {
  if (this.timerId != null) {
    clearInterval(this.timerId);
    this.timerId=null;
  }

  this.moveMenuToPosition();

  
  if (nsDOM) {
    //ha scrollozva vagyunk, akkor valamiert mozilla elrontja a szelesseget
    setSize(this.node,this.size);
  }

  //hideselect
  if (ieDOM) {
    this.ulti.notifyShow(this);
  }

  var menu=this;
 
  setTimeout(function() {
      menu.node.style.visibility='visible'; 
      },10);
  this.state=2;
}

/** Eltunteti a menut
  */
Menu.prototype.hide = function () {
  if (this.timerId != null) {
    clearInterval(this.timerId);
    this.timerId=null;
  }
  this.dehighlight();
  
  this.node.style.visibility='hidden';

  this.state=0;
  //showselect
  if (ieDOM) {
    this.ulti.notifyHide(this);
  }
}






/** Egy szeparator megjeleniteset csinalja meg
  * @return a szeparator html kodja
  */
Menu.prototype.renderSeparator = function () {
  var src="";
  if (this.direction == 0) {
    //fuggoleges
    src+="<tr><td onmouseover='UltimateMenu.getMenu("+this.ulti.index+").separatorMouseover(event,\""+this.id+"\");' ><div class='"+this.ulti.classes['horizontalSeparator']+"'></div></td></tr>";
  } else if (this.direction == 1) {
    //vizszintes
    src+="<td onmouseover='UltimateMenu.getMenu("+this.ulti.index+").separatorMouseover(event,\""+this.id+"\");' ><div class='"+this.ulti.classes['verticalSeparator']+"'></div></td>";
  }
  return src;
}

/** Egy menupont megjeleniteset csinalja meg a kapott parameterektol fuggoen
  * @param cfg a menupont parameterek objektuma
  * @return a menupont html kodja
  */
Menu.prototype.renderItem = function (cfg) {
  var src="";
  var link="";
  var image="menu_icon_none.gif";
  var htmlParam="";
  var itemClass=this.ulti.classes["menuItem"];
  var linkClass=this.ulti.classes["menuItemLink"];
  var itemSrc="";
  if (cfg.image) {
    image=cfg.image;
  }
  if (cfg.link != null) {
    link=" href='"+cfg.link+"' ";
  }
  if (cfg.htmlParam != null) {
    htmlParam=cfg.htmlParam;
  }
  if (cfg.selected == true) {    
    var itemClass=this.ulti.classes["menuItemSelected"];
    var linkClass=this.ulti.classes["menuItemLinkSelected"];
  }
  image="<img src='"+this.ulti.images+image+"' border='0' width='18' height='18' class='menuIcon' />";

  if (cfg.parent == 1) {
    //szulo az illeto
    if (nsDOM || operaDOM) {
      //a tablazat jo neki, csak a szineket nem orokli a tablazat
      itemSrc="<td valign='middle' id='"+cfg.id+"' class='"+itemClass+"' onmouseover='UltimateMenu.getMenu("+this.ulti.index+").itemMouseover(event,this);' onmouseout='UltimateMenu.getMenu("+this.ulti.index+").itemMouseout(event,this);'><a "+link+" "+htmlParam+" class='"+linkClass+"'><table cellpadding='0' cellspacing='0' width='100%' style='background: inherit; color: inherit;'><tr><td valign='middle'>"+image+cfg.text+"</td><td align='right' valign='middle'><img src='"+this.ulti.images+"menu_arrow.gif' border='0' /></td></tr></table></a></td>";
    } else {
      //IE nem szereti a tablazatot, nem lehet tablazatos linkre kattintani
      itemSrc="<td valign='middle' id='"+cfg.id+"' class='"+itemClass+"' onmouseover='UltimateMenu.getMenu("+this.ulti.index+").itemMouseover(event,this);' onmouseout='UltimateMenu.getMenu("+this.ulti.index+").itemMouseout(event,this);'><a "+link+" "+htmlParam+" class='"+linkClass+"'><div style='float: left;'>"+image+cfg.text+"</div><div align='right' ><img src='"+this.ulti.images+"menu_arrow.gif' style='vertical-align: middle;' border='0'/></div></a></td>";
    }
  } else {
    //nem szulo
    itemSrc="<td valign='middle' id='"+cfg.id+"' class='"+itemClass+"' onmouseover='UltimateMenu.getMenu("+this.ulti.index+").itemMouseover(event,this);' onmouseout='UltimateMenu.getMenu("+this.ulti.index+").itemMouseout(event,this);'><a "+link+" "+htmlParam+" class='"+linkClass+"'>"+image+cfg.text+"</a></td>";
  }

  if (this.direction == 0) {
    //fuggoleges
    src+="<tr>"+itemSrc+"</tr>";  
  } else if (this.direction == 1) {
    //vizszintes
    src+=itemSrc;  
  }

  return src;
}


/** Egy menu megjeleniteset vegzi el, hatter es arnyek elemek kiszamitasa
  */
Menu.prototype.render = function () {
  var tableClass=this.ulti.classes["menuTable"];
  if (this.opacityBackground == 1) {
    tableClass=this.ulti.classes["menuTableOpacity"];
  }

  var src="<div id='"+this.id+"' class='menuDiv' onmouseover='UltimateMenu.getMenu("+this.ulti.index+").menuMouseover(event,this);' onmouseout='UltimateMenu.getMenu("+this.ulti.index+").menuMouseout(event,this);' ><div id='"+this.id+"_content' class='"+this.ulti.classes['menuContentDiv']+"'><table id='"+this.id+"_table' class='"+tableClass+"' border='0'>";
  for (var i in this.renderItems) {
    if (typeof this.renderItems[i] == "object") {
      var cfg=this.renderItems[i];
      if (cfg.type == 1) {
        //separator
        src+=this.renderSeparator();
      } else if (cfg.type == 0) {
        //item
        src+=this.renderItem(cfg);
      }
    }
  }
  
  src+="</table>";
 
  if (this.opacityBackground == 1) {
    src+="<div id='"+this.id+"_background' class='"+this.ulti.classes['menuBackground']+"'></div>";
  }
  if (this.shadowSize > 0 && this.shadows != "") {
      src+="<div id='"+this.id+"_shadow_1' class='"+this.ulti.classes['menuShadow']+"'></div>";
      src+="<div id='"+this.id+"_shadow_2' class='"+this.ulti.classes['menuShadow']+"'></div>";
      src+="<div id='"+this.id+"_shadow_3' class='"+this.ulti.classes['menuShadow']+"'></div>";
  }
  
  
  src+="</div></div>";

  document.write(src);

  //renderelheto elemekre mar nincs szukseg
  this.renderItems=null;
  //tovabbiakban this.items tombot lehet hasznalni: num -> id

}

/** Oldal betoltodese esemenykor beallitja a mereteket (opera es arrow.gif!) es hatter illetve arnyekok helyet
  */
Menu.prototype.onloadTrigger = function () {
  this.node=this.ulti.getElem(this.id);
  this.content=this.ulti.getElem(this.id+"_content");

  document.body.appendChild(this.node);  //opera miatt, kulonben egy td-ban middle eseten rossz lesz az offsetTop

  this.setSize();


  if (ieDOM) {
    HideSelect.registerNode(this.id,this.node);
  }

}



/**
  */
Menu.prototype.setSize = function() {
  var table=this.ulti.getElem(this.id+"_table");  
//  this.size.width=getContentMarginWidth(table);
//  this.size.height=getContentMarginHeight(table);
  this.size.width=getContentMarginWidth(table);          //itt feltesszuk, hogy table-nek nem lesz soha margin-ja
  this.size.height=getContentMarginHeight(table);
  var tableSize=copyObject(this.size);


  var pos={top: 0,left: 0};

  if (this.shadowSize > 0 && this.shadows != "") {
    var shadow1=this.ulti.getElem(this.id+"_shadow_1");            
    var shadow2=this.ulti.getElem(this.id+"_shadow_2");            
    var shadow3=this.ulti.getElem(this.id+"_shadow_3");            

    if (this.shadows == "N-W-NW") {
      pos.top=this.shadowSize;
      pos.left=this.shadowSize;

      setSize(shadow1,{width: this.size.width-this.shadowSize,height: this.shadowSize});
      setPos(shadow1,{top: 0,left: this.shadowSize},false,true);
      
      setSize(shadow2,{width: this.shadowSize,height: this.size.height-this.shadowSize});
      setPos(shadow2,{top: this.shadowSize,left: 0},false,true);

      setSize(shadow3,{width: this.shadowSize,height: this.shadowSize});
      setPos(shadow3,{top: 0,left: 0},false,true);
    } else if (this.shadows == "N-E-NE") {
      pos.top=this.shadowSize;
      pos.left=0;

      setSize(shadow1,{width: this.size.width-this.shadowSize,height: this.shadowSize});
      setPos(shadow1,{top: 0,left: this.shadowSize},false,true);
      
      setSize(shadow2,{width: this.shadowSize,height: this.size.height-this.shadowSize});
      setPos(shadow2,{top: this.shadowSize,left: this.size.width},false,true);

      setSize(shadow3,{width: this.shadowSize,height: this.shadowSize});
      setPos(shadow3,{top: 0,left: this.size.width},false,true);
    } else if (this.shadows == "S-W-SW") {
      pos.top=0;
      pos.left=this.shadowSize;

      setSize(shadow1,{width: this.size.width-this.shadowSize,height: this.shadowSize});
      setPos(shadow1,{top: this.size.height,left: this.shadowSize},false,true);
      
      setSize(shadow2,{width: this.shadowSize,height: this.size.height-this.shadowSize});
      setPos(shadow2,{top: this.shadowSize,left: 0},false,true);

      setSize(shadow3,{width: this.shadowSize,height: this.shadowSize});
      setPos(shadow3,{top: this.size.height,left: 0},false,true);
    } else if (this.shadows == "S-E-SE") {
      pos.top=0;
      pos.left=0;

      setSize(shadow1,{width: this.size.width-this.shadowSize,height: this.shadowSize});
      setPos(shadow1,{top: this.size.height,left: this.shadowSize},false,true);
      
      setSize(shadow2,{width: this.shadowSize,height: this.size.height-this.shadowSize});
      setPos(shadow2,{top: this.shadowSize,left: this.size.width},false,true);

      setSize(shadow3,{width: this.shadowSize,height: this.shadowSize});
      setPos(shadow3,{top: this.size.height,left: this.size.width},false,true);
    }

    
    //ha modosult a meret, akkor most gyorsan beallitjuk
    
    this.size.width+=this.shadowSize;                //left es right 
    this.size.height+=this.shadowSize;               //top es bottom
    
    setPos(table,pos);
    
  }
  setSize(this.node,this.size);
  setSize(this.content,this.size);
 
  if (this.opacityBackground == 1) {
    var back=this.ulti.getElem(this.id+"_background");
    setSize(back,tableSize);                   //hatter felveszi a meretet
    setPos(back,pos,false,true);                          //content ala kerul a hatter (csak o absolute, mig content relative)
  }
}

