var DOM, NC4, NC, IE4, IE5, NC6, OPERA, IE, wop;
DOM=(document.getElementById)?true:false;
wop=(window.opera)?true:false;
NC4=(document.layers && !wop)?true:false;
IE4=(document.all && document.all.item && !document.getElementById && !wop)?true:false;
IE5=(document.all && document.getElementById && !wop)?true:false;
OPERA=DOM && wop;
NC6=DOM && !IE4 &&!IE5 && !OPERA;
IE=(IE4 || IE5) && !OPERA;
function lrefs(ln){var el=IE?document.all[ln].style:(NC6||OPERA)?document.getElementById(ln).style:document[ln]; return el;}


var globalindex=0;
var globalmenus=new Array();

var submenuover=0;
var menuobject=null;
var activesubmenu=null;
var activeitem=0;
var activehide=0;
var anchorobject='';
var menustack=new Array;
var stackindex=0;
var callobject=null;
var callbgr0='';
var callbgr1='';
var operaobj=null;
var operacolor='';

// additional functions

function coo(evt, ob, mo, lr, a)
{
  if (mo.items[a].sub.rx==-1)
  {
    var l, t, o;
    var x=0;
    var y=0;
    var xx=0;
    var yy=0;
    var lo=lrefs(lr);
    var h=mo.height;
    var w=mo.width;
    var loleft, lotop;
    var bw=Math.abs(mo.style.bw);
    if (bw!=0) bw--;
    if (mo.dir==0) { w=-1*bw; h+=bw; } else { h=-1*bw; w+=bw; }
    if (IE)
    {
      var xxx=yyy=0;
      xxx=document.body.scrollLeft;
      yyy=document.body.scrollTop;
      x=evt.clientX;
      y=evt.clientY;
      xx=evt.offsetX;
      yy=evt.offsetY;
      loleft=xxx+x-xx-2+w;
      lotop=yyy+y-yy+h-2;
      lo.left=loleft;
      lo.top=lotop;
    }

    if (OPERA)
    {
      o=ob;
      xx=o.offsetLeft; yy=o.offsetTop;
      while (o && o!=document.body)
      {
        o=o.offsetParent;
        xx+=o.offsetLeft;
        yy+=o.offsetTop;
      }
      loleft=xx+w;
      lotop=yy+h;
      lo.pixelLeft=loleft;
      lo.pixelTop=lotop;
    }

    if (NC6)
    {
      o=document.anchors[anchorobject];
      xx=o.offsetLeft;
      yy=o.offsetTop;
      while (o!=document.body)
      {
        o=o.offsetParent;
        xx+=o.offsetLeft;
        yy+=o.offsetTop;
      }

      loleft=xx+w;
      lotop=yy+h-1-11-2;
      lo.left=loleft;
      lo.top=lotop;
    }

    if (NC4)
    {
      l=(mo.lr!='') ? lrefs(mo.lr) : '';
      if (l!='')
      {
        x=l.left;
        y=l.top;
        xx=l.document.anchors[anchorobject].x;
        yy=l.document.anchors[anchorobject].y;
      }
      else
      {
        xx=document.anchors[anchorobject].x;
        yy=document.anchors[anchorobject].y;
      }

      loleft=xx+x+w;
      lotop=yy+y+h;
      lo.left=loleft;
      lo.top=lotop;
    }
    mo.items[a].sub.rx=loleft;
    mo.items[a].sub.ry=lotop;
  }
}

function nc4click()
{
  menuobject.clk(activeitem);
}

var nnfs=0;

function hfout()
{
  activehide=1;
  nnfs++;
  setTimeout("closestack();", 100);
}

function fixstack()
{
  var i=0;
  if (activehide==1)
  {
    submenuover=0;
    menuobject=null;
    activesubmenu=null;
    activeitem=0;
    activehide=0;
  }
  if (stackindex>0)
  {
    for (i=stackindex; i>0; i--)
    {
      if (menuobject==null)
      {
        if (menustack[i]!=null) setcallbgc(menustack[i], 0);
        menustack[i].hide();
        stackindex--;
      }
      else
        if (menustack[i].index!=menuobject.index) {menustack[i].hide(); stackindex--;} else break;
    }
  }
  if (activeitem>0)
    if (menuobject.items[activeitem].sub!=null)
    {
      menuobject.items[activeitem].sub.keep=callobject;
      menuobject.items[activeitem].sub.cob0=callbgr0;
      menuobject.items[activeitem].sub.cob1=callbgr1;
      menuobject.items[activeitem].sub.show();
    }
}

