function Node(mId,mPid,mNivel,mUrl, mTitulo, mTarget, mAlt) {
  this.id = mId;
  this.Parent = mPid;
  this.Nivel = mNivel;
  this.url = mUrl;
  this.titulo = mTitulo;
  this.target = mTarget;
  this.Alt = mAlt;
};

/*function AbreCierra() {
  clickSmack('',0,'nodo',false,'UL','plugins/menupanel/collapsed.gif','plugins/menupanel/expanded.gif');
}*/

function clickSmack(oThisOb,oLevel,oBsID,oCol,oT,oImgC,oImgE) {
// alert(oThisOb + '  ' + oLevel + '  ' + oBsID + '  ' + oCol + ' ' + oT + ' ' + oImgC + '  ' + oImgE);	
 if( oThisOb.blur ) oThisOb.blur(); 
 oThisOb = oThisOb.parentNode.getElementsByTagName( unescape(oT) )[0];
 if( oCol ) {
  for( var x = openLists[oBsID].length - 1; x >= oLevel; x-=1 ) { 
   if( openLists[oBsID][x] ) {
    openLists[oBsID][x].style.display = 'none'; 
    if( oLevel != x ) openLists[oBsID][x] = null; 
   }
  }
  if( oThisOb == openLists[oBsID][oLevel] ) openLists[oBsID][oLevel] = null; 
  else { 
   oThisOb.style.display = 'block'; 
   openLists[oBsID][oLevel] = oThisOb; 
  }
 }else {
  oThisOb.style.display = ( oThisOb.style.display == 'block' ) ? 'none' : 'block'; 
  try{
   if (oThisOb.style.display == 'block') oThisOb.parentNode.childNodes[0].childNodes[0].src=oImgE;
    else oThisOb.parentNode.childNodes[0].childNodes[0].src=oImgC;
  }catch(e){}
 }
};

