// Menu class
function Menu() {
    // properties
    this.items = new Array();
    // methods
    this.addMenuItem = addMenuItem;
    this.render  = renderMenu;
    this.draw    = drawMenu;
}

function addMenuItem(id, imageDefault, imageSelected, altText, url, isSelected) {
    var item;
    item = new MenuItem(id, imageDefault, imageSelected, altText, url, isSelected, (this.items.length==0));
    this.items[this.items.length] = item;
    return item;
}

function renderMenu() {
    var i, html = '';
    for (i=0; i<this.items.length; i++) html += this.items[i].render();
    return html;
}

function drawMenu() {
    document.write(this.render());
}

// MenuItem class
function MenuItem(id, imageDefault, imageSelected, altText, url, isSelected, isFirst) {
    // properties
    this.id = id;
    this.imageDefault = imageDefault;
    this.imageSelected = imageSelected;
    this.altText = altText;
    this.url = url;
    this.isSelected = isSelected;
    this.isFirst = isFirst;
    this.parent = false;
    this.items = new Array();
    // methods
    this.addSubMenuItem = addSubMenuItem;
    this.render = renderMenuItem;
    this.dropDownMenuMouseOver = dropDownMenuMouseOver;
    this.dropDownMenuMouseOut = dropDownMenuMouseOut;
    this.dropDownMenuClear = dropDownMenuClear;
    this.showSubMenuAndParents = showSubMenuAndParents;
    // preload images
    if (imageSelected) {
        eval('image'+id+'x0=imgPreload(\''+imageDefault+'\');');
        eval('image'+id+'x1=imgPreload(\''+imageSelected+'\');');
    }
}

function addSubMenuItem(id, text, url) {
    var item;
    item = new SubMenuItem(this, id, text, url);
    this.items[this.items.length] = item;
    return item;
}

function renderMenuItem() {
    var i, imgName, imgURL, subName, mouseHandlers, html = '';
    if (!this.isFirst) html += '<td><img src="/en/images/top_menu_v.gif" alt="" width="2" height="28" border="0"></td>';
    html += '<td align="center" valign="middle"'+(this.isSelected ? ' background="/en/images/top_menu_selected.gif"' : '')+'>';
    if (this.items.length>0) {
        itemName = 'item'+this.id;
        subName  = 'submenu'+this.id;
        html += '<span style="position:absolute;">';
        html += '<div id="'+subName+'" style="display:none;position:absolute;left:-11px;top:20px;z-index:2;" onmouseover="'+itemName+'.dropDownMenuMouseOver();" onmouseout="'+itemName+'.dropDownMenuMouseOut();">';
        html += '<table bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" class="subMenu0">';
        for (i=0; i<this.items.length; i++) {
            html += this.items[i].render();
            if (i<this.items.length-1)
                html+='<tr><td class="subMenuDelimiter"><img src="/en/images/_.gif" alt="" width="1" height="1" border="0"></td></tr>'
        }
        html += '</table>';
        html += '</div></span>';
        html += '<span onmouseover="'+itemName+'.dropDownMenuMouseOver();" onmouseout="'+itemName+'.dropDownMenuMouseOut();">';
    }
    imgName = 'image'+this.id+'x';
    if (this.imageSelected && !this.isSelected) {
        mouseHandlers = ' onmouseover="imgMouseOver(\''+imgName+'\')" onmouseout="imgMouseOut(\''+imgName+'\')"';
    }
    if (this.isSelected && this.imageSelected) {
        imgURL = this.imageSelected;
    } else {
        imgURL = this.imageDefault;
    }
    html += '<a h'+'ref="'+this.url+'"'+mouseHandlers+'><img id="'+imgName+'" src="'+imgURL+'" alt="'+this.altText+'" height="11" hspace="4" border="0"></a>';
    if (this.items.length>0) html += '</span>';
    html += '</td>';
    return html;
}