function chbg(e,o,c,a,d,m)
{
  if (OPERA) operacolor=m.style.bgc;
  if (OPERA && operaobj!=null) operaobj.style.background=operacolor;
  if (OPERA)
  {
    if (a>0) operaobj=o; else operaobj=null;
  }
  if (IE) document.selection.empty();
  if (NC6) window.getSelection().removeAllRanges();

  if (m!=null) m.activeitem=(a==0)?activeitem:a;
//  if (m!=null) if (a==0) {if (m.mouseOut!='') eval(m.mouseOut);} else {if (m.mouseOver!='') eval(m.mouseOver);}
  callbgr0=m.style.bgc;
  callbgr1=m.style.sbgc;
  callobject=o;
  if (m.keep!=null)
  {
    setcallbgc(m, 1);
  }
  if (NC4||NC6)
  {
    anchorobject=(a==0) ? '' : 'phm'+m.index+'i'+a;
  }
  menuobject=m;
  submenuover=m.index;
  activeitem=a;

  if (IE||NC6) o.style.backgroundColor=c;
  if (OPERA) { operaobj=o; o.style.background=operacolor; o.style.background=c; }
  if (NC4)
  {
    if (a==0) o.releaseEvents(Event.CLICK); else { o.captureEvents(Event.CLICK); o.onclick=nc4click; }
    o.bgColor=c;
  }

  if (a!=0)
  {
    if (m.items[activeitem].sub!=null)
    {
      if ((IE&&!e.srcElement.type)||NC4||OPERA||NC6) coo(e, o, m, m.items[a].sub.lr, a);
      activesubmenu=m.items[a].sub;
      m.items[a].sub.show();
    }
  }
  if (a!=0) activehide=0;
  setTimeout("fixstack();", 50);
  top.status=defaultStatus;
}

function sethandlers()
{
  var i, m, o;
  if ((NC4 || OPERA) && globalindex>0)
  {
    for (i=1; i<=globalindex; i++)
    {
      m=globalmenus[i].lr;
      if (NC4 && m!='') { o=lrefs(m); o.onmouseover = hfover; o.onmouseout = hfout; }
      if (OPERA && m!='') { o=lrefs(m); o.pixelWidth=globalmenus[i].width; }
    }
  }
}


// menu style object
function mStyle(b, s, c, h, w, r)
{
  this.bgc=b;
  this.sbgc=s;
  this.css=c;
  this.bw=w;
  this.bc=r;
  this.hf=h;
}

// menu object
cMenu.prototype.add=cmadd;
cMenu.prototype.hide=cmhide;
cMenu.prototype.show=cmshow;
cMenu.prototype.make=cmmake;
cMenu.prototype.output=cmmout;
cMenu.prototype.clk=cmclk;

function cMenu(o,l, p, s, d, w, h)
{
  if (o!='')
  {
    t=this;
    globalindex++;
    globalmenus[globalindex]=t;
    t.obj=o;
    t.vis=(l=='')?1:0;
    t.lr=l;
    if (l!=''){t.vis=0;} else {t.vis=1};
    t.parent=p;
    if (d==0) w=0;
    if (w) t.width=w; else t.width=0;
    if (h) t.height=h; else t.height=0;
    t.style=s;
    t.dir=d;
    t.count=0;
    t.items=new Array;
    t.index=globalindex;
    t.keep=null;
    t.cob0='';
    t.cob1='';
    t.code='';
    t.rx=-1;
    t.ry=-1;
    t.mouseOver='';
    t.mouseOut='';
    t.activeitem=0;
    var opout='';
    if (OPERA) opout=" onMouseOut=\"hfout()\"";
    t.d1= (l!='') ? "<div id=\""+l+"\" onMouseOver=\"submenuover="+t.index+"; activehide=0; menuobject="+t.obj+";\""+opout+">\n" : '';
    t.d2= (l!='') ? "\n<\/div>\n" : '';
    t.me= ((IE || NC6 || OPERA) && t.lr!='') ? " onMouseOver=\"hfover()\" onMouseOut=\"hfout()\"" : '';
    var bw=Math.abs(s.bw);
    var cs= (s.bw>0) ? 0 : (s.bw<0) ? bw : 0;
    var cp= (s.bw>0) ? bw : (s.bw<0) ? 0 : 0;
    t.t1= (s.bw==0) ? "<table border=0 cellspacing="+cs+" cellpadding="+cp+t.me+">\n" : "<table border=0 cellspacing=0 cellpadding="+cs+t.me+"><tr><td bgcolor="+s.bc+">\n<table border=0 cellspacing="+cp+" cellpadding=0>\n";
    t.t2= (s.bw==0) ? "<\/table>" : "<\/table>\n<\/td><\/tr><\/table>";
  }
}

