var IC_Photo_DarkLayer = null;

var IC_Photo_Popup_referer = null;
var IC_SlideShow = null;
var IC_Body = null;
var IC_Html = null;

var IC_Photo_Settings = {
  MarginToBorders: 10,
  Title: 'Klik hier om te sluiten',
  UseAltTag: true,
  UseDarkLayer: true,
  Padding: 15,
  Index: 0,
  Loop: false,
  Looper:null
};

function IC_InitLayers(){
  IC_Body = document.getElementsByTagName( 'body' ).item( 0 );
  IC_Html = document.getElementsByTagName( 'html' ).item( 0 );

  if ( IC_Photo_Settings.UseDarkLayer ){
    if ( ! IC_Photo_DarkLayer ){
      var Body = document.getElementsByTagName( 'body' ).item( 0 );
      IC_Photo_DarkLayer = document.createElement( 'div' );
      IC_Photo_DarkLayer.id = 'IC_Photo_DarkLayer';
      IC_Body.appendChild( IC_Photo_DarkLayer );
    } 
  }
}

function IC_DarkLayerUp(){
  if ( IC_Photo_Settings.UseDarkLayer ){
    IC_Photo_DarkLayer.style.display = 'block';

    var DLHeight = Math.max( IC_Body.offsetHeight, IC_Html.offsetHeight );
    var DLWidth = Math.max( IC_Body.offsetWidth, IC_Html.offsetWidth );
    IC_Photo_DarkLayer.style.height = DLHeight + 'px';
    IC_Photo_DarkLayer.style.width = DLWidth + 'px';
    window.onresize = IC_DarkLayerUp;
  }
}

function RemoveDarkLayer(){
  if ( IC_Photo_Settings.UseDarkLayer ){
    if ( IC_Photo_DarkLayer ){
      IC_Photo_DarkLayer.style.display = 'none';
    }
  }
}

var SlideShow_Config = {
  CurrentWindow : null,
  Picture: null,
  Controls: null,
  Titel: null,
  Title: 'Klik hier om te sluiten', 
  Index: 0,
  Loop: false,
  Afbeeldingen: null,
  Afbeelding: null,
  Teksten: null,
  Tekst: null
};

