 timerOn= false;
 timerID= 0;
 timecount= 3000; 
 timetofade = 1000;
 corectiesubmeniuX= 22;
 corectieIEsubmeniuY = -1;
 corectieMozsubmeniuY = -6;
 corectieIEsubmeniuX = 18;
 corectieMozsubmeniuX = 10;






function showmenu()

{
// alert ('Am intrat');


 document.write("<div id='mp' class='meniuprincipal'>meniu</div><div id='submeniu' class='submeniu'></div>");


// alert(meniuprincipal[21]);



// alert(st);
  descris="<table class='tbmp' cellpadding='0' cellspacing='0'><tr class='trmp'>";
 // descris="";
  for(i=0; i<txtm.length; i++)
 {
  iiid = 'm' + i;
  if  (i == (txtm.length - 1)) {
   descris= descris + "<td class='ltdmp'></td><td class='tdmp'><div id='" + iiid +"' class='divmp'><a  class='amp' href='" + linkm[i][0] +"' onmouseover=\"chovmp("+ i +")\" onmouseout=\"choutmp(" + i + ")\">" + txtm[i][0] + "</a></div></td><td class='rtdmp'></td>";
    }
   else 
     {
   descris= descris + "<td class='ltdmp'></td><td class='tdmp'><div id='" + iiid +"' class='divmp'><a  class='amp' href='" + linkm[i][0] +"' onmouseover=\"chovmp("+ i +")\" onmouseout=\"choutmp(" + i + ")\">" + txtm[i][0] + "</a></div></td><td class='rtdmp'></td>";
   }
 //  descris= descris + "<a style='" + st + "' href='javascript: return();' onmouseover='' onmouseout=''>" + txtm[i][0] + "</a>";  
 }
 descris = descris + "</tr></table>";
// alert(descris);
 ll= document.getElementById('mp');
 ll.innerHTML = descris;
//  alert('am iesit');
}


function  chovmp(l)
{
// alert('am intrat in chovmp');
 iiid= 'm' + l;
 el = document.getElementById(iiid);


 //alert(el.style.color + " si background: " + el.style.background);
 if (txtm[l].length>1)
 {
  punesubmeniu(l);   
 }
}

function choutmp(l)
{
 iiid='m' + l;
 el = document.getElementById(iiid);

// alert(el.style.color + " si background: " + el.style.background);

 if (txtm[l].length>1) {
  starttime();
 }
}


function punesubmeniu(l)
{
 // alert('am intrat!');
  changeOpac(0, 'submeniu');
  pozX=0;
  pozY=0;

  elmp = document.getElementById('mp');
  var pozY = elmp.offsetTop; //+  elmp.offsetHeight;
  var pozX = elmp.offsetLeft;
  iiid='m' + l;
  elmp = document.getElementById(iiid);
  pozY = pozY + elmp.offsetHeight;
  lungimeelementcurent= Math.round(elmp.offsetWidth/2);



  for (i=0; i<l; i++)
  {
    iiid='m' + i;
    elmp = document.getElementById(iiid);
    pozX = pozX + elmp.offsetWidth + elmp.offsetLeft;
   } 

  el = document.getElementById('submeniu');

   tmps="<table class='tbms' cellpadding='0' cellspacing='0'>";

  for(i=1; i<txtm[l].length; i++)
  {
   idd='s' + i;

   if (i == (txtm[l].length -1)) {
       tmps = tmps + "<tr class='trms'><td class='tdmslast'><a id='" + idd +"' class='ams' href='" + linkm[l][i] +"' onmouseover=\"chovms("+ i +")\" onmouseout=\"choutms(" + i + ")\">" + txtm[l][i] + "</a></td></tr>";
     }
   else 
   {
    tmps = tmps + "<tr class='trms'><td class='tdms'><a id='" + idd +"' class='ams' href='" + linkm[l][i] +"' onmouseover=\"chovms("+ i +")\" onmouseout=\"choutms(" + i + ")\">" + txtm[l][i] + "</a></td></tr>";
   }

  }
  tmps = tmps + "</table>";


  el.innerHTML = tmps;
  lungimesubmeniu = Math.round(el.offsetWidth/2);

   if(navigator.appName == "Microsoft Internet Explorer") {
        pozY = pozY + corectieIEsubmeniuY;
        el.style.top = pozY + "px";
       pozX = pozX  + corectiesubmeniuX + lungimeelementcurent - lungimesubmeniu + l*corectieIEsubmeniuX;
        //alert(pozX);
       el.style.left = pozX  + "px";

        }
   else {
        pozY = pozY + corectieMozsubmeniuY;
        el.style.top = pozY + "px";
       pozX = pozX  + corectiesubmeniuX + lungimeelementcurent - lungimesubmeniu + l*corectieMozsubmeniuX;
       el.style.left = pozX  + "px";
        }

  stoptime();

  opacity('submeniu', 0, 99, timetofade);
//  alert('am iesit din punesubmeniu cu opacitate: ' + ms[l][9]);  
}

function chovms(l)
{
 idd='s' + l;
 el = document.getElementById(idd);
 stoptime();
}

function choutms(l)
{
 idd='s' + l;
 el = document.getElementById(idd);
 starttime();
}


function stoptime()
{
 
  if (timerOn) { 
 clearTimeout(timerID); 
 timerID = null; 
 timerOn = false; 
 } 
}

function starttime() { 
 if (timerOn == false) { 
 timerID=setTimeout( "closediv()", timecount); 
 timerOn = true; 
 } 
 }

function closediv()
{
 opacity("submeniu", 99, 0, timetofade);
}

function opacity(id, opacStart, opacEnd, millisec) {
 
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}


function changeOpac(opacity, id) {
//    if (ie4) { document.getElementById(id).style.filter = "alpha(opacity=" + opacity + ")";}
//   else { document.getElementbyId(id).style.MozOpacity = opacity/100;}

  var object = document.getElementById(id).style;
      object.filter = "alpha(opacity=" + opacity + ")";
      object.MozOpacity = (opacity / 100);
      object.opacity = (opacity / 100);

//    object.KhtmlOpacity = (opacity / 100);
// alert(id + 'o:' + opacity);

}
