// font resizer
var sitefunctions = {
	textresize : function(){
		var $cookie_name = "BNG-LetterFormaat";
		var originalFontSize = '0.6em';
      var bigFontSize = '0.9em';
      var smallFontSize = '0.4em';
      var $getSize = $j.cookie($cookie_name);
      $j("#pagefunctions").show(); // show text resizing links
      if($getSize) {			// if exists load saved value
			$j("#top").css({fontSize : $getSize }); 
		}
		// reset link - reset cookie
		$j("#pagefunctions .FontSizeReset").bind("click", function() {
			$j("#top").css("font-size", '');
         $j.cookie($cookie_name, null); // reset cookie
         sitefunctions.resetpage();
         return false;
		});
      // text “+" link
      $j("#pagefunctions .FontSizeInc").bind("click", function() {
         $j("#top").css("font-size", bigFontSize);
         $j.cookie($cookie_name, bigFontSize);
         sitefunctions.resetpage();
         return false;
      });
      // text “-" link
      $j("#pagefunctions .FontSizeDec").bind("click", function() {
         $j("#top").css("font-size", smallFontSize);
         $j("#footer").css("font-size", smallFontSize);
         $j.cookie($cookie_name, smallFontSize);
         sitefunctions.resetpage();
         return false;
      });
	},
   // functies die herhaald moeten worden na font resizen
   resetpage : function(){
      document.refresh();  // refresehen om uitklapmenu te herpositioneren
   }
};

// gebruik $j als jquery variabele zodat deze niet conflicteerd met de scripts uit de smartsite formulieren generator
var $j = jQuery.noConflict();  


var kol=0;
var w = 0;
// kolommen van menu splisten
function splits(wie){
   kol++;
   kolclass = "kolom"+kol // classname voor de nieuwe kolom
   var wi = kol*w;      // breedte * aantal kolommen = linker marge voor de nieuwe kolom
   $j('li:gt(3)',wie).remove().clone().insertAfter(wie).wrapAll("<ul class='kolommenu "+kolclass+"'></ul>").parent().css({marginLeft:wi,width:w});
   kolclass = "."+kolclass;
   $j('a',wie).css('width',w);
   // indien meer als 4 li in de nieuwe url - weer splitsen
   if($j(wie).parent().find('li',kolclass).length>4){
      obj = $j(wie).parent().find(kolclass);
      splits(obj);
   };
};

function initmenu(){
   // elk hoofdmenu item checken op sublisten en die splitsen
   $j('#navigatie #primair ol>li').each(function(){
      var x = Math.ceil(($j('ul li', this).length)/4);
      var obj = $j('ul', this);
      w=0;
      w = $j(obj).outerWidth(); // width van de ul
      $j(obj).css('width',w);
      // indien meer als 4 li in de onderliggende url - splitsen
      if($j('li',obj).length>4){
         kol=0;               // kolommtenteller per hoofdmenu>li
         splits(obj);
      }
   });
   // sublisten vergbergen
   $j('#navigatie #primair ol>li ul').hide();
   // menu tonen bij mouseover
   dh = 140;
   var ulh = $j('#navigatie #primair ol ul:first').outerHeight() + $j('#navigatie #primair').outerHeight() + 10;
   if (ulh>dh){dh=ulh;}
   $j('#navigatie #primair ol>li').hover(function(){
      $j(this).addClass('hover');
      if($j('ul',this).is('ul')){ // zijn er kinderen?
         $j('#deurmat').height(dh).css('opacity','1'); //deurmat tonen
         $j(this).parent().addClass('hover');
         $j('ul',this).fadeIn();
      } else {
         $j('#deurmat').height('0px');
      }
   },function(){
      $j(this).removeClass('hover');
      $j('#deurmat').height('0px');
      $j('hover',this).removeClass('hover');
      $j('ul',this).hide();
   });
};

$j(document).ready(function(){
   
   
   // font resizer
   if($j('#top.home').length==0){
      sitefunctions.textresize();	
   };
   
   // uitklapmenu maken
   initmenu();
   
   // IE6 hack
   $j('#top.home #homekader .kader3').css('display','block');

});   