function OpenSlideShow( BaseElement, Titel, Index, Loop ){
  SlideShow_Config.Afbeeldingen = Afbeeldingen;
  SlideShow_Config.Teksten = Teksten;
  Afbeelding = SlideShow_Config.Afbeeldingen[ Index ];
  Tekst = SlideShow_Config.Teksten[ Index ];
  if ( Afbeelding ){
    SlideShow_Config.Index = Index;
    SlideShow_Config.Loop = Loop && SlideShow_Config.Afbeeldingen.length > 0;
    SlideShow_Config.Title = Titel;

    if ( SlideShow_Config.CurrentWindow == null ){
      SlideShow_Config.CurrentWindow = new IC_Window( {Size:{Width:776,Height:200},Position:{Left:'htmlcenter',Top:'htmlcenter'}}, '' );
   
      SlideShow_Config.CurrentWindow.Element.onkeyup = IC_SlideShow_Popup_Key_Press;

      SlideShow_Config.Picture1 = document.createElement( 'div' );
      SlideShow_Config.Picture1.className = 'IC_SlideShow_Popup_Picture';
      SlideShow_Config.Picture1.onclick = IC_SlideShow_Close;

      SlideShow_Config.CurrentWindow.Element.appendChild( SlideShow_Config.Picture1 );
      IC_SlideShow_SetFading( SlideShow_Config.Picture1, 0 );


      SlideShow_Config.Picture2 = document.createElement( 'div' );
      SlideShow_Config.Picture2.className = 'IC_SlideShow_Popup_Picture';
      SlideShow_Config.Picture2.onclick = IC_SlideShow_Close;

      SlideShow_Config.Focus = SlideShow_Config.Picture1;
      SlideShow_Config.DeFocus = SlideShow_Config.Picture2;

      SlideShow_Config.CurrentWindow.Element.appendChild( SlideShow_Config.Picture2 );

      IC_SlideShow_SetFading( SlideShow_Config.Picture2, 100 );
 
      SlideShow_Config.Controls = document.createElement( 'div' );
      SlideShow_Config.Controls.onkeyup = IC_SlideShow_Popup_Key_Press;

      SlideShow_Config.Controls.id = 'IC_SlideShow_Popup_Controls';

      SlideShow_Config.Controls.NavPrev = document.createElement( 'a' );
      SlideShow_Config.Controls.NavPrev.className = 'Navigation';
      SlideShow_Config.Controls.NavPrev.id = 'NavPrev';
      SlideShow_Config.Controls.NavPrev.href = '#';
      SlideShow_Config.Controls.NavPrev.onclick = IC_SlideShow_GoPrev;
      SlideShow_Config.Controls.NavPrev.innerHTML = '&lt;&lt;';
      SlideShow_Config.Controls.appendChild( SlideShow_Config.Controls.NavPrev );

      SlideShow_Config.Controls.NavNext = document.createElement( 'a' );
      SlideShow_Config.Controls.NavNext.className = 'Navigation';
      SlideShow_Config.Controls.NavNext.id = 'NavNext';
      SlideShow_Config.Controls.NavNext.href = '#';
      SlideShow_Config.Controls.NavNext.onclick = IC_SlideShow_GoNext;
      SlideShow_Config.Controls.NavNext.innerHTML = '&gt;&gt;';
      SlideShow_Config.Controls.appendChild( SlideShow_Config.Controls.NavNext );

      SlideShow_Config.Controls.Close = document.createElement( 'a' );
      SlideShow_Config.Controls.Close.className = 'Close';
      SlideShow_Config.Controls.Close.href = '#';
      SlideShow_Config.Controls.Close.onclick = IC_SlideShow_Close;
      SlideShow_Config.Controls.Close.appendChild( document.createTextNode( 'Close' ) );
      SlideShow_Config.Controls.appendChild( SlideShow_Config.Controls.Close );

      SlideShow_Config.Controls.DiaWeergave = document.createElement( 'div' );
      SlideShow_Config.Controls.DiaWeergave.id = 'IC_SlideShow_Popup_DiaWeergave';
      SlideShow_Config.Controls.appendChild( SlideShow_Config.Controls.DiaWeergave );

      SlideShow_Config.CurrentWindow.Element.appendChild( SlideShow_Config.Controls );          

      SlideShow_Config.Titel = document.createElement( 'div' );
      SlideShow_Config.Titel.id = 'IC_SlideShow_Popup_Titel';
      SlideShow_Config.Titel.innerHTML = Titel;
      SlideShow_Config.CurrentWindow.Element.appendChild( SlideShow_Config.Titel );

      BaseElement.onkeyup = IC_SlideShow_Popup_Key_Press;
   } else {
     SlideShow_Config.Focus = SlideShow_Config.Focus != SlideShow_Config.Picture1 ? SlideShow_Config.Picture1 : SlideShow_Config.Picture2;
     SlideShow_Config.DeFocus = SlideShow_Config.Focus != SlideShow_Config.Picture1 ? SlideShow_Config.Picture1 : SlideShow_Config.Picture2;
     IC_SlideShow_SetFading( SlideShow_Config.Focus, 0 );
     IC_SlideShow_SetFading( SlideShow_Config.DeFocus, 100 );
   }
   SlideShow_Config.Focus.style.zIndex = 100;
   SlideShow_Config.DeFocus.style.zIndex = 50;

   SlideShow_Config.CurrentWindow.SetVisibility( true );

   SlideShow_Config.Focus.style.backgroundImage = 'url(' + AfbeeldingenPath + Afbeelding + ')';
   SlideShow_Config.Titel.innerHTML = Titel;

   IC_SlideShow_Step_Start();

   SlideShow_Config.CurrentWindow.SetSize( 
      {
        Width: 776, 
        Height: 526 + SlideShow_Config.Controls.offsetHeight + SlideShow_Config.Titel.offsetHeight
      }
    );
    SlideShow_Config.CurrentWindow.SetPosition( {Left:'htmlcenter',Top:'htmlcenter'} );

    if ( Loop ){
      IC_SlideShow_DiaAan();
    }

    IC_SlideShow_UpdateDiaString();

    return false;
  }
  return true;
} 

function IC_SlideShow_Step_Start(){
  IC_SlideShow_Step_Stop();
  SlideShow_Config.Runner = setInterval( 'IC_SlideShow_Step()', 50 );
}

function IC_SlideShow_Step_Stop(){
  SlideShow_Config.Runner = clearInterval( SlideShow_Config.Runner );
}

