/* $Id: menu.js,v 1.27 2011/04/29 08:42:51 wolf Exp $ */

var menuItemWidth = 125;
var menuItemHeight = 19;

// Sprache herausfinden	
var chwUrl = window.location.pathname;
//alert (chwURL);
var chwResult = chwUrl.indexOf("ger");
var chwLang = (chwResult != -1) ? 'ger': 'engl';

if (document.images) { // Browser supports image swaps (most do)
    var menuOutButtons = new Array();
    menuOutButtons[0] = new Image();
    menuOutButtons[0].src = "/" + chwLang + "/images/menu_prod.gif";
    menuOutButtons[1] = new Image();
    menuOutButtons[1].src = "/" + chwLang + "/images/menu_firma.gif";
    menuOutButtons[2] = new Image();
    menuOutButtons[2].src = "/" + chwLang + "/images/menu_kontakt.gif";
    menuOutButtons[3] = new Image();
    menuOutButtons[3].src = "/" + chwLang + "/images/menu_press.gif";

    var menuOverButtons = new Array();
    menuOverButtons[0] = new Image();
    menuOverButtons[0].src = "/" + chwLang + "/images/menu_prod_mo.gif";
    menuOverButtons[1] = new Image();
    menuOverButtons[1].src = "/" + chwLang + "/images/menu_firma_mo.gif";
    menuOverButtons[2] = new Image();
    menuOverButtons[2].src = "/" + chwLang + "/images/menu_kontakt_mo.gif";
    menuOverButtons[3] = new Image();
    menuOverButtons[3].src = "/" + chwLang + "/images/menu_press_mo.gif";
}

var menuLengths = new Array(7,6,3,3);
var menuURLs = new Array(menuLengths.length);
for (i=0;i<menuLengths.length;i++) 
    menuURLs[i] = new Array(menuLengths[i]);

menuURLs[0][0] = "/" + chwLang + "/intertec-relays-relais-brands.html";
menuURLs[0][3] = "/" + chwLang + "/p_visuals.php";
menuURLs[0][2] = "/" + chwLang + "/p_solenoids.php";
menuURLs[0][1] = "/" + chwLang + "/p_semicon.php";
menuURLs[0][4] = "/" + chwLang + "/p_frequency.php";
menuURLs[0][5] = "/" + chwLang + "/p_stock.php";
//menuURLs[0][4] = "/" + chwLang + "stocklist-1.html";
menuURLs[0][6] = "/" + chwLang + "/p_linecard.php";
//menuURLs[0][7] = "http://www.intertec-shop.de";
menuURLs[1][0] = "/" + chwLang + "/f_jobs.php";         
menuURLs[1][1] = "/" + chwLang + "/f_philo.php";        
menuURLs[1][2] = "/" + chwLang + "/f_news.php";      
menuURLs[1][3] = "/" + chwLang + "/f_impress.php";
menuURLs[1][4] = "/" + chwLang + "/f_traderef.php";
menuURLs[1][5] = "/" + chwLang + "/f_agb.php";
menuURLs[2][0] = "/" + chwLang + "/k_anfahrt.php";
menuURLs[2][1] = "/" + chwLang + "/k_mitarbeiter.php";
menuURLs[2][2] = "javascript:popupwin(1, 'k_callback.php?lang="+ chwLang+"', 'width=420,height=400,screenX=40,screenY=50,top=50,left=40,scrollbars=no');";
menuURLs[3][0] = "/" + chwLang + "/pr_mit.php";
menuURLs[3][1] = "/" + chwLang + "/pr_downl.php";
menuURLs[3][2] = "/" + chwLang + "/pr_fachartikel.php";


var menuTimers = new Array(menuLengths.length);

function getStyleObj(id) {
    if (document.getElementById || // DOM-compliant browsers (MSIE5, NSN6, O5)
        document.all) {            // or MSIE 4
        return getObj(id).style;
    } else return getObj(id); // NSN4
}

function getObj(id) {
    if (document.getElementById) { // DOM-compliant browsers (MSIE5, NSN6, O5)
        return document.getElementById(id);
    } else if (document.all) { // MSIE4
        return document.all[id];
    } else if (document.layers) { // NSN4
        return document.layers[id];
    } else { // Trap DHTML-impaired browsers 
        //alert("Your browser does not support DHTML!");
        return false;
    }
}

