CurrentOpen = null;
LastOpened = null;
timeouter = null;
timeouttime = 3000;

function OpenBehindMe( element, menuitemID, menuitem ){

  elem = document.getElementById( 'SubMenu' + menuitemID );
  if ( elem ){
    if ( CurrentOpen ){
      CurrentOpen.style.visibility = 'hidden';
    }
    CurrentMenuitem = menuitem;
    elem.style.visibility = 'visible';
    elem.style.left = element.offsetLeft + 'px';
    CurrentOpen = elem;
    KeepOpen();
  }
}

function KeepOpen(  ){
  LastOpened = new Date();
  if ( timeouter ){
    clearTimeout( timeouter );
  }
  timeouter = setTimeout( "HideMenu()", timeouttime );
}

function HideMenu( ){
  if ( CurrentOpen && LastOpened){
    time = new Date() - LastOpened;
    if ( time >= timeouttime ){
      CurrentOpen.style.visibility = 'hidden';
      CurrentOpen = null;
    } else {
      setTimeout( "HideMenu()", time );
    }
  }
}


function ShowFlash( url, width, height ){
  document.write( '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">' );
  document.write( '<param name="allowScriptAccess" value="sameDomain" />' );
  document.write( '<param name="movie" value="' + url + '">' );
  document.write( '<param name="quality" value="high">' );
  document.write( '<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>' );
  document.write( '</object>');
}

var IC_Photo_DarkLayer = null;
var IC_Photo_Popup_referer = null;

var IC_Photo_Settings = {
  MarginToBorders: 10,
  Title: 'Klik hier om te sluiten',
  CloseTitle: 'x',
  UseAltTag: true,
  UseCloseTag: true,
  UseDarkLayer: true,
  Padding: 15
};

function IC_Photo_Popup( Link, URL, Width, Height, Alt ){
  var Body = document.getElementsByTagName( 'body' ).item( 0 );
  var Html = document.getElementsByTagName( 'html' ).item( 0 );

  if ( ! IC_Photo_DarkLayer && IC_Photo_Settings.UseDarkLayer ){
    IC_Photo_DarkLayer = document.createElement( 'div' );
    IC_Photo_DarkLayer.id = 'IC_Photo_DarkLayer';
    Body.appendChild( IC_Photo_DarkLayer );
  }

  if ( IC_Photo_Popup_referer == null ){
    IC_Photo_Popup_referer = document.createElement( 'a' );
    IC_Photo_Popup_referer.id = 'IC_Photo_Popup_Holder';
    IC_Photo_Popup_referer.onclick = IC_Photo_Popup_Close;
    IC_Photo_Popup_referer.href = '#';
    IC_Photo_Popup_referer.title = IC_Photo_Settings.Title;

    if ( IC_Photo_Settings.UseAltTag ){
      var AltTag = document.createElement( 'span' );
      AltTag.className = 'AltLabel';
      AltTag.appendChild( document.createTextNode( Alt ) );
      IC_Photo_Popup_referer.appendChild( AltTag );
      IC_Photo_Popup_referer.Label = AltTag;
    }

    if ( IC_Photo_Settings.UseCloseTag ){
      var ATag = document.createElement( 'a' );
      ATag.className = 'CloseButton';
      ATag.href = '#';
      ATag.appendChild( document.createTextNode( IC_Photo_Settings.CloseTitle ) );
      IC_Photo_Popup_referer.appendChild( ATag );
    }
    Body.appendChild( IC_Photo_Popup_referer );
  }
  if ( IC_Photo_Popup_referer != null ) {
    IC_Photo_Popup_referer.style.display = 'block';

    IC_Photo_Popup_referer.style.height = ( Height + IC_Photo_Settings.Padding * 2 ) + 'px';
    IC_Photo_Popup_referer.style.width = ( Width + 30 ) + 'px';

    LabelHeight = 0;

    if ( IC_Photo_Settings.UseAltTag ){
      IC_Photo_Popup_referer.Label.innerHTML = Alt;

      if ( Alt != '' ){
        LabelHeight = IC_Photo_Popup_referer.Label.offsetHeight;

        IC_Photo_Popup_referer.style.height = ( Height + LabelHeight + IC_Photo_Settings.Padding * 2 ) + 'px';
      }
    }

    IC_Photo_Popup_referer.style.backgroundPosition = 'center ' + ( IC_Photo_Settings.Padding + LabelHeight ) + 'px';

    IC_Photo_Popup_referer.style.backgroundImage = 'url(' + URL + ')';

    IC_Image = null;
    for( i=0; i<Link.childNodes.length; i++ ){
      if ( Link.childNodes[ i ].tagName.toUpperCase() == 'IMG' ){
        IC_Image = Link.childNodes[ i ];
      }
    }
    if ( IC_Image ){
      Position = getPositionFrom( IC_Image );

      Left = ( Position.left + IC_Image.offsetWidth / 2 ) - IC_Photo_Popup_referer.offsetWidth / 2;

      Left = Math.min( Left, Body.offsetWidth - IC_Photo_Popup_referer.offsetWidth - IC_Photo_Settings.MarginToBorders );
      Left = Math.max( Left, IC_Photo_Settings.MarginToBorders );

      Top = ( Position.top + IC_Image.offsetHeight / 2 ) - IC_Photo_Popup_referer.offsetHeight / 2;
      WindowMax = Math.max( Body.offsetHeight, Html.offsetHeight );
      Top = Math.min( Top, WindowMax - IC_Photo_Popup_referer.offsetHeight - IC_Photo_Settings.MarginToBorders );
      Top = Math.max( Top, IC_Photo_Settings.MarginToBorders );

      IC_Photo_Popup_referer.style.top = Top + 'px';
      IC_Photo_Popup_referer.style.left = Left + 'px';

      if ( IC_Photo_Settings.UseDarkLayer ){
        IC_Photo_DarkLayer.style.display = 'block';
        DLHeight = Math.max( Body.offsetHeight, Html.offsetHeight, Top + IC_Photo_Popup_referer.offsetHeight );

        IC_Photo_DarkLayer.style.height = DLHeight + 'px';

      }
    }
  }
}