function cMenuItem(x, f, i, s, p)
{
  t=this;
  t.text=x;
  t.loc=t.exe=f;
  if (f.length>0) if (f.charAt(f.length-1)==';') this.loc=''; else this.exe='';
  t.index=i;
  t.sub=s;
  if (s!=null) s.parent=t;
  w= (p.width!=0) ? " width="+p.width : '';
  h= (p.height!=0) ? " height="+p.height : '';
  t.parent=p;
  var ps=p.style;
  var ap=(NC4) ? "<a name=\"phm"+globalindex+"i"+i+"\"><wbr></a>" : (NC6) ? "<a name=\"phm"+globalindex+"i"+i+"\"></a>" : '';
  var ar;
  if (NC4)
    ar=(t.sub!=null && p.dir==1) ? "&nbsp;<img src=\"./images/arrow11.gif\" align=top border=0>":'';
  if (IE||NC6||OPERA)
   ar=(t.sub!=null && p.dir==1) ? "<img src=\"./images/arrow11.gif\" align=top border=0 style=\"float:right\" type=a>":'';
 var c=" onMouseover=\"chbg(event, this,'"+ps.sbgc+"', "+i+", '"+ps.bgc+"', "+p.obj+")\" onMouseout=\"chbg(event, this,'"+ps.bgc+"', 0, '"+ps.bgc+"', "+p.obj+")\"";
  var a=(IE || NC6 || OPERA) ? ar+"<nobr>"+ps.hf+x+ps.hf+"<\/nobr>" : (NC4) ? "<ilayer"+w+h+"><layer width=100%"+h+c+"><a class="+ps.css+" href=\"javascript: "+p.obj+".clk("+i+")\" onFocus=\"blur\"><nobr>"+ps.hf+"<spacer type=block width=1"+h+" align=absmiddle>"+x+ar+ps.hf+"<\/nobr><\/a><\/layer><\/ilayer>" : "";
  var d=(IE || NC6 || OPERA) ? " onClick=\""+p.obj+".clk("+i+")\"" : "";
  if (NC4) cbg='';
  t.code="<td valign=middle bgcolor="+ps.bgc+" class="+ps.css+w+h+c+d+">"+ap+a+"<\/td>";
}

function cmadd(t, f, s)
{
  this.count++;
  if (!s) s=null;
  this.items[this.count]=new cMenuItem(t, f, this.count, s, this);
}

var mx=my=0;

function hfover()
{
  activehide==0;
}

function cmhide()
{
  if (this.lr!='')
  {
    this.vis=0;
    lrefs(this.lr).visibility="hidden";
    if (this.keep!=null)
    {
      if (callobject!=this.keep) setcallbgc(this, 0);
    }
  }
}

function setcallbgc(ob, st)
{
  var o=ob.keep;
  var c=(st==1)?ob.cob1:ob.cob0;
  if (o)
  {
    if (o.style)
    {
      if (IE||NC6) o.style.backgroundColor=c;
      if (OPERA) o.style.background=c;
      if (NC4) o.bgColor=c;
    }
  }
}

