window.addEvent('domready',initPage);

function initPage(event) {
  /****************************************************************************\

    Initializing the page

    The next steps has to be performed to set-up the page

    - SlimBox
    - Menu
    - Screen maximization
    - Form validation
    - Table striping
    - Table highlighting
    - Table sorting
  
  \****************************************************************************/
  var links = $$("a").filter(function(el) {
    return el.rel && el.rel.test(/^lightbox/i);
  });
  $$(links).slimbox({
    loop:             true, 
    counterText:      'Afbeelding {x} van {y}', 
    resizeTransition: Fx.Transitions.Bounce.easeOut}, 
    null, 
    function(el) {
      return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
    }
  );
  
  
  /****************************************************************************\

    Form validation

    Add form validation to each form which has to be validated.
    Also setting custom options for InterShift Applications
  
  \****************************************************************************/
  $$('.validate').each(function(el) {
    var opts = { 
       img            : doc_base +'/base/img/icon/error.png',
       msgContainerTag : 'span',
       styleNeutral:  { 'border': '1px solid #aab' , 'background' : '#fff' , 'color': '#000'},
       styleBad:      { 'border': '1px solid #f00' , 'background' : '#fee' , 'color': '#f00'},
       required:      { msg : 'Verplicht' },
       req:           { msg : 'Verplicht' },
       alpha:         { msg: 'alleen letters' },
       alphanum:      { msg: 'alleen alfanumeriek' },
       num:           { msg: 'alleen cijfers' },
       real:          { msg: 'alleen (decimale) getallen'},
       reqClass:      'req',
       reqText:       '*',
       reqPos:        'right'
     };
    new fValidatorOwn(el,opts);
  });
  
  
  /****************************************************************************\

    Table striping

    Create striping for each zebra-table
    NOTE: You don't have to add striping to tables which are sortable
  
  \****************************************************************************/
  $$('.zebra tbody tr').each(function(el, i) {
    el.addClass((i % 2) ? 'even' : 'odd');
  });


  /****************************************************************************\

    Table highlighting

    Create highlighting on tables at mouseover
  
  \****************************************************************************/
  $$('table.highlight').each(function(el,i) {
    new TableHighlight(el);
  });

  /****************************************************************************\

    Table sorting

    Bind table sorting functionality to defined tables.
  
  \****************************************************************************/
  $$('.sortable').each(function(el) {
    new SortingTable(el,{zebra: true});
  });  
}