// JavaScript Document

/*

//Contents for menu azienda
var menu1=new Array()
menu1[0]='<a href="chi_siamo.php">chi siamo</a>'
menu1[1]='<a href="focus.php">focus</a>'
menu1[2]='<a href="collaborazioni.php">collaborazioni</a>'
menu1[3]='<a href="storia.php">storia</a>'
menu1[4]='<a href="#">controllo qualità sicurezza</a>'
menu1[5]='<a href="contatti.php">contatti&nbsp;</a>'

//Contents for menu idrocoltura
var menu2=new Array()
menu2[0]='<a href="cosa.php">cos\'è</a>'
menu2[1]='<a href="vantaggi.php">vantaggi&nbsp;</a>'
menu2[2]='<a href="come_funziona.php">come funziona</a>'
menu2[3]='<a href="materiale_informativo.php">materiale informativo</a>'

//Contents for menu servizi
var menu3=new Array()
menu3[0]='<a href="progettazione.php">progettazione</a>'
menu3[1]='<a href="rendering_fotografici.php">rendering fotografici&nbsp;</a>'
menu3[2]='<a href="noleggio.php">noleggio</a>'
menu3[3]='<a href="manutenzione.php">manutenzione</a>'
menu3[4]='<a href="businnes_consumer.php"">vendita</a>'
menu3[5]='<a href="garanzia.php">garanzia</a>'


//Contents for menu prodotti
var menu4=new Array()
menu4[0]='<a href="piante_fioriere.php">piante e fioriere</a>'
menu4[1]='<a href="vasi_contenitori.php">vasi contenitori&nbsp;</a>'
menu4[2]='<a href="accessori_idrocoltura.php">accessori idrocoltura</a>'
menu4[3]='<a href="hobby_set.php">hobby set</a>'


var menuwidth='165px' //default menu width
var menubgcolor='#669b09'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all
var currentLink;

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu();openQuad();" onMouseout="dynamichide(event);closeQuad();"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth)
{
  if (ie4||ns6)
  dropmenuobj.style.left=dropmenuobj.style.top=-500
  
  if (menuwidth!="")
  {
    dropmenuobj.widthobj=dropmenuobj.style
    dropmenuobj.widthobj.width=menuwidth
  }
  if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
  {
    obj.visibility = visible
  }
  else if (e.type=="click")
  {
    obj.visibility=hidden
  }
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function dropdownmenu(obj, e, menucontents, menuwidth)
{
  if (window.event) 
    event.cancelBubble = true
  else if (e.stopPropagation) 
    e.stopPropagation()
  
  clearhidemenu()
  dropmenuobj = document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
  populatemenu(menucontents)
  
  if (ie4||ns6)
  {
    showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
    dropmenuobj.x=getposOffset(obj, "left")
    dropmenuobj.y=getposOffset(obj, "top")
    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
  }
  
  currentLink = obj  // Memorizzo il link attivo - potrei annullarlo all'uscita. 
  
  return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e)
{
  if (ie4&&!dropmenuobj.contains(e.toElement))
    delayhidemenu()
  else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
    delayhidemenu()
}

function hidemenu(e)
{
  if (typeof dropmenuobj!="undefined")
  {
    if (ie4||ns6)
      dropmenuobj.style.visibility = "hidden"
  }
}

function delayhidemenu()
{
  if (ie4||ns6)
    delayhide = setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu()
{
  if (typeof delayhide!="undefined")
  {
    clearTimeout(delayhide)
  }
}

function openQuad(obj)
{ 
  if (typeof delayClose!="undefined")
  {
    clearTimeout ( delayClose )
  }
  
  document.getElementById("menu1").style.backgroundImage = "";
  document.getElementById("menu2").style.backgroundImage = "";
  document.getElementById("menu3").style.backgroundImage = "";
  document.getElementById("menu4").style.backgroundImage = "";
  document.getElementById("menu5").style.backgroundImage = "";
  document.getElementById("menu6").style.backgroundImage = "";
  document.getElementById("menu7").style.backgroundImage = "";
    
  obj = currentLink
  obj.style.backgroundImage = "url(immagini/quad.gif)";
  obj.style.backgroundPosition = "left 8px";
  obj.style.backgroundRepeat = "no-repeat";
}

function closeQuad(obj)
{
  delayClose = setTimeout("closeQuadImm()",disappeardelay)
}

function closeQuadImm(obj)
{
  obj = currentLink
  obj.style.backgroundImage = "";
  obj.style.backgroundPosition = "left 8px";
  obj.style.backgroundRepeat = "no-repeat";
  
}


if (hidemenu_onclick=="yes")
  document.onclick=hidemenu
*/