function cmshow()
{
  if (this.lr!='')
  {
    if (this.vis!=1)
    {
      stackindex++;
      menustack[stackindex]=this;
    }
    lrefs(this.lr).visibility="visible";
    this.vis=1;
  }
}

function cmmake()
{
  var t=this;
  if (t.count>0)
  {
    var c1=t.d1+t.t1;
    var c2=t.t2+t.d2;
    if (t.dir==0)
    {
      c1+="<tr valign=middle>";
      c2="\n<\/tr>\n"+c2;
      for (var i=1; i<=t.count; i++) c1+="\n"+t.items[i].code;
    }
    else
      for (var i=1; i<=t.count; i++) c1+="<tr valign=middle>"+t.items[i].code+"<\/tr>\n";
    t.code=c1+c2;
  }
}

function cmmout()
{
  return this.code;
}

function closestack()
{
  if (stackindex>0 && activehide==1)
  {
    for (i=stackindex; i>0; i--)
    {
      if (menustack[i].keep!=null) { setcallbgc(menustack[i], 0); menustack[i].keep=null; }
      if (menustack[i].parent!=null) menuobject=menustack[i].parent;
      menustack[i].hide();
      stackindex--;
    }
  }
}

function cmclk(i)
{
  if (this.items[i].loc!='' || this.items[i].exe!='')
  {
    if (IE||NC6) callobject.style.backgroundColor=callbgr0;
    if (OPERA)
    {
      callobject.style.background=callbgr0;
    }
    if (NC4)
    {
      callobject.bgColor=callbgr0;
    }
    activehide=1;
    if (OPERA && this.mouseOut!='') eval(this.mouseOut);
    closestack();
    if (this.items[i].loc!='') document.location=this.items[i].loc;
    if (this.items[i].exe!='') eval(this.items[i].exe);
  }
}

var s1=new mStyle("#FFFFFF", "#E2EAF6", "smitem", "&nbsp;", 0, "#000000");
var s2=new mStyle("#FFFFFF", "#E2EAF6", "smitem", "&nbsp;", -1, "#002967");

var mm, dd2, dd3, dd4, dd6, sd21, sd22, sd23;


//dd2=new cMenu('dd2', 'm2', null, s2, 1, 120, 15);
//dd2.add('В Центъра', 'timetable2.php');
//dd2.add('Корпоративни клиенти', 'custlist.php');
//dd2.add('Bulgarian for foreigners', 'bg4for.php');
//dd2.make();

dd1=new cMenu('dd1', 'm1', null, s2, 1, 190, 15);
dd1.add('В Базата', 'basecourse.php');
dd1.add('По месторабота', 'custlist.php');
dd1.make();

//dd6=new cMenu('dd6', 'm6', null, s2, 1, 120, 15);
//dd6.add('Публикации и снимки', 'bbcphotos.php');
//dd6.make();


dd4=new cMenu('dd4', 'm4', null, s2, 1, 180, 15);
dd4.add('Учебната база', 'mbase.php');
dd4.add('Международни проекти', 'euprojects.php');
dd4.add('Проекти по експортен контрол', 'proj_export.php');
dd4.add('Bels & Belin клуб - Галерия', 'bbcphotos.php');
dd4.make();

dd5=new cMenu('dd5', 'm5', null, s2, 1, 180, 15);
dd5.add('Заявка за езиков курс', 'anketa.php');
dd5.add('Заявка за корпоративен курс', 'corpcourse.php');
dd5.make();



mm=new cMenu('mm', '', null, s1, 0, 100, 19);
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;За нас&nbsp;', '', dd4);
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;Нашите услуги&nbsp;', 'services.php', dd1);
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;Записване&nbsp;', '', dd5);
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;Акредитация&nbsp;', 'accredit.php');
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;Контакти&nbsp;', 'contacts.php');
mm.add('<img src="./images/ms.gif" align="top" border="0">&nbsp;Работа&nbsp;', 'jobs.php');
mm.make();

document.writeln(dd1.output());
//document.writeln(dd2.output());
document.writeln(dd4.output());
document.writeln(dd5.output());
//document.writeln(dd6.output());

var mainmenu=mm.output();

//window.onload=sethandlers;

if (IE) document.body.onmouseover=fixstack;