function IC_Photo_Popup_Close(){
  if ( IC_Photo_Popup_referer != null ){
    IC_Photo_Popup_referer.style.display = 'none';
  }
  if ( IC_Photo_Settings.UseDarkLayer && IC_Photo_DarkLayer != null ){
    IC_Photo_DarkLayer.style.display = 'none';
  }
  return false;
}

function getPositionFrom(element) {
  var Pos = {top:0,left:0};
  var absoluteAncestor = false;

  while ( element.offsetParent ) {
    Pos.top += element.offsetTop - element.scrollTop;
    Pos.left += element.offsetLeft - element.scrollLeft;

    element = element.offsetParent;

    if ( element.nodeName.toLowerCase() != 'html' ) {
      if ( element.currentStyle ) {
        if (element.currentStyle[ 'position' ] == 'absolute')
          absoluteAncestor = true;
      } else {
        if ( window.getComputedStyle ){
          if ( document.defaultView.getComputedStyle(element,null).getPropertyValue( 'position' ) == 'absolute' ){
            absoluteAncestor = true;
          }
        }
      }
    }
  }

  if ( ! absoluteAncestor ){
    var Body = document.getElementsByTagName( 'BODY' ).item( 0 );
    Pos.top += Body.offsetTop;
    Pos.left += Body.offsetLeft;
  }

  return Pos;
}



CurrentMenuOpen = null;
function MenuOpenList( ID ) {
  Element = document.getElementById( ID );
  if ( Element ){

    if ( CurrentMenuOpen ){
      CurrentMenuOpen.style.display = 'none';
    }

    Element.style.display = 'block';
    CurrentMenuOpen = Element;
  }
}

var DarkLayer = null;
OpenPictureNext = null;
OpenPicturePrev = null;
function OpenAfbeelding( idx ){
  if ( idx != null){
    url = Images[ idx ];
  }
  if ( url ){
    bodys = document.getElementsByTagName( 'body' );
    body = bodys[ 0 ];
    phj = document.getElementById( 'PopupHolder' );

    phjFoto = document.getElementById( 'PopupFoto' );

    phjSluiten = document.getElementById( 'Sluiten' );

    pvol = document.getElementById( 'PopupVolgende' );
    pvor = document.getElementById( 'PopupVorige' );

    if ( body && phj && phjFoto && pvol && pvor && phjSluiten ){


      if ( ! DarkLayer ){

        DarkLayer = document.createElement( 'div' );
        DarkLayer.className = 'DarkLayer';
        DarkLayer.style.height = GetWindowHeight() + 'px';
      }

      body.appendChild( DarkLayer );
      phj.style.display = 'block';
      phjFoto.style.backgroundImage = 'url(' + url + ')';

      pvor.style.display = Images[ idx - 1 ] ? 'block' : 'none';
      pvol.style.display = Images[ idx + 1 ] ? 'block' : 'none';

      phjSluiten.href = '#foto' + idx;

      OpenPictureNext = idx + 1;
      OpenPicturePrev = idx - 1;
    }
  }
}

function ClosePicture () {
  bodys = document.getElementsByTagName( 'body' );
  body = bodys[ 0 ];
  body.removeChild( DarkLayer );
  phj = document.getElementById( 'PopupHolder' );
  if ( phj ){
    phj.style.display = 'none';
  }
}
function GetWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight + 1;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight + 2;
  }
  return myHeight;
}

