function initICIT()
{
  //showTooltip();
}
window.onload = function () {
  LoadStyle();
  buildSubMenus ();  
  buildToolTips ();
  rotateBanners();
}


function buildToolTips () {
  if (tooltipTheWords != null) {
    tooltipWords = new TooltipWords(tooltipTheWords, 'content');  
  }
}

function rotateBanners () {  
  if ($$('.banner_block')) {
    
    // each li if empty, kill it
    $$( '.banner_block ul' ).forEach( function( el ) {
      new ImageSlides( el, (4000) );
    }.bind(this) );    
  }
}

firstElm = null;
function buildSubMenus ()
{
  l = document.getElementById ( 'tabMenu' ).getElementsByTagName ( 'a' );
  for ( a = 0; a < l.length; a ++ )
  {
    l [ a ].onmouseover = function () {
      clearTimeout ( activeTimer );
      return displaySubMenu ( this );
    };
    l [ a ].onmouseout = function () {
      activeTimer = setTimeout ( 'displaySubMenuTimeout ( );', activeTimeout );
      return false;
    };

    if ( l [ a ].className == 'active' )
    {
      id = 'subMenu_' + l [ a ].id.substring ( 9, l [ a ].id.length );

      if ( e = document.getElementById ( id ) )
        activeElm = firstElm = e;
    }
  }

  document.getElementById ( 'mainNav' ).onmouseover = function () {
    clearTimeout ( activeTimer );
  }
  document.getElementById ( 'mainNav' ).onmouseout = function () {
    activeTimer = setTimeout ( 'displaySubMenuTimeout ( );', activeTimeout );
  }
}

activeElm = null;
activeTimer = null;
activeTimeout = 1400;

function displaySubMenu ( elm )
{
  id = 'subMenu_' + elm.id.substring ( 9, elm.id.length );

  if ( e = document.getElementById ( id ) )
  {
    if ( activeElm != null && activeElm != e )
      activeElm.style [ 'display' ] = 'none';

    e.style [ 'display' ] = 'block';

    activeElm = e;
  }

  return false;
}

function displaySubMenuTimeout ( )
{
  if ( activeElm != null && firstElm != activeElm )
    activeElm.style [ 'display' ] = 'none';

  if ( firstElm != null && firstElm != activeElm )
  {
    firstElm.style [ 'display' ] = 'block';
    activeElm = firstElm;
  }

  return false;
}
/*
//Tooltip
function showLibraryInfo(elm, info) {
  lDiv = document.getElementById('libraryDiv');

  wt = 240;
  w = 7 * info.length + 6;
  h = 140;

  if (info.length > 0) {
    lDiv.style.height = h + "px";
    leftOff = -40;
    topOff = -145;
    tElm = elm;
    while (tElm = tElm.offsetParent) {
      topOff += tElm.offsetTop;
      leftOff += tElm.offsetLeft;
      tElm2 = tElm;
    }
    if (leftOff > tElm2.clientWidth / 2) {
      leftOff = leftOff - lDiv.clientWidth;
    } else {
      leftOff = leftOff + elm.clientWidth;
    }
    topOff = $(elm).getPosition().y -145;
    leftOff = $(elm).getPosition().x;
    cntDiv = document.getElementById('infoContent');

    //elm.style.backgroundColor = '#dceeff';
    cntDiv.innerHTML = '<p style="margin: 0px;">' + info + '</p>';
    lDiv.style.left = leftOff + "px";
    lDiv.style.top = ( topOff + elm.clientHeight ) + "px";
    lDiv.style.visibility = "visible";
    lDiv.style.display = "block";
  } else {
    lDiv.style.visibility = "hidden";
    lDiv.style.display = "none";
    //elm.style.backgroundColor = '';
  }
}



function showTooltip()
{
  spans = document.getElementsByTagName ( 'span' );
  for ( a = 0; a < spans.length; a ++ )
  {
    if ( spans [ a ].className == 'tooltip' && spans [ a ].title.length > 0 )
    {
      while ( ( b = spans [ a ].title.indexOf ( '  ' ) ) != -1 )
        spans [ a ].title = spans [ a ].title.substring ( 0, b ) + '<br />' + spans [ a ].title.substring ( b + 2, spans [ a ].title.length );

      eval ( 'spans [ a ].onmouseover = function () {showLibraryInfo ( this, \'' + spans [ a ].title + '\' );}' );
      spans [ a ].onmouseout = function () {
        setTimeout("showLibraryInfo ( this, '' );",1000);
      }
      spans [ a ].title = '';
    }
  }
}
*/

/**
 * Generates rotating banners from UL lists (right-side vertical bar)
 *
 * @author Damien Overeem <damien@icit.nl>
 *
 */
var ImageSlides = new Class({
  initialize: function(ul, slideTime) {
    
    this.slideTime    = slideTime

    this.mainUl       = $(ul);
    this.listItems    = new Array();
    
    var elements    = this.mainUl.getElements('li');
    var listItemCounter = 0;
    for ( var i=0; i < elements.length; i++ ) {
      if (decodeURI(elements[i].getChildren('a')[0].getChildren('img')[0].src) != 'http://www.icit.nl/<<VALUE>>') { // ! empty link
        this.listItems[listItemCounter++] = elements[i];
      } else {
        elements[i].setStyle('display', 'none');
      }
    }    
    
    this.slidesCount  = this.listItems.length;
    this.currentSlide = 0;

    this.listItems.forEach(function(el, i) {
      if (i > 0)
        el.setStyle('display', 'none');
    });

    this.nextSlide.delay(this.slideTime, this);
  },

  nextSlide: function() {
      if (this.listItems[this.currentSlide]) {
        this.listItems[this.currentSlide].setStyle('display', 'none')
      }
      this.currentSlide++

      if (this.currentSlide >= this.slidesCount) {
        this.currentSlide = 0;
      }
      this.listItems[this.currentSlide].setStyle('display', 'block')
      this.nextSlide.delay(this.slideTime, this);
  }
});