// SubMenuItem class
function SubMenuItem(parent, id, text, url) {
    // properties
    this.id = id;
    this.text = text;
    this.url = url;
    this.parent = parent;
    this.items = new Array();
    // methods
    this.render = renderSubMenuItem;
    this.addSubMenuItem = addSubMenuItem;
    this.dropDownMenuMouseOver = dropDownMenuMouseOver;
    this.dropDownMenuMouseOut = dropDownMenuMouseOut;
    this.dropDownMenuClear = dropDownMenuClear;
    this.showSubMenuAndParents = showSubMenuAndParents;
}

function renderSubMenuItem() {
    var i, itemName, cellName, subName, html = '';
    itemName = 'item'+this.id;
    cellName = 'cell'+this.id;
    subName = 'submenu'+this.id;
    parentName = 'submenu'+this.parentID;
    html += '<tr><td id="'+cellName+'" nowrap class="subMenuItem_inactive">';
    if (this.items.length>0) {
        html += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr onmouseover="'+itemName+'.dropDownMenuMouseOver();" onmouseout="'+itemName+'.dropDownMenuMouseOut();">';
        html += '<td width="100%" nowrap class="subMenuItem" onmouseover="'+itemName+'.dropDownMenuMouseOver();" onmouseout="'+itemName+'.dropDownMenuMouseOut();">&nbsp;&nbsp;';
        html += '<a h'+'ref="'+this.url+'" class="subMenuItem" onmouseover="subMenuItemMouseOver(\''+cellName+'\');" onmouseout="subMenuItemMouseOut(\''+cellName+'\');" id="'+itemName+'">'+this.text+'</a>';
        html += '</td><td width="0" align="right" class="subMenuItem"><img src="/en/images/_.gif" width="8" height="1"><img src="/en/images/submenu_more.gif" width="4" height="7">';
        html += '<span id="'+subName+'" style="display:none;position:absolute;padding-top:0px;padding-left:0px;padding-bottom:20px;z-index:2;" onmouseover="'+itemName+'.dropDownMenuMouseOver();" onmouseout="'+itemName+'.dropDownMenuMouseOut();">';
        html += '<div style="position:relative;left:-10px;top:0px;">';
        html += '<table bgcolor="#ffffff" cellspacing="0" cellpadding="0" class="subMenu">';
        for (i=0; i<this.items.length; i++) {
            html += this.items[i].render();
            if (i<this.items.length-1)
                html+='<tr><td class="subMenuDelimiter"><img src="/en/images/_.gif" alt="" width="1" height="1" border="0"></td></tr>'
        }
        html += '</table>';
        html += '</div></span>';
        html += '</td></tr></table>';
    } else {
        html += '&nbsp;&nbsp;';
        html += '<a h'+'ref="'+this.url+'" class="subMenuItem" id="'+itemName+'" onmouseover="subMenuItemMouseOver(\''+cellName+'\');" onmouseout="subMenuItemMouseOut(\''+cellName+'\');">'+this.text+'</a>';
        html += '&nbsp;&nbsp;';
    }
    html += '</td></tr>';
    return html;
}

function showSubMenuAndParents() {
    var obj;
    obj = findObj('submenu'+this.id);
    obj.style.display='block';
    obj.style.visibility='visible';
    dropDownMenuOpened[dropDownMenuOpened.length]=this.id;
    if (this.parent) this.parent.showSubMenuAndParents();
}

// dropDown menu event handlers
var dropDownMenuDelay = 500;
var dropDownMenuClearTimeout;
var dropDownMenuOpened = new Array();
function dropDownMenuMouseOver() {
    if (dropDownMenuClearTimeout) clearInterval(dropDownMenuClearTimeout);
    if (dropDownMenuOpened.length==0 || dropDownMenuOpened[0]!=this.id) {
        dropDownMenuClear();
        this.showSubMenuAndParents();
    }
    self.event.cancelBubble = true;
}

function dropDownMenuMouseOut() {
    if (dropDownMenuClearTimeout) clearInterval(dropDownMenuClearTimeout);
    dropDownMenuClearTimeout = setTimeout("dropDownMenuClear()", dropDownMenuDelay)
    self.event.cancelBubble = true;
}

