var PopmenuHeight = 4
var POPSUBMENU_GRAPHIC_HEIGHT = 7;
var POPSUBMENU_GRAPHIC_WIDTH = 7;
var POPSUBMENU_GRAPHIC_MARGIN = 10;
var POPMENU_ZINDEX_DEFAULT = 2;
var POPMENU_ID = "PopMenu";
var POPMENUITEM_ID = "MenuItem";
var POPMENU_SUBIMG_ID = "SubImg";
var POPMENU_NSFRAME_ID = "NSFrame";
var POPSUBMENU_OVERLAP = 5;
var POPSUBMENU_DROP = 5;
var TEST_POPMENUITEM_ID = "PopMenuTest";
var TRUE = 0;
var FALSE = 1;
var TRUE = 0;
var FALSE = 1;
var MENUBAR_ID = "MENUBAR";
var MENUBARITEM_ID = "MENUBARITEM";
var MENUBAR_GRAPHIC = "MENUBARGRAPHIC";
var g_fPageLoad = TRUE;
window.onresize = reloadPage;
window.onload = loadPage;
function createPopMenu( a_strTitle )
{
        if( !this.PopMenuContainer )
                this.PopMenuContainer = new Array();
        this.PopMenuContainer[ this.PopMenuContainer.length ] = new createPopMenuObject( a_strTitle, this.PopMenuContainer.length );
        return this.PopMenuContainer[ this.PopMenuContainer.length - 1 ];
}
function createPopMenuObject( a_strText, a_nIndex )
{
        this.popMenuItems = new Array();
        this.Text = a_strText;
        this.Action = "";
        this.addPopMenuItem = addPopMenuItem;
        this.parent = "";
        this.closeWindow = TRUE;
        this.Index = a_nIndex;
        this.width = 0;
        this.setPopMenuWidth = setPopMenuWidth; 
}
function addPopMenuItem( a_strText, a_strAction )
{
        this.popMenuItems[ this.popMenuItems.length ] = new createPopMenuItemObject( a_strText, a_strAction, this );
}
function createPopMenuItemObject( a_strText, a_strAction, a_popMenuParent )
{
        this.Text = a_strText;
        this.Action = a_strAction;
        this.parent = a_popMenuParent;
}
function initPopMenu( a_BgColor, a_SelBgColor, a_nBorderSize )
{
        g_PopBgColor = a_BgColor;
        g_PopSelBgColor = a_SelBgColor;
        g_PopBorderSize = a_nBorderSize;
        writePopMenuHTML();
        posPopMenuItems();
}
function writePopMenuHTML()
{       
        var strOutput = '<DIV ID="' + TEST_POPMENUITEM_ID + '" CLASS="PopMenuItemStyle">';
        strOutput += '<IMG SRC="images/empty.gif" WIDTH=' + POPSUBMENU_GRAPHIC_WIDTH + ' HEIGHT=' + POPSUBMENU_GRAPHIC_HEIGHT + ' BORDER=0 ALT="" ALIGN="RIGHT"></DIV>';
        document.write( strOutput );
        if( document.all )
                this[ TEST_POPMENUITEM_ID ].style.visibility = "hidden";
        else
                document[ TEST_POPMENUITEM_ID ].visibility = "hidden";
        strOutput = "";
        for( var nIndex = 0; nIndex < this.PopMenuContainer.length; nIndex++ )
        {
                var menuCurrent = this.PopMenuContainer[ nIndex ];
                strOutput += '<DIV ID="' + POPMENU_ID + nIndex + '" CLASS="PopMenuContainerStyle">';
                for( var nItemIndex = 0; nItemIndex < menuCurrent.popMenuItems.length; nItemIndex++ )
                {
                        strOutput += '<DIV ID="' + POPMENU_ID + nIndex + POPMENUITEM_ID + nItemIndex + '" CLASS="PopMenuItemStyle">';
                        strOutput += '<IMG SRC="images/empty.gif" WIDTH=' + POPSUBMENU_GRAPHIC_WIDTH + ' HEIGHT=' + POPSUBMENU_GRAPHIC_HEIGHT + ' BORDER=0 ALT="" ALIGN="RIGHT">'
                        strOutput += '&nbsp;' + menuCurrent.popMenuItems[ nItemIndex ].Text + '</DIV>';
                } 
                strOutput += "</DIV>";
        } 
        document.write( strOutput );
}
function posPopMenuItems()
{
        var nHeight;
        var nWidth = 0;
        if( document.all )
        {
                nHeight = this[ TEST_POPMENUITEM_ID ].offsetHeight - PopmenuHeight ;
                nWidth = this[ TEST_POPMENUITEM_ID ].offsetWidth;
        }
        else
        {
                nHeight = document[ TEST_POPMENUITEM_ID ].clip.height - PopmenuHeight;
                nWidth = document[ TEST_POPMENUITEM_ID ].clip.width;
        }
        for( var nIndex = 0; nIndex < this.PopMenuContainer.length; nIndex++ )
        {
                var menuCurrent = this.PopMenuContainer[ nIndex ];
                var menuDiv;
                if( document.all )
                        var menuDiv =  this[ POPMENU_ID + nIndex ].style;
                else
                        var menuDiv = document[ POPMENU_ID + nIndex ];
                menuDiv.popMenuInfo = menuCurrent;
                var nItemWidth = nWidth;
                if( menuCurrent.width != 0 )
                        nItemWidth = menuCurrent.width;
                var nContHeight = nHeight * menuCurrent.popMenuItems.length + ( g_PopBorderSize * 2 ) + PopmenuHeight;
                var nContWidth = nItemWidth + ( g_PopBorderSize * 2 );
                menuDiv.height = nContHeight;
                menuDiv.width = nContWidth;
                if( !document.all )
                {
                        var nFrameHeight = (nHeight * menuCurrent.popMenuItems.length) - 6;
                        var nFrameWidth = nItemWidth - 6;
                        document.write( '<DIV ID="' + POPMENU_NSFRAME_ID + nIndex + '" CLASS="PopMenuContainerStyle"><TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=' + nFrameWidth + '><TR><TD HEIGHT=' + nFrameHeight + '></TD></TR></TABLE></DIV>' );
                        document[ POPMENU_NSFRAME_ID + nIndex ].height = nContHeight;
                        document[ POPMENU_NSFRAME_ID + nIndex ].width = nContWidth;
                        document[ POPMENU_NSFRAME_ID + nIndex ].clip.height = nHeight * menuCurrent.popMenuItems.length + ( g_PopBorderSize * 2 );      // Add one for NS               
                        menuDiv.clip.height = nHeight * menuCurrent.popMenuItems.length + ( g_PopBorderSize * 2 ) + 1;                                                                  // Add one for NS
                }
                for( var nItemIndex = 0; nItemIndex < menuCurrent.popMenuItems.length; nItemIndex++ )
                {
                        var menuItemDiv; var menuItemHref;
                        if( document.all )
                        {
                                menuItemDiv = this[ POPMENU_ID + nIndex + POPMENUITEM_ID + nItemIndex ];
                                menuItemDiv.style.backgroundColor = g_PopBgColor;
                                menuItemDiv.style.top = nHeight * nItemIndex;
                                menuItemDiv.style.width = nItemWidth;
                        }
                        else
                        {
                                menuItemDiv = document[ POPMENU_ID + nIndex ].document[ POPMENU_ID + nIndex + POPMENUITEM_ID + nItemIndex ];
                                menuItemDiv.top = nHeight * nItemIndex;
                                menuItemDiv.bgColor = g_PopBgColor;
                                menuItemDiv.clip.width = nItemWidth;                            
                                menuItemDiv.captureEvents( Event.MOUSEUP );                             
                        }
                        menuItemDiv.onmouseover = popMenuItemMouseOver;
                        menuItemDiv.onmouseout = popMenuItemMouseOut;
                        menuItemDiv.onmouseup = popMenuItemMouseUp;
                        menuItemDiv.popMenuInfo = menuCurrent.popMenuItems[ nItemIndex ];
                        menuItemDiv.ItemIndex = nItemIndex;
                }
        } 
}
function popMenuItemMouseOver()
{
        this.popMenuInfo.parent.closeWindow = FALSE;
        if( this.popMenuInfo.parent.parent.popMenuItems )
                this.popMenuInfo.parent.parent.closeWindow = FALSE;
        var nTop;
        var nLeft;
        var nZIndex;
        if( document.all )
        {
                var divText = window[ POPMENU_ID + this.popMenuInfo.parent.Index + POPMENUITEM_ID + this.ItemIndex ];
                divText.style.backgroundColor = g_PopSelBgColor;
                nTop = divText.offsetParent.offsetTop + divText.offsetTop + POPSUBMENU_DROP;
                nLeft = divText.offsetParent.offsetLeft + divText.offsetWidth - POPSUBMENU_OVERLAP;
                nZIndex = window[ POPMENU_ID + this.popMenuInfo.parent.Index ].style.zIndex;
        }
        else
        {
                var divText = window.document[ POPMENU_ID + this.popMenuInfo.parent.Index ].document[ POPMENU_ID + this.popMenuInfo.parent.Index + POPMENUITEM_ID + this.ItemIndex ];
                divText.document.bgColor = g_PopSelBgColor;
                nLeft = divText.pageX + divText.clip.width - POPSUBMENU_OVERLAP;
                nTop = divText.pageY + POPSUBMENU_DROP;
                nZIndex = window.document[ POPMENU_ID + this.popMenuInfo.parent.Index ].zIndex;
        }
}
function showPopMenu( a_popMenu, a_nXPos, a_nYPos, a_nZIndex )
{
        a_popMenu.closeWindow = FALSE;
        if( a_nZIndex == 0 || a_nZIndex == null )
                a_nZIndex = POPMENU_ZINDEX_DEFAULT;
        var divMenu;
        var divNSFrame;
        if( document.all )
        {
                divMenu = this[ POPMENU_ID + a_popMenu.Index ].style;
                divMenu.top = a_nYPos;
                divMenu.left = a_nXPos;
        }
        else
        {
                divMenu = document[ POPMENU_ID + a_popMenu.Index ];
                divMenu.top = a_nYPos + g_PopBorderSize;
                divMenu.left = a_nXPos + g_PopBorderSize;
                divNSFrame = document[ POPMENU_NSFRAME_ID + a_popMenu.Index ];
                divNSFrame.top = a_nYPos;
                divNSFrame.left = a_nXPos;
                divNSFrame.zIndex = a_nZIndex + 1;
                divNSFrame.visibility = "visible";
        }
        divMenu.zIndex = a_nZIndex + 1; 
        divMenu.visibility = "visible";
}
function hidePopMenu( a_popMenu )
{
        var divMenu;
        var divNSFrame;
        if( a_popMenu.popMenuItems )
        {
                if( document.all )
                        divMenu = this[ POPMENU_ID + a_popMenu.Index ].style;
                else
                {
                        divMenu = document[ POPMENU_ID + a_popMenu.Index ];
                        divNSFrame = document[ POPMENU_NSFRAME_ID + a_popMenu.Index ];
                }
        }
        else 
        {
                if( document.all )
                        divMenu = this[ POPMENU_ID + a_popMenu ].style;
                else
                {
                        divMenu = document[ POPMENU_ID + a_popMenu ];
                        divNSFrame = document[ POPMENU_NSFRAME_ID + a_popMenu ];
                }       
        }
        if( divMenu.popMenuInfo.closeWindow == TRUE )
        {
                divMenu.visibility = "hidden";
                if( !document.all )
                        divNSFrame.visibility = "hidden";
                if( divMenu.popMenuInfo.parent.popMenuItems )
                {
                        hidePopMenu( divMenu.popMenuInfo.parent );
                }
                else
                {
                        hidePopMenuCallBack( divMenu.popMenuInfo );
                }
        }
}
function popMenuItemMouseUp()
{
        if( this.popMenuInfo.Action != "" )
                if( g_PopActionDestSelf == true )
                {                
                        window.open( this.popMenuInfo.Action, "_self" );
                }
                else
                {
                        window.open( this.popMenuInfo.Action, "_blank" );
                 }
}
function setPopMenuWidth( a_nMenuWidth )
{
        this.width = a_nMenuWidth;
}
function setPopActionDestSelf( a_fSameWindow )
{
        g_PopActionDestSelf = a_fSameWindow;
}
function popMenuItemMouseOut()
{
        if( document.all )
                window[ POPMENU_ID + this.popMenuInfo.parent.Index + POPMENUITEM_ID + this.ItemIndex ].style.backgroundColor = g_PopBgColor;
        else
        {
                window.document[ POPMENU_ID + this.popMenuInfo.parent.Index ].document[ POPMENU_ID + this.popMenuInfo.parent.Index + POPMENUITEM_ID + this.ItemIndex ].bgColor = g_PopBgColor;
        }
        if( this.popMenuInfo.parent.parent.popMenuItems )
                this.popMenuInfo.parent.parent.closeWindow = TRUE;
        setTimeout( "hidePopMenu( '" + this.popMenuInfo.parent.Index + "' );", 100 );
        this.popMenuInfo.parent.closeWindow = TRUE;
}
function reloadPage()
{
        if( !document.all  )
        {
                if( (g_fPageLoad == FALSE) && ( (parseFloat( navigator.appVersion )) < 4.1 ) )
                        location.reload();
                if( (parseFloat( navigator.appVersion ) >= 4.1) )
                        location.reload();
                g_fPageLoad = FALSE;
        }
}
function loadPage()
{
        g_fPageLoad = TRUE;
}
function createMenuBar()
{
        if( !this.MenuBarContainer )
                this.MenuBarContainer = new createMenuBarObject();
        return this.MenuBarContainer;
}
function createMenuBarObject()
{
        this.menuBarItems = new Array();
        this.addMenuBarItem = addMenuBarItem;
}
function createMenuBarItem( a_strAction, a_intWidth, a_intHeight )
{
        this.PopMenu;
        this.Text = "";
        this.Action = a_strAction;
        this.ImageOn = new Image();
        this.ImageOff = new Image();
        this.ImageActive = new Image();
        this.Width = a_intWidth;
        this.Height = a_intHeight;
        this.ItemImage = null;                                  
        this.ItemIndex = 0;     
        this.setImageOn = setImageOn;
        this.setImageOff = setImageOff;
        this.setPopMenu = setPopMenu;
        this.IsPressed = false;
        this.setActive = setActive;
}
function addMenuBarItem( a_strAction, a_intWidth, a_intHeigth )
{
        this.menuBarItems[ this.menuBarItems.length ] = new createMenuBarItem( a_strAction, a_intWidth, a_intHeigth );
        return this.menuBarItems[ this.menuBarItems.length - 1];
}
function setImageOn( a_strGraphicSrc )
{
   this.ImageOn.src = a_strGraphicSrc;
}
function setImageOff( a_strGraphicSrc )
{
        this.ImageOff.src = a_strGraphicSrc;
}
function setPopMenu( a_PopMenu )
{
        this.PopMenu = a_PopMenu;
        this.Text = a_PopMenu.Text;
}
function setActive( a_strActiveImg )
{
        this.IsPressed = true;
        this.ImageActive.src = a_strActiveImg;
}
function initMenuBar()
{
        writeMenuBarHTML();
        posMenuBarItems();
}
function writeMenuBarHTML()
{
        var strOutput = "";
        var menuBarCurrent = this.MenuBarContainer;
        for( var nItemIndex = 0; nItemIndex < menuBarCurrent.menuBarItems.length; nItemIndex++ )
        {
                var menuBarItem = menuBarCurrent.menuBarItems[ nItemIndex ];
                if(menuBarItem.IsPressed == true) 
                      ItemSrc = menuBarItem.ImageActive.src;
                else
                      ItemSrc = menuBarItem.ImageOff.src;
                strOutput += '<A class="MenuBarItemStyle" HREF="' + menuBarItem.Action + '" onMouseOver="menuBarItemMouseOver( window.MenuBarContainer.menuBarItems[' + nItemIndex + '] )" onMouseOut="menuBarItemMouseOut( window.MenuBarContainer.menuBarItems[' + nItemIndex + '] )"><IMG NAME="' + MENUBAR_GRAPHIC + nItemIndex + '" ALT="ITW GEMA ПОЛИТЕГ" BORDER="0"  hspace="0"  SRC="' + ItemSrc + '"' + ((menuBarItem.Width != null)?' WIDTH="'+menuBarItem.Width+'"':'') + ((menuBarItem.Height != null)? ' HEIGHT="'+menuBarItem.Height+'"':'') + '></A>';
        }
        document.write( strOutput );
}
function posMenuBarItems()
{
        var menuBarCurrent = this.MenuBarContainer;
        for( var nItemIndex = 0; nItemIndex < menuBarCurrent.menuBarItems.length; nItemIndex++ )
        {
                var menuBarImg;
                if( document.all )
                        menuBarImg = this.document.images[ MENUBAR_GRAPHIC + nItemIndex ];
                else
                        menuBarImg = document.images[ MENUBAR_GRAPHIC + nItemIndex ];
                menuBarCurrent.menuBarItems[ nItemIndex ].ItemImage = menuBarImg;
                menuBarCurrent.menuBarItems[ nItemIndex ].ItemIndex = nItemIndex;
        }
}
function menuBarItemMouseOver( a_MenuItem )
{
        if( !a_MenuItem.IsPressed ) a_MenuItem.ItemImage.src = a_MenuItem.ImageOn.src;
        if( document.all )
        {
                var nLeft = 0;
                var nTop = 0;
                var fParentExists = true;
                var CurrentObject = a_MenuItem.ItemImage;
                while( fParentExists )
                {
                        nLeft += CurrentObject.offsetLeft;
                        nTop += CurrentObject.offsetTop;
                        if( CurrentObject.offsetParent.tagName != "BODY" )
                                CurrentObject = CurrentObject.offsetParent;
                        else
                                fParentExists = false;
                }
                showPopMenu( a_MenuItem.PopMenu, nLeft, nTop + a_MenuItem.ItemImage.height );
        }
        else
                showPopMenu( a_MenuItem.PopMenu, a_MenuItem.ItemImage.x, a_MenuItem.ItemImage.y + a_MenuItem.ItemImage.height);
}
function menuBarItemMouseOut( a_MenuItem )
{
        a_MenuItem.PopMenu.closeWindow = TRUE;  
        setTimeout( 'deactivateImage( window.MenuBarContainer.menuBarItems[' + a_MenuItem.ItemIndex + '] )', 50 );
}
function deactivateImage( a_MenuItem )
{
        if( a_MenuItem.PopMenu.closeWindow == TRUE )
        {
                if( !a_MenuItem.IsPressed ) a_MenuItem.ItemImage.src = a_MenuItem.ImageOff.src;
                hidePopMenu( a_MenuItem.PopMenu );
        }
}
function hidePopMenuCallBack( a_popMenu )
{
        for( var nItemIndex = 0; nItemIndex < this.MenuBarContainer.menuBarItems.length; nItemIndex++ )
        {
                if(( this.MenuBarContainer.menuBarItems[ nItemIndex ].PopMenu.Text == a_popMenu.Text )&&( !this.MenuBarContainer.menuBarItems[ nItemIndex ].IsPressed) )
                       this.MenuBarContainer.menuBarItems[ nItemIndex ].ItemImage.src = this.MenuBarContainer.menuBarItems[ nItemIndex ].ImageOff.src;
        }
}




