/**
 * Bestandsnaam:         script.js
 * Gemaakt door:         Erwin Geerdink
 * Contact:              erwingeerdink@gmail.com
 * Gemaakt op:           10.03.2009 (dd.mm.jjjj)
 * Laatst gewijzigd:     07.07.2011 (dd.mm.jjjj)
 *
 * Dit bestand:
 * - Bevat alle JavaScript-functies voor de gehele website
 *
 * Externe variabelen:
 * - jQuery
 * - FancyBox
 * - ...
 *
 * Bijzonderheden:
 * - ...
 */


$(document).ready(function(){
     
     if(document.getElementById('home_galerij'))
     {
          init_home_galerij();
     }
     
     
     // FancyBox
     $("a.FancyBox").fancybox();
     
     
     // Preloader instellen als er op een menu-link wordt geklikt
     $("div.menu_top a, div.menu_links a").bind('click', function(event)
     {
          $('#preloader').css('visibility', 'visible');
     });
     
});


function init_home_galerij()
{
     var aantal_fotos = 10;
     var foto = new Array();
     var home_galerij = document.getElementById('home_galerij');
     
     
     // Maak eerst het element leeg
     while(home_galerij.hasChildNodes())
     {
          home_galerij.removeChild(home_galerij.firstChild);
     }
     
     
     // Toon willekeurige foto's
     while(foto.length < 3)
     {
          var l = foto.length;
          var nr = Math.ceil( Math.random() * aantal_fotos );    // getal tussen 1 en aantal_fotos, dus niet 0!
          
          var uniek = true;
          for(var j = 0; j < l; j++)
          {
               if(nr == foto[j])
               {
                    uniek = false;
                    break;
               }
          }
          
          
          // Toon alleen unieke foto's
          if(uniek)
          {
               foto[l] = nr;
               l++;
               
               
               var img = document.createElement('img');
               img.setAttribute('src', 'afbeeldingen/home/' + nr + '-klein.jpg');
               img.setAttribute('alt', 'Foto #' + l);
               img.setAttribute('id', 'home_galerij_' + l);
               img.setAttribute("class", 'foto');
               img.setAttribute("className", 'foto');    // IE
               
               var a = document.createElement('a');
               a.setAttribute('href', 'afbeeldingen/home/' + nr + '-groot.jpg');
               a.setAttribute('rel', 'slideshow');
               a.setAttribute('title', 'Foto #' + l);
               a.setAttribute("class", 'FancyBox');
               a.setAttribute("className", 'FancyBox');    // IE
               
               a.appendChild(img);
               
               home_galerij.appendChild(a);
               
          } // Einde if()
          
     } // Einde while()
     
} // Einde init_home_galerij()