function showMenu(index) {
	//alert(index);
    if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);

    for (i=1;i<=menuLengths.length;i++)
        if (i!=index) closeMenu(i);

    var menu = getStyleObj("menu"+index);
    if (menu) menu.visibility = "visible";
    if (document.images) document.images["menubutton"+index].src =
                            menuOverButtons[index-1].src;
}

function hideMenu(index) {
    if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);
    menuTimers[index-1] = setTimeout("closeMenu('"+index+"');",500);
}

function closeMenu(index) {
    var menu = getStyleObj("menu"+index);
    if (menu) menu.visibility = "hidden";
    if (document.images) document.images["menubutton"+index].src =
                            menuOutButtons[index-1].src;
}

function overMenuItem() {
    this.hilightitem.visibility='visible';
    showMenu(this.menuid);
}

function outMenuItem() {
    this.hilightitem.visibility='hidden';
    hideMenu(this.menuid);
}

function clickMenuItem() {
    if (this.url) { // There is a URL associated with this item
    	var myurl = this.url;
    	if(myurl.indexOf("http") != -1){ 
        	window.open(this.url, "_blank");
		}else{
			window.location = this.url;
		}
    }
}

window.onload=setupMenus; // Assign to onLoad event handler
function setupMenus() {
    if (document.layers) { // This section is for Netscape 4 only
        for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu
            var menu = getObj("menu"+menuid);
            menu.clip.width = menuItemWidth + 2;
            menu.clip.height = (menuItemHeight+1) * menuLengths[menuid-1] + 1;
            menu.document.bgColor="#3f3f3f";

            for (i=1;i<=menuLengths[menuid-1];i++) { // For each menu item
                var item = eval("menu.document.menu"+menuid+"item"+i);
                var onitem = eval("menu.document.menu"+menuid+"item"+i+"on");
                item.top = (menuItemHeight + 1) * (i-1) + 1;
                onitem.top = (menuItemHeight + 1) * (i-1) + 1;
                item.clip.width = menuItemWidth;
                item.clip.height = menuItemHeight;
                item.document.bgColor="#3f3f3f";
                onitem.clip.width = menuItemWidth;
                onitem.clip.height = menuItemHeight;
                onitem.document.bgColor="#000000";

                item.hilightitem = onitem;
                onitem.hilightitem = onitem;

                item.menuid = menuid;
                onitem.menuid = menuid;
                var url = menuURLs[menuid-1][i-1];
                item.url = url;
                onitem.url = url;

                var eTypes = Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK;
                item.captureEvents(eTypes);
                onitem.captureEvents(eTypes);
                item.onmouseover = overMenuItem;
                onitem.onmouseover = overMenuItem;
                item.onmouseout = outMenuItem;
                onitem.onmouseout = outMenuItem;
                item.onclick = clickMenuItem;
                onitem.onclick = clickMenuItem;
            }
        }
    } else { // This section is for all other browsers
        for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu
        	for (i=1;i<=menuLengths[menuid-1];i++) { // For each menu item
                var item = getObj("menu"+menuid+"item"+i);
                var onitem = getObj("menu"+menuid+"item"+i+"on");
                var itemstyle = getStyleObj("menu"+menuid+"item"+i);
                var onitemstyle = getStyleObj("menu"+menuid+"item"+i+"on");
                itemstyle.top = (menuItemHeight + 1) * (i-1) + 1 +"px";
                onitemstyle.top = (menuItemHeight + 1) * (i-1) + 1 +"px";
                if (navigator.appName=="Microsoft Internet Explorer") {
                    itemstyle.cursor = "hand";
                    onitemstyle.cursor = "hand";
                }
                item.hilightitem = onitemstyle;
                onitem.hilightitem = onitemstyle;
                item.menuid = menuid;
                onitem.menuid = menuid;
                var url = menuURLs[menuid-1][i-1];
                item.url = url;
                onitem.url = url;
                item.onmouseover = overMenuItem;
                onitem.onmouseover = overMenuItem;
                item.onmouseout = outMenuItem;
                onitem.onmouseout = outMenuItem;
                item.onclick = clickMenuItem;
                onitem.onclick = clickMenuItem;
            }
        }
    }
}

function handleResize() {
  location.reload();
  return false;
}
if (document.layers) {
  window.onresize = handleResize;
}