function MenuPanel(ImgC, ImgE, mWidth) {
 var openLists = [];
 var oIcount = 0;
 this.Name = 'nodo';
 if (ImgC != '') this.ImgCollapsed = '<img src=\'' + ImgC +'\' border=0> '; else this.ImgCollapsed = '';
 if (ImgE != '') this.ImgExpanded = '<img src=\'' + ImgE +'\' border=0> ';  else this.ImgExpanded = '';
 this.AutoCollapsed = false;
 this.Content = '<div style=\'width: ' + mWidth + 'px;\'>';
 this.mNodos = [];

 MenuPanel.prototype.LoadMenu = function() {
  this.preloadImages(this.ImgCollapsed,this.ImgExpanded);
  this.Content += this.CreaMenu() + '</div>';
  document.write(this.Content);
  this.compactMenu(this.Name,this.AutoCollapsed,this.ImgCollapsed);
  this.selfLink(this.Name,'samePage',false);  
 };

 MenuPanel.prototype.AbreCierra = function() {
  if(!document.getElementsByTagName || !document.childNodes || !document.createElement ) return;
  var baseElement = document.getElementById('nodo'); 
  if( !baseElement ) return; 
  oThisOb = baseElement.parentNode.getElementsByTagName('UL')[1];
  oThisOb.style.display = ( oThisOb.style.display == 'block' ) ? 'none' : 'block'; 
 }
 
 MenuPanel.prototype.AddOpc = function(mId,mPid,mNivel,mUrl, mTitulo, mTarget, mAlt) {
  this.mNodos[this.mNodos.length] = new Node(mId,mPid,mNivel,mUrl, mTitulo, mTarget, mAlt);    
 };

 MenuPanel.prototype.CreaMenu = function() {
   str = '<ul id=\''+ this.Name +'\'>';	 
   i=0;
   do {  
    if (this.mNodos[i].Parent == 0) {
     str += '<li>' + this.mNodos[i].titulo;
	 hijo = this.listChildren(this.mNodos[i].id);
	 if (hijo != '') str += '<ul>' + hijo + '</ul>';
	 str += '</li>';
	}
	i++; 
   }while (i < this.mNodos.length)
   str += '</ul>';
   return str;
 };
 
 MenuPanel.prototype.listChildren = function(padre) {
  var cad = '';
  var hijo = '';
  for (var pos =0; pos < this.mNodos.length; pos++) {
   if (this.mNodos[pos].Parent == padre) {
    if (this.mNodos[pos].url) cad += '<li><a href=\'' + this.mNodos[pos].url + '\' target=\'' + this.mNodos[pos].target + '\'>' + this.mNodos[pos].titulo+'</a>';
     else cad += '<li>' + this.mNodos[pos].titulo;
    hijo = this.listChildren(this.mNodos[pos].id);
	if (hijo != '') cad += '<ul>' + hijo + '</ul>';
    cad += '</li>';
   }
  }
  return cad;
 }
 
 MenuPanel.prototype.compactMenu = function(oID,oAutoCol,oPlMn,oMinimalLink) {
  if(!document.getElementsByTagName || !document.childNodes || !document.createElement ) return;
  var baseElement = document.getElementById( oID ); 
  if( !baseElement ) return; 
  this.compactChildren( baseElement, 0, oID, oAutoCol, oPlMn, baseElement.tagName.toUpperCase(), oMinimalLink && oPlMn );
 };
 
 MenuPanel.prototype.compactChildren = function(oOb,oLev,oBsID,oCol,oPM,oT,oML) {
  if(!oLev) { 
   oBsID = escape(oBsID); 
   if( oCol ) openLists[oBsID] = []; 
  }
  for( var x = 0, y = oOb.childNodes; x < y.length; x++ ) { 
   if( y[x].tagName ) {   //for each immediate LI child
    var theNextUL = y[x].getElementsByTagName( oT )[0];
    if( theNextUL ) { //collapse the first UL/OL child
     theNextUL.style.display = 'none';
     var newLink = document.createElement('A');  //create a link for expanding/collapsing
     newLink.setAttribute( 'href', '#' );
	// alert('clickSmack(this,' + oLev + ',\'' + oBsID + '\',' + oCol + ',\'' + escape(oT) + '\',\'' + ImgC + '\',\'' + ImgE + '\');return false;');
     newLink.onclick = new Function('clickSmack(this,' + oLev + ',\'' + oBsID + '\',' + oCol + ',\'' + escape(oT) + '\',\'' + ImgC + '\',\'' + ImgE + '\');return false;');
     if( oML ) var theHTML = '';  //wrap everything upto the child U/OL in the link
     else{
      var theT = y[x].innerHTML.toUpperCase().indexOf('<'+oT);
      var theA = y[x].innerHTML.toUpperCase().indexOf('<A');
      var theHTML = y[x].innerHTML.substr(0, ( theA + 1 && theA < theT ) ? theA : theT );
      while( !y[x].childNodes[0].tagName || ( y[x].childNodes[0].tagName.toUpperCase() != oT && y[x].childNodes[0].tagName.toUpperCase() != 'A' ) ) {
       y[x].removeChild( y[x].childNodes[0] );
      }
     }
     y[x].insertBefore(newLink,y[x].childNodes[0]);
     y[x].childNodes[0].innerHTML = oPM + theHTML.replace(/^\s*|\s*$/g,'');
     theNextUL.MWJuniqueID = oIcount++;
     this.compactChildren( theNextUL, oLev + 1, oBsID, oCol, oPM, oT, oML );
    }
   }
  }
 };

 MenuPanel.prototype.stateToFromStr = function(oID,oFStr) {
  if( !document.getElementsByTagName || !document.childNodes || !document.createElement ) return ''; 
  var baseElement = document.getElementById( oID ); 
  if( !baseElement ) return ''; 
  if( !oFStr && typeof(oFStr) != 'undefined' ) return '';
  if( oFStr ) oFStr = oFStr.split(':');
  for( var oStr = '', l = baseElement.getElementsByTagName(baseElement.tagName), x = 0; l[x]; x++ ) {
   if( oFStr && this.MWJisInTheArray( l[x].MWJuniqueID, oFStr ) && l[x].style.display == 'none' ) l[x].parentNode.getElementsByTagName('a')[0].onclick(); 
   else if( l[x].style.display != 'none' ) oStr += (oStr?':':'') + l[x].MWJuniqueID; 
  }
  return oStr;
 };

 MenuPanel.prototype.MWJisInTheArray = function(oNeed,oHay) { 
  for(var i = 0; i < oHay.length; i++ ) { 
   if( oNeed == oHay[i] ) return true; 
  } 
  return false; 
 };

 MenuPanel.prototype.selfLink = function(oRootElement,oClass,oExpand) {
  if(!document.getElementsByTagName||!document.childNodes) return;
  oRootElement = document.getElementById(oRootElement);
  for( var x = 0, y = oRootElement.getElementsByTagName('a'); y[x]; x++ ) {
   if( y[x].getAttribute('href') && !y[x].href.match(/#$/) && this.getRealAddress(y[x]) == this.getRealAddress(location) ) {
    y[x].className = (y[x].className?(y[x].className+' '):'') + oClass;
    if( oExpand ) {
     oExpand = false;
     for( var oEl = y[x].parentNode, ulStr = ''; oEl != oRootElement && oEl != document.body; oEl = oEl.parentNode ) {
      if( oEl.tagName && oEl.tagName == oRootElement.tagName ) ulStr = oEl.MWJuniqueID + (ulStr?(':'+ulStr):'');
     }
     this.stateToFromStr(oRootElement.id,ulStr);
    }
   }
  }
 };

 MenuPanel.prototype.getRealAddress = function(oOb) { 
  return oOb.protocol + ((oOb.protocol.indexOf(':') + 1) ? '' : ':') + oOb.hostname + ((typeof(oOb.pathname) == typeof(' ') && oOb.pathname.indexOf('/') != 0) ? '/' : '' ) + oOb.pathname + oOb.search;
 };
  
 MenuPanel.prototype.preloadImages = function() {
  for (var i=0;i<arguments.length;i++) {
   var img = new Image();
   img.src = arguments[i];
  }
 };
 
}