function dropDownMenuClear() {
    var obj, i, cnt;
    cnt = dropDownMenuOpened.length;
    for(i=0; i<cnt; i++) {
        obj = findObj('submenu'+dropDownMenuOpened[i]);
        obj.style.display='none';
        obj.style.visibility='hidden';
    }
    dropDownMenuOpened.length = 0;
}

function subMenuItemMouseOver(id) {
    var obj;
    if (obj = findObj(id)) {
        obj.className = 'subMenuItem_active';
        //obj.style.color = '#5174AD';
    }
}

function subMenuItemMouseOut(id) {
    var obj;
    if (obj = findObj(id)) {
        obj.className = 'subMenuItem_inactive';
        //obj.style.color = '#315A86';
    }
}

menu = new Menu();
item3 = menu.addMenuItem(3, '/upload/old_images/7cea147e7a2768552e4f05d03feb53b3.gif', '/upload/old_images/fdd3ca27f05f4997ae14e932053016ce.gif', 'Our News', '/en/news', false);
item27 = item3.addSubMenuItem(27, 'Events', '/en/news/?SectionID=148');
item29 = item3.addSubMenuItem(29, 'The Mass Media About Us', '/en/news/?SectionID=150');
item30 = item3.addSubMenuItem(30, 'News Archive', '/en/news');
item5 = menu.addMenuItem(5, '/upload/old_images/d3b0f0b4dca6cea0068561251434e304.gif', '/upload/old_images/25eb8d43cebd3dcf0e8b10f05d61c42c.gif', 'Our Trademarks', '/en/businessgroups', false);
item44 = item5.addSubMenuItem(44, 'Silpo Supermarkets', '/en/businessgroups/silpo.php');
item42 = item5.addSubMenuItem(42, 'Fora Ñonveniences', '/en/businessgroups/fora.php');
item33 = item5.addSubMenuItem(33, 'Fozzy Cash&Carry ', 'http://www.fozzyshop.com/');
item45 = item5.addSubMenuItem(45, 'Bila Romashka, Pharmaceutical Supermarkets Chain', '/en/businessgroups/bilaromashka.php');
item37 = item5.addSubMenuItem(37, 'Bud Zdorovyi Pharmacies', '/en/businessgroups/budzdorov.php');
//item38 = item5.addSubMenuItem(38, 'Îòòî Øòåêêåð', 'http://www.fozzy.ua/?page=contentview&amp;func=contentCtgSetCurrent&amp;ctgID=38&amp;lastPage=home');
item41 = item5.addSubMenuItem(41, 'U Chrom&yacute; Pol Czech Restaurant', '/en/businessgroups/uhromogopola.php');
item6 = menu.addMenuItem(6, '/upload/old_images/2b4ae54cf1cd3ababbd6ca3ea9b9a76e.gif', '/upload/old_images/07cd0525db422e2902936650a8980a70.gif', 'Our Vacancies', '/en/vacancy', false);
//item19 = item6.addSubMenuItem(19, 'ÒÎÏ-âàêàíñèè', 'http://www.fozzy.ua/?page=vacancy&amp;func=vacancySetFilter&amp;lastPage=home&amp;vacTypeID=1');
//item21 = item6.addSubMenuItem(21, 'Ïðîèçâîäñòâî', 'http://www.fozzy.ua/?page=vacancy&amp;func=vacancySetFilter&amp;lastPage=home&amp;vacTypeID=3');
//item22 = item6.addSubMenuItem(22, 'Óñëóãè', 'http://www.fozzy.ua/?page=vacancy&amp;func=vacancySetFilter&amp;lastPage=home&amp;vacTypeID=4');
item7 = menu.addMenuItem(7, '/upload/old_images/481fa31e06dd853de77b7a4c0daa8686.gif', '/upload/old_images/9146eb391b5e01d4fbc9372579bb82bc.gif', 'Contact Us', '/en/contacts', false);