function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

	var corp = createPopMenu( "Corporate", "#" );
	corp.addPopMenuItem( "О фирме", "about.html" );
	corp.addPopMenuItem( "Новости", "news.html" );
	corp.addPopMenuItem( "Наши партнеры", "partner.html" );
	corp.addPopMenuItem( "Форум", "http://www.guestbook.ru/book.php?user=Polyteg&action=show" );
	corp.addPopMenuItem( "Вакансии", "mail.html");
	corp.addPopMenuItem( "Контакты", "contacts.html" );
	corp.setPopMenuWidth( 148 );

	var news = createPopMenu( "Technology", "#" );
	news.addPopMenuItem( "Технология", "technology.html" );
	news.addPopMenuItem( "Статьи", "tech-article.html" );
	news.addPopMenuItem( "Вопросы и ответы", "ask.html" );
	news.setPopMenuWidth( 149 );

	var products = createPopMenu( "Service", "#" );
	products.setPopMenuWidth( 149 );

	var sales_manager = createPopMenu( "Equpment", "#" );
	sales_manager.addPopMenuItem( "Комплект. оборуд.", "sfb-about.html" );
	sales_manager.addPopMenuItem( "ITW Gema ", "itw-about.html" );
	sales_manager.addPopMenuItem( "Партнеры", "cps-about.html" );
	sales_manager.addPopMenuItem( "Участок окраски", "uchastok-open.html" );
	sales_manager.addPopMenuItem( "Комплектующие", "defil-about.html" );
	sales_manager.addPopMenuItem( "Тех. задание", "form.html" );
	sales_manager.addPopMenuItem( "Наши проекты", "projekt.html" );
	sales_manager.setPopMenuWidth( 149 );

	var sitemap = createPopMenu( "Paint", "#" );
	sitemap.addPopMenuItem( "Общие сведения", "paint-about.html" );
	sitemap.addPopMenuItem( "Порошки JOTUN", "paint.html" );
	sitemap.addPopMenuItem( "Прайс-лист", "paint-price.html" );
        sitemap.addPopMenuItem( "Распродажа", "rasprodaga.html" );
	sitemap.setPopMenuWidth( 149 );

	
	setPopActionDestSelf( true );
	initPopMenu( "f0f0f0", "cccccc", 1 );

	var MenuBar = createMenuBar();

	var corp2 = MenuBar.addMenuBarItem( "#" );
	corp2.setImageOn( "images/knopki_html_smartbutton6.gif" );
	corp2.setImageOff( "images/knopki_html_smartbutton1.gif" );
	corp2.setPopMenu( corp );
	
	var news2 = MenuBar.addMenuBarItem( "#" );
	news2.setImageOn( "images/knopki_html_smartbutton7.gif" );
	news2.setImageOff( "images/knopki_html_smartbutton2.gif" );
	news2.setPopMenu( news );

	var products2 = MenuBar.addMenuBarItem( "#" );
	products2.setImageOn( "images/knopki_html_smartbutton8.gif" );
	products2.setImageOff( "images/knopki_html_smartbutton3.gif" );
	products2.setPopMenu( products );

	var sales_manager2 = MenuBar.addMenuBarItem( "#" );
	sales_manager2.setImageOn( "images/knopki_html_smartbutton9.gif" );
	sales_manager2.setImageOff( "images/knopki_html_smartbutton4.gif" );
	sales_manager2.setPopMenu( sales_manager );

	var sitemap2 = MenuBar.addMenuBarItem( "#" );
	sitemap2.setImageOn( "images/knopki_html_smartbutton10.gif" );
	sitemap2.setImageOff( "images/knopki_html_smartbutton5.gif" );
	sitemap2.setPopMenu( sitemap );

	