function IC_SlideShow_Step(){
  if ( SlideShow_Config.Focus.Fading < 100 ){
    IC_SlideShow_SetFading( SlideShow_Config.Focus, SlideShow_Config.Focus.Fading + 10 );
  }
  if ( SlideShow_Config.DeFocus.Fading > 0 ){
    IC_SlideShow_SetFading( SlideShow_Config.DeFocus, SlideShow_Config.DeFocus.Fading - 10 );
  }
  if ( SlideShow_Config.Focus.Fading == 100 || SlideShow_Config.DeFocus.Fading == 0 ){
    IC_SlideShow_Step_Stop();
  }
}

function IC_SlideShow_Popup_Key_Press( evt ){
  e = evt ? evt : event;
  element = getTargetElement( e );
  switch( e.keyCode ){
    case 39 : {
      IC_SlideShow_GoNext();
    } break;
    case 37 : {
      IC_SlideShow_GoPrev();
    } break;
  }
}

function getTargetElement(evt) {
    var elem
    if (evt.target) {
        elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
    }
    else {
        elem = evt.srcElement;
    }
    return elem;
}

function IC_SlideShow_UpdateDiaString(  ){
   SlideShow_Config.Controls.DiaWeergave.innerHTML = 'Diaweergave: <a href="#" onclick="return IC_SlideShow_DiaAan()" class="' + ( SlideShow_Config.Loop ? 'Active' : 'InActive' ) + '">aan</a> / <a href="#" onclick="return IC_SlideShow_DiaUit()" class="' + ( SlideShow_Config.Loop ? 'InActive' : 'Active' ) + '">uit</a>';
}

function IC_SlideShow_DiaAan(){
  SlideShow_Config.Loop = true;
  clearInterval( SlideShow_Config.Looper );
  SlideShow_Config.Looper = setInterval( 'IC_SlideShow_GoNext( true )', 5 * 1000 );
  IC_SlideShow_UpdateDiaString();
  return false;
}

function IC_SlideShow_DiaUit(){
  SlideShow_Config.Loop = false;
  clearInterval( SlideShow_Config.Looper );
  IC_SlideShow_UpdateDiaString();
  return false;
}

function IC_SlideShow_GoNext( Auto ){
  if ( ! Auto ){
    IC_SlideShow_DiaUit();
  }

  var Index = SlideShow_Config.Index < SlideShow_Config.Afbeeldingen.length - 1 ? SlideShow_Config.Index + 1 : 0;

  OpenSlideShow( null, SlideShow_Config.Teksten[ Index ], SlideShow_Config.Index < SlideShow_Config.Afbeeldingen.length - 1 ? SlideShow_Config.Index + 1 : 0, SlideShow_Config.Loop );
  return false;
}

function IC_SlideShow_GoPrev( Auto ){
  if ( ! Auto ){
    IC_SlideShow_DiaUit();
  }
  
  var Index = SlideShow_Config.Index > 0 ? SlideShow_Config.Index - 1 : SlideShow_Config.Afbeeldingen.length - 1;

  OpenSlideShow( null, SlideShow_Config.Teksten[ Index ], SlideShow_Config.Index > 0 ? SlideShow_Config.Index - 1 : SlideShow_Config.Afbeeldingen.length - 1, SlideShow_Config.Loop );
  return false;
}

function IC_SlideShow_Close(){
  IC_SlideShow_DiaUit();
 
  if ( SlideShow_Config.CurrentWindow ){ 
    SlideShow_Config.CurrentWindow.SetVisibility( false );
  }

  return false;
}

function IC_SlideShow_SetFading( Elem, Value )  {
  if ( Elem ){
    var Value = Value >= 100 ? 100 : Value;

    if ( Elem.filters && Elem.filters.alpha )
      Elem.filters.alpha.opacity = Value;
    Elem.style.MozOpacity = Value / 100;
    Elem.style.opacity = Value / 100;
    Elem.Fading = Value;
  }
}

