      var recsPage,page;
      var numPages = [];
      // set number of items per page
      recsPage=15;

      // calculate number of pages
      setPages = function(divid,dataSource){
      	
      	result = dataSource.length/recsPage;
      	result_round = Math.round(result);
      	if(result_round < result){
      		result_round++;
      	}
      	numPages[divid]=result_round;
      }

      // define createDivs function
      createDivs=function(divid){

        // create items containing <ul>
        var itemsUl=document.createElement('ul');
        itemsUl.id='list';

        // create paging link containing <div>
        var pagingDiv=document.createElement('div');
        pagingDiv.id='paging';
		
        // insert <div> elements into document structure
        document.getElementById(divid).appendChild(itemsUl);
        document.getElementById(divid).appendChild(pagingDiv);
        }          

        // define displayRecords function
        displayRecords=function(page,divid,dataSource,type,bewoner){
           var itemsUl=document.getElementById('list');
           if(!itemsUl){return;}
           var ul=document.createElement('ul');
           ul.id='list';
           if(!page){page=1;}

           // extract records from rows array
           for(var i=(page-1)*recsPage;i<((page-1)*recsPage)+recsPage;i++){
             if(dataSource[i] && dataSource[i]['id']){

               // insert records as paragraph elements 
               // <li><a href="#" class="link_iwatch"><span class="titel">Win een dvd van Ratatouille!</span></a></li>
               var li=document.createElement('li');
               var a=document.createElement('a');
               var span=document.createElement('span');
               span.appendChild(document.createTextNode(dataSource[i]['title']));
               span.setAttribute('className','titel');
               span.setAttribute('class','titel');
               
               if(type == 'news'){
               
               a.setAttribute('href','items/item_' + dataSource[i]['id'] + '.html?page=' + page + '&type=' + type);
               a.setAttribute('className','link');
               a.setAttribute('class','link');
               }
               a.appendChild(span);
               li.appendChild(a);
               ul.appendChild(li);
               }else if (i==0){
			 	var li=document.createElement('li');
               var a=document.createElement('a');
               var span=document.createElement('span');
               span.appendChild(document.createTextNode("Nog geen items beschikbaar..."));
               span.setAttribute('className','titel');
               span.setAttribute('class','titel');
               
			  
			  
			   
			   
			   
               
              
               a.setAttribute('href','#');
               a.setAttribute('className','link');
               a.setAttribute('class','link');
              
               a.appendChild(span);
               li.appendChild(a);
               ul.appendChild(li);
              
			 }
             }

             // replace old records node with new records node
             itemsUl.parentNode.replaceChild(ul,itemsUl);
           }

           // define generateLinks function
           generateLinks=function(page,divid,dataSource,type,bewoner){
           	
           	if(numPages[divid] > 1){
           	
             var pagingDiv=document.getElementById('paging');
             if(!pagingDiv){return;}
             var div=document.createElement('div');
             div.id='paging';

             // assignn default value to array pointer
             if(!page){page=1;}

             // create previous link
             if(page>1){
               var a=document.createElement('a');
               a.href='#' + divid;
               a.id=parseInt(page)-1;
               a.appendChild(document.createTextNode('<<'));
               a.setAttribute('className','vorige');
               a.setAttribute('class','vorige');
               div.appendChild(a);
               a.onclick=function(){

                 // update record list
                 displayRecords(this.id,divid,dataSource,type,bewoner);

                 // update paging links
                 generateLinks(this.id,divid,dataSource,type,bewoner);
               } 
             }

             // create numbered links
             for(var i=1;i<=numPages[divid];i++){
               if(i!=page){

                 // create paging links
                 div.appendChild(document.createTextNode(' '));
                 var a=document.createElement('a');

                 // assign paging links attributes
                 a.href='#' + divid;
                 a.id=i;
                 a.appendChild(document.createTextNode(i));

                 // append link to <div> container
                 div.appendChild(a);

                 // append blank space
                 div.appendChild(document.createTextNode(' '));

                 // assign onclick event handler to paging links
                 a.onclick=function(){

                   // update records list
                   displayRecords(this.id,divid,dataSource,type,bewoner);

                   // update paging links
                   generateLinks(this.id,divid,dataSource,type,bewoner);
                 }
               } 
               else{

                 // the current page is not linked
                var span=document.createElement('span');
                span.appendChild(document.createTextNode(i));
                div.appendChild(span);
              }
            }

            // create next link
            if(page<numPages[divid]){
              var a=document.createElement('a');
              a.href='#' + divid;
              a.id=parseInt(page)+1;
              a.appendChild(document.createTextNode('>>'));
              a.setAttribute('className','volgende');
               a.setAttribute('class','volgende');
              div.appendChild(a);
              a.onclick=function(){

                // update records list
                displayRecords(this.id,divid,dataSource,type,bewoner);

                // update paging links
                generateLinks(this.id,divid,dataSource,type,bewoner);
              }
            }

            // replace old links node with new links node
            pagingDiv.parentNode.replaceChild(div,pagingDiv);
            
           	}

          }