$E.add (window, "load", init_menu, false);

function init_menu(e, handle) 
{
	if ( tag = document.getElementById('menuNav') )
	{
  	 
   for (var i=0; i<tag.childNodes.length; i++)
   {
      tags = tag.childNodes;
      
      if (tags[i].childNodes.length > 1)
      {
        if (tags[i].childNodes[1].nodeName.toLowerCase() == "ul" )
        {
           op_mn = function(e, idx, arg){
                         closeAllMenu(null,null);
                         arg["obj"].style.visibility = "visible";
                         arg["obj"].style.position = "absolute";
                         arg["obj"].style.top = "10px";
                         arg["obj"].style.left = "-1px";
                         //arg["obj"].style.borderTop = "1px solid #d5d5d5";
                    };
                                        
           $E.add( tags[i], "mouseover", op_mn, false, { "obj" : tags[i].childNodes[1]} );
           
           var cl_mn = function (e,idx, arg){
                         arg["obj"].style.visibility = "hidden";
                        };
                        
           $E.add (tags[i].childNodes[1], "mouseout", cl_mn, false, { "obj": tags[i].childNodes[1]} );
        }
      }
      else
      {
        $E.add (tags[i],"mouseover",closeAllMenu,false);
        $E.add (tags[i],"mouseout",closeAllMenu,false);
      }
   }
  }
  
  $E.add ( $("menu1"), "mouseout", closeQuad, false);
  $E.add ( $("menu1"), "mouseover", openQuad, false);
  
  $E.add ( $("menu2"), "mouseout", closeQuad, false);
  $E.add ( $("menu2"), "mouseover", openQuad, false);
  
  $E.add ( $("menu3"), "mouseout", closeQuad, false);
  $E.add ( $("menu3"), "mouseover", openQuad, false);
  
  $E.add ( $("menu4"), "mouseout", closeQuad, false);
  $E.add ( $("menu4"), "mouseover", openQuad, false);
  
  $E.add ( $("menu5"), "mouseout", closeQuad, false);
  $E.add ( $("menu5"), "mouseover", openQuad, false);
  
  $E.add ( $("menu6"), "mouseout", closeQuad, false);
  $E.add ( $("menu6"), "mouseover", openQuad, false);
  
  $E.add ( $("menu7"), "mouseout", closeQuad, false);
  $E.add ( $("menu7"), "mouseover", openQuad, false);
  
  // Faccio partire l'header
  fnLoad()
}

function closeAllMenu(e){
 	if(tag = document.getElementById('menuNav'))
	{	 
   for (var i=0; i<tag.childNodes.length; i++)
   {
      tags = tag.childNodes;
      if (tags[i].childNodes.length > 1)
      {
        if (tags[i].childNodes[1].nodeName.toLowerCase() == "ul" )
        {
           tags[i].childNodes[1].style.visibility = "hidden";
        }
      }
   }
  }	
}

function openQuad(){
  this.style.backgroundImage    = "url(immagini/quad.gif)";
  this.style.backgroundPosition = "left 11px";
  this.style.backgroundRepeat   = "no-repeat";
}

function closeQuad(){
  closeAllMenu();
  this.style.backgroundImage  = "";
}

function fnLoad()
{
  try
  {
    var control = arrJsonData;
  }
  catch(e)
  {
    var control = null;
  }

  if ( control != null )
  {
    var opt = {"arrJsonData":arrJsonData,"automatic":false,"automaticTime":15000};
    var eXg = new Gallery ( "ciao", opt );
    eXg.play();
  }
}

function swap(id, id2)
{
  var tmp = arrJsonData[id];
  arrJsonData[id] = arrJsonData[id2];
  arrJsonData[id2]=tmp;
}
