addEvent( window, 'load', load );
var popID;
var tID;
var flash;
function load() {
inMenu = false;
flash = getNode( "flash" );
body = document.getElementsByTagName( "body" )[0];
last = null;

var idro  = new MenuP( getNode( "idronicaline" ));
idro.add( new Menu( "Benvenuto", "http://www.idronicaline.net/index.php?id_sez=006" ) );
idro.add( new Menu( "Come raggiungerci", "http://www.idronicaline.net/index.php?id_sez=009" ) );
idro.add( new Menu( "Novita", "http://www.idronicaline.net/index.php?id_sez=008" ) );
idro.add( new Menu( "Presentazione", "http://www.idronicaline.net/index.php?id_sez=005" ) );
idro.add( new Menu( "Supporto tecnico", "http://www.idronicaline.net/index.php?id_sez=007" ) );
idro.create();

var soft  = new MenuP( getNode( "software" ));
soft.add( new Menu( "STIMA10", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00002" ) );
soft.add( new Menu( "TFM", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00003" ) );
soft.add( new Menu( "MODUL", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00004" ) );
soft.add( new Menu( "PSYCHRO", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00005" ) );
soft.add( new Menu( "TUBI", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00006" ) );
soft.add( new Menu( "UNICO", "http://www.idronicaline.net/index.php?id_sez=soft&id_soft=00007" ) );
//soft.add( new Menu( "Listino prezzi", "http://www.idronicaline.net/index.php?id_sez=027" ) );
soft.add( new Menu( "Caratteristiche generali", "http://www.idronicaline.net/index.php?id_sez=025" ) );
soft.add( new Menu( "Manuali", "http://www.idronicaline.net/index.php?id_sez=026" ) );
soft.create();

var form  = new MenuP( getNode( "formazione" ));
form.add( new Menu( "Presentazione", "http://www.idronicaline.net/index.php?id_sez=017" ) );
form.add( new Menu( "Legge 10/91 + Dlg 192", "http://www.idronicaline.net/index.php?id_sez=018" ) );
form.add( new Menu( "Carichi estivi", "http://www.idronicaline.net/index.php?id_sez=019" ) );
form.add( new Menu( "Impianti termici", "http://www.idronicaline.net/index.php?id_sez=020" ) );
form.add( new Menu( "Bilanciamento idraulico", "http://www.idronicaline.net/index.php?id_sez=021" ) );
form.add( new Menu( "Corsi AICARR", "http://www.idronicaline.net/index.php?id_sez=022" ) );
form.create();

//var onli  = new MenuP( getNode( "online" ));

var down  = new MenuP( getNode( "scarica" ));
down.add( new Menu( "Trial Run", "http://www.idronicaline.net/download.php?dwn_sez=trial" ) );
down.add( new Menu( "Revisioni", "http://www.idronicaline.net/download.php?dwn_sez=revisioni" ) );
down.create();

var lett  = new MenuP( getNode( "letteratura" ));
lett.add( new Menu( "Tecnica", "http://www.idronicaline.net/index.php?id_sez=015" ) );
lett.add( new Menu( "Norme", "http://www.idronicaline.net/index.php?id_sez=016" ) );
lett.add( new Menu( "Software", "http://www.idronicaline.net/index.php?id_sez=023" ) );
lett.create();

//var rece  = new MenuP( getNode( "recensioni" ));

var watt  = new MenuP( getNode( "wattsindustries" ));
//watt.add( new Menu( "Rivista Tecnica", "../dwnld/Catalogo_Idronica_line.pdf" ) );
watt.add( new Menu( "Watts Industries", "http://www.wattsindustries.com/start01.asp?l=it&CID=13" ) );
watt.create();

}

function MenuP ( node ) {
this.node = node;
this.menuItems = new Array();
MenuP.prototype.add = function( menuItem ) {
this.menuItems[ this.menuItems.length ] = menuItem;
}

MenuP.prototype.create = function( ) {
var dNode = document.createElement( "div" );
dNode.className = "jsMenu";
var str = "_" + this.node.id;
dNode.setAttribute( "id", str );
var w = this.node.offsetWidth;
dNode.style.width = w > 160 ? w+"px" : "160px";
dNode.style.top = ( this.node.offsetTop + this.node.offsetHeight ) + "px";
dNode.style.left = this.node.offsetLeft + "px";
addEvent( this.node, "mouseover", function() { showMenuInTime(str, 150) } );
addEvent( this.node, "mouseout", function() { setInMenu(false) } );
dNode.setAttribute( "pItemID", this.node.id );
addEvent( dNode, "mouseover", function() { setInMenu(true) } );
addEvent( dNode, "mouseout", function() { setInMenu(false) } );
var html = "<ul>";
for( var i=0; i<this.menuItems.length; i++ ) {
    html += this.menuItems[i].getLinkHTML();
}
body.appendChild( dNode );
dNode.innerHTML = html + "</ul>";
}
}

function Menu( value, href ) {
this.value = ( value == null ) ? "" : value;
this.href = ( href == null ) ? "" : href;
if( this.href != "" && typeof useAbsPath != "undefined" )
    if( useAbsPath && this.href.indexOf( "http://" ) == -1 && this.href.indexOf( "https://" ) == -1 )
        this.href = "http://www.idronicaline.net" + this.href;
Menu.prototype.getLinkHTML = function () {
    if( this.value != "" && this.href != "" )
        return "<li><a onclick=\"setInMenu(false); hideMenu(); return true;\" href=\"" + this.href + "\">" + this.value + "</a></li>";
    else if( this.value != "" && this.href == "" )
        return "<li class='heading'>" + this.value + "</li>";
    else
        return "<li class='separator'>&nbsp;</li>";
}
}

function showMenuInTime( node, time ) {
popID = setTimeout( "showMenu('" + node + "')", time );
}

function showMenu( node ) {
clearTimeout( popID );
if( typeof node == "string" )
    node = getNode( node );
if( last != null && last != node )
    hideMenu( last );
else if( last == node ) {
    setInMenu( true );
    return;
}
var pItem = getNode( node.getAttribute( "pItemID" ) );
var menuLeft = 0;
var menuTop = pItem.offsetHeight;
var tmp = pItem;
while(tmp!=null && tmp.tagName!="BODY") {
    if( tmp.tagName == "html:body" ) break;

    menuLeft += tmp.offsetLeft;
    //menuTop  += tmp.offsetTop;
    tmp = tmp.offsetParent;
}
node.style.left = menuLeft + "px";
node.style.top = 86 + "px"; /* distanza px tendina bordo superiore menu */
var w = pItem.offsetWidth;
node.style.width = w > 160 ? w+"px" : "160px";
node.style.display = "block";
setInMenu( true );
last = node;
if( flash != null ) flash.style.visibility = "hidden";
tID = setTimeout( "hideMenu( last )", 500 );
}

function hideMenu( node ) {
if( node == null ) {
    setInMenu( false );
    hideMenu( last );
    return;
}
if( typeof node == "string" )
    node = getNode( node );
if( !inMenu ) {
    node.style.display = "none";
    var pItem = getNode( node.getAttribute( "pItemID" ) );
    last = null;
    clearTimeout( tID );
    if( flash != null )	flash.style.visibility = "visible";
} else
    tID = setTimeout( "hideMenu( last )", 500 );
}

function setInMenu( value ) {
inMenu = value;
if( !value ) clearTimeout( popID );
}

function addEvent( node, evtType, func ) {
if( node.addEventListener ) {
    node.addEventListener( evtType, func, false );
    return true;
} else if( node.attachEvent )
    return node.attachEvent( "on" + evtType, func );
else
    return false;
}

function getNode( nodeId ) {
if( document.getElementById )
    return document.getElementById( nodeId );
else if( document.all && document.all( nodeId ) )
    return document.all( nodeId );
else if( document.layers && document.layers[ nodeId ] )
    return document.layers[ nodeId ];
else
    return false;
}