function IC_Photo_Popup( Link, URL, Width, Height, Alt ){
  IC_InitLayers();

  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;
    }
    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;
    Pos.left += element.offsetLeft;

    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;
}

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 = Link;
    for( i=0; i<Link.childNodes.length; i++ ){
      if ( Link.childNodes[ i ].tagName && 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 OpenReferentieItem( id, GroteFoto, Adres, A_Element ){
  var Teaser = document.getElementById( 'ReferentieItem' + id );
  if ( Teaser ){
    A_Element.className = "Link Up";

    var Contents = '';
    var Wnd = new IC_Window( {Size:{Width:600,Height:476},Position:{Left:'htmlcenter',Top:'htmlcenter'}}, Contents );

    var Content = document.createElement( 'div' ); 
    Content.id = 'Referenties_Aankoop';
    if ( GroteFoto ){
      var Picture_div = document.createElement( 'div' );
      Picture_div.id = 'RA_Picture';
      Picture_div.style.backgroundImage = 'url(' + GroteFoto + ')';
      Content.appendChild( Picture_div );
    }

    var Adres_div = document.createElement( 'div' );
    Adres_div.id = 'RA_Adres';
    Adres_div.appendChild( document.createTextNode( Adres ) );
    Content.appendChild( Adres_div );

    var Close_link = document.createElement( 'a' );
    Close_link.className = 'RA_Close';
    Close_link.href = '#';
    Close_link.onclick = function(){
      A_Element.className = "Link";
      Wnd.SetVisibility( false );
      return false;
    }
    Close_link.appendChild( document.createTextNode( 'Close' ) );
    Content.appendChild( Close_link );
 
    var TeaserDiv = document.createElement( 'div' );
    TeaserDiv.className = 'RA_Teaser';
    TeaserDiv.innerHTML = document.getElementById( 'ReferentieItem' + id ).innerHTML;
    Content.appendChild( TeaserDiv );

    Wnd.Element.appendChild( Content );

    Wnd.SetSize( { Width: 600, Height: 476 + TeaserDiv.offsetHeight } );
    Wnd.SetPosition( {Left:'htmlcenter',Top:'htmlcenter'} );

    Wnd.SetVisibilityLayer( true );
    Wnd.SetVisibility( true );
  }
}

var IC_Window_Config = {

  Objects : {
    IC_Body : null,
    IC_DarkLayer : null
  },

  Settings : {
    MarginToBorders: 10,
    UseDarkLayer: true
  }

};

function IC_Window( Settings, Contents ){
  this.Settings = Settings;

  this.InitLayers();

  this.Element = document.createElement( 'div' );

  if ( this.Element ){
    this.SetSize();
    this.SetPosition();
    this.Element.className = 'ICWindow';
    IC_Window_Config.Objects.IC_Body.appendChild( this.Element );
  }
}

IC_Window.prototype = { 

  InitLayers : function() {
 
    if ( ! IC_Window_Config.Objects.IC_Body ){
      IC_Window_Config.Objects.IC_Body = document.getElementsByTagName( 'body' ).item( 0 );
    }

    if ( IC_Window_Config.Objects.IC_Body && IC_Window_Config.Settings.UseDarkLayer ){
      IC_Window_Config.Objects.IC_DarkLayer = document.createElement( 'div' );
      IC_Window_Config.Objects.IC_DarkLayer.id = 'IC_DarkLayer';
      var self = this;
      IC_Window_Config.Objects.IC_DarkLayer.onclick = function(){
        self.SetVisibility( false );
      }
      IC_Window_Config.Objects.IC_Body.appendChild( IC_Window_Config.Objects.IC_DarkLayer );
    }

  },

  SetVisibilityLayer : function( Show ){
    if ( IC_Window_Config.Settings.UseDarkLayer && IC_Window_Config.Objects.IC_DarkLayer ){
      var WindowSize = this.getWindowSize();

      if ( Show ){
        IC_Window_Config.Objects.IC_DarkLayer.style.display = 'block';

        var DLHeight = Math.max( IC_Window_Config.Objects.IC_Body.offsetHeight, WindowSize.Height );
        var DLWidth = Math.max( IC_Window_Config.Objects.IC_Body.offsetWidth );
        IC_Window_Config.Objects.IC_DarkLayer.style.height = DLHeight + 'px';
        IC_Window_Config.Objects.IC_DarkLayer.style.width = DLWidth + 'px';
      } else {
        IC_Window_Config.Objects.IC_DarkLayer.style.display = 'none';
      }
    }
  },

  SetSize : function( Size ){
    var Size = Size ? Size : this.Settings.Size;
    if ( ! Size ) {
      Size = {Width: 200, Height: 200};
      this.Settings.Size = Size;
    }
    this.Element.style.width = Size.Width + 'px';
    this.Element.style.height = Size.Height + 'px';
    this.Settings.Size = Size;
  },

  SetPosition : function( Position ){
    var WindowSize = this.getWindowSize();

    var Position = Position  ? Position : this.Settings.Position;
    if ( ! Position ){
      Position = {Left:'center',Top:'center'};
      if ( this.Settings.AnkerFrom ){
        var AnkerPosition = getPositionFrom( this.Settings.AnkerFrom );
        Position.Left = Math.floor( ( AnkerPosition.left + this.Settings.AnkerFrom.offsetWidth / 2 ) - this.Settings.Size.Width / 2 );
        Position.Top = Math.floor( ( AnkerPosition.top + this.Settings.AnkerFrom.offsetHeight / 2 ) - this.Settings.Size.Height / 2 );
      }
      this.Settings.Position = Position;
    }

    if ( Position.Left == 'htmlcenter' || Position.Top == 'htmlcenter' ){
      ScrollRate = this.getScrollPosition();
    }

    if ( isNaN( Position.Left ) ) {
      if ( Position.Left == 'center' ){
        this.Element.style.left = '50%';  
        this.Element.style.marginLeft = '-' + Math.floor( this.Settings.Size.Width / 2 ) + 'px';
      } else { 
        if ( Position.Left == 'htmlcenter' ){
          Position.Left = ScrollRate.Left + Math.floor( WindowSize.Width / 2 - this.Settings.Size.Width / 2 );
          this.Element.style.left = Position.Left + 'px';
        } else {
          this.Element.style.left = Position.Left;
        }
      }      
    } else { 
      if ( Position.Left == 'center' ) {
        Position.Left = Math.floor( Math.max( IC_Window_Config.Objects.IC_Body.offsetWidth, WindowSize.Width ) / 2 - this.Settings.Size.Width / 2 );
      }
      if ( Position.Left <= IC_Photo_Settings.MarginToBorders ){
        Position.Left = IC_Photo_Settings.MarginToBorders;
      }
      this.Element.style.left = Position.Top + 'px';
    }

    if ( isNaN( Position.Top ) ) {  
      if ( Position.Top == 'center' ){
        this.Element.style.top = '50%';
        this.Element.style.marginTop = '-' + Math.floor( this.Settings.Size.Height / 2 ) + 'px';
      } else {
        if ( Position.Top == 'htmlcenter' ){
          Position.Top = ScrollRate.Top + Math.floor( WindowSize.Height / 2 - this.Settings.Size.Height / 2 );
          this.Element.style.top = Position.Top + 'px';
        } else {
          this.Element.style.top = Position.Top;
        }
      }
    } else { 
      if ( Position.Top == 'center' ) {
        Position.Top = Math.floor( Math.max( IC_Window_Config.Objects.IC_Body.offsetHeight, WindowSize.Height ) / 2 - this.Settings.Size.Height / 2 );
      }
      if ( Position.Top <= IC_Photo_Settings.MarginToBorders ){
        Position.Top = IC_Photo_Settings.MarginToBorders;
      }
      this.Element.style.top = Position.Top + 'px';
    }
  },

  SetVisibility : function( Show ) {
    if ( Show ){
      this.Element.style.display = 'block';
    } else {
      this.Element.style.display = 'none';
    }
    this.SetVisibilityLayer( Show );
  },

  getScrollPosition : function( ){
    var Position = { Left:0, Top:0 };
    Position.Left = document.body.scrollLeft;
    Position.Top  = document.body.scrollTop;
    if ( Position.Left == 0 ){
      if ( window.pageXOffset ){
        Position.Left = window.pageXOffset;
      } else {
        Position.Left = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
      }
    }
    if ( Position.Top == 0 ){
      if ( window.pageYOffset ){
        Position.Top = window.pageYOffset;
      } else {
        Position.Top = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
      }
    }
    return Position;
  },

  getWindowSize : function (){
    var viewportwidth;
    var viewportheight;
    if (typeof window.innerWidth != 'undefined')
    {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    } else {
      if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
      } else {
        viewportwidth = IC_Window_Config.Objects.IC_Body.clientWidth,
        viewportheight = IC_Window_Config.Objects.IC_Body.clientHeight
      }
    }
    return { Width:viewportwidth, Height:viewportheight };
  },

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

    while ( element.offsetParent ) {

      Pos.top += element.offsetTop;
      Pos.left += element.offsetLeft;

      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 ){
      Pos.top += IC_Window_Config.Objects.IC_Body.offsetTop;
      Pos.left += IC_Window_Config.Objects.IC_Body.offsetLeft;
    }
 
    return Pos;
  }

}
