﻿/*****************Dropdown Menu********************/
var timeout = 200;
var closetimer = 0;
var ddmenuitem = 0;
var list = null;
var size = 0;

function subMenuItem_onMouseOver(id, childCount, rootCount) {
  if (document.getElementById('slider')!=null){ 
    $('#slider').data('nivo:vars').stop = true;
    document.getElementById('menu').style.zIndex = '1000';
  }
  
  closeAllItems(rootCount);
  mcancelclosetime();
  
  list = document.getElementById(id);
  size = 0;
  
  if (childCount > 0) {
    size = ((childCount * 28) + 45);
  }
  subMenuOpen(size);
}

function subMenuItem_onMouseOut(control) {
  if (document.getElementById('slider')!=null) {
    $('#slider').data('nivo:vars').stop = false;  
  }
  list = control;
  startCloseTimer();
}

function closeAllItems(count) {
  for (var i = 0; i <= count; i++) {
    var item = document.getElementById('item_' + i);
    subMenuClose(item,0);
  }
}

function subMenuOpen() {
  // close old layer
  if (list!=null && list.style.height != size + 'px') {
    list.style.display = '';
    //list.style.height = size + 'px'
    $(list).animate ( { height: size }, 200, function() { } );
  }
}

//Close submenu
function subMenuClose(item, delay) {
  if (item) {
    $(item).animate ( { height: 0 }, delay, function() { item.style.display = 'none'; } );
  }
}

//Start timer
function startCloseTimer() {
  closetimer = window.setTimeout(function(){subMenuClose(list,200)}, timeout);
                                           }
                                 // cancel close timer
                                 function mcancelclosetime() {                            
                                   if (closetimer) {
                                     window.clearTimeout(closetimer);
                                     closetimer = null;
                                   }
                                 }
                                 
                                 /*********************************************/                                   
                                 
                                 function subMenuExpander(list, count, src) {
    size = (count * 28);
  if (list.style.height == '0px' || list.style.height == '') {
    list.style.display = '';
    $(list).animate ( { height: size }, 200, function () { } );
    
  } else {
    $(list).animate ( { height: '0px' }, 200, function () { list.style.display = 'none'; } );
  }
}

