
	// gebruik $j als jquery variabele zodat deze niet conflicteerd met de scripts uit de smartsite formulieren generator
var $j = jQuery.noConflict();  

// Cookies needed for Font Resizer
function createCookie(name,value){ document.cookie = name+"="+value+"; path=/"; }
function eraseCookie(name){ createCookie(name,"",-1); }
function readCookie(name){
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}


var sitefunctions = {
   // font resizer
	textresize : function(){
	
	
     // FONT RESIZER
     // edit configuration
     var container = $j('#top'); // outer div, containing the site
     var baseFontSize = '0.8em'; // set base font-size same as css
     var maxSize = 1.18;            // max fontsize in em
     var minSize = 0.5;          // min fontsize in em
     var stepSize = 0.1;         // increase/decrease by steps of 0.1
     function resetpage(){ // functies die uitgevoerd worden na het resizen
      // location.reload();  // refreshen om divs te herpositioneren
     }
     // end configuration
     $j('#pagefunctions').show(); 
     var fontsizeContainer = $j('#FontSize'); 
     var sFontSize = readCookie('font');
     if (sFontSize) {
         container.css('fontSize', sFontSize+ 'em'); 
         if (sFontSize*(1+stepSize) > maxSize){ $j(".FontSizeInc",fontsizeContainer).css('opacity','0.1');  }
         if (sFontSize*(1-stepSize) < minSize){ $j(".FontSizeDec",fontsizeContainer).css('opacity','0.1');  }
     } else { // set base fontsize
         $j('#top').css('fontSize',baseFontSize);
     }
     // reset FontSize
     $j(".FontSizeReset",fontsizeContainer).click(function(){
       container.css('fontSize', baseFontSize);
       $j("a",fontsizeContainer).css('opacity','');
       eraseCookie("font");
       resetpage();
       return false;
     });
     // Increase Font Size
     $j(".FontSizeInc",fontsizeContainer).click(function(){
       var newFontSize = parseFloat(container.css('fontSize'), 10) * (1+stepSize);
       if (newFontSize > maxSize){
          $j(".FontSizeInc",fontsizeContainer).css('opacity','0.1');
       } else {
          $j("a",fontsizeContainer).css('opacity','');
          container.css('fontSize', newFontSize+ 'em');
          createCookie("font", newFontSize);
          resetpage();
       }
       return false;
     });
     // Decrease Font Size
     $j(".FontSizeDec",fontsizeContainer).click(function(){
       var newFontSize = parseFloat(container.css('fontSize'), 10) * (1-stepSize);
       if (newFontSize < minSize){
          $j(".FontSizeDec",fontsizeContainer).css('opacity','0.1');
       } else {
          $j("a",fontsizeContainer).css('opacity','');
          container.css('fontSize', newFontSize+ 'em');
          createCookie("font", newFontSize);
          resetpage();
       }
       return false;
     });
	
	}
};


// load ContrastCss 
function loadjscssfile(filename){
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
  fileref.setAttribute("id", "contrastcss");
  document.getElementsByTagName("head")[0].appendChild(fileref);
}


$j(document).ready(function(){

   // font resizer
   sitefunctions.textresize();

   // imagereplacement met alttag
   $j('.padding img').each(function(){
      var alt = $j(this).attr('alt');
      var w = $j(this).width();
      if (alt.length > 0){
         $j(this).parent().append('<span class="sub">'+alt+'</span>').wrap('<div class="imagebox"></div>');
      }
   })
   
   // toon printlink
   $j('a.print').css('display','block');;
   
    // maak een TableOfContents
	// if($j('#contentcolumn>.padding>h2').not('h1 + h2').length>1){
   if($j('#contentcolumn>.padding>h2').not('h1 + h2').not('.pagetitle').length>1){
      var toc = "<h2>On this page</h2><ul class='toc list'>";
      var i=1;
      $j('#contentcolumn>.padding>h2').not('.pagetitle').each(function(){
         var t = $j(this).html();
         $j(this).prepend("<a name='toc_"+i+"'></a>");
         toc += "<li><a href='#toc_"+i+"'>"+t+"</a></li>";
         i++;
      });
      toc += "</ul>"
	  
      $j('#toc').prepend(toc);
   } 

  // hoofdmenu
   $j('#menu>ol>li.active ol').show(); // toon active submenu
   $j('#menu>ol>li>a').mouseover(function(){
      $j("#menu>ol>li>a.hover").not(this).removeClass('hover');
      $j("#menu ol ol").not($j(this).next("ol")).hide();
      $j(this).addClass('hover');
      $j(this).next("ol").show();
   });

   $j('#menu').mouseleave(function(){  // verlaat het menu
      $j("#menu>ol>li>a.hover").removeClass('hover');
      $j("#menu>ol>li:not('.active') ol").hide();
      $j('#menu>ol>li.active ol').show(); // toon active submenu 
   })
    
 /*
   // hoofdmenu jQuery 1.4.2
   $j('#menu>ol>li.active ol').show(); // toon active submenu
   $j('#menu>ol>li>a').hover(function(){
      $j(this).addClass('hover');
      $j('#menu>ol>li>a').not(this).removeClass('hover');
      $j('#menu ol ol').clearQueue();  // cancel andere animaties
      if ($j(this).parent().hasClass('active')){  // mouseover active - verberg de andere
         $j('#menu>ol>li.active>a').removeClass('hide');
         $j('#menu ol li').not('.active').find('ol:first').clearQueue().delay(500).animate({width:'hide'},function(){
            $j(this).removeAttr("style").css('height', navH);
         });
      } else { // mouseover - toon over active heen
         $j('#menu>ol>li.active>a').addClass('hide');
         $j('#menu>ol>li').not('.active').not($j(this).parent()).find('ol:first').css('zIndex','5');
         $j(this).next('ol').css('zIndex','10').delay(500).animate({width:'show'},function(){
            $j('#menu ol li').not('.active').find('ol:first').not(this).hide().removeAttr("style").css('height', navH);
         });      
      }
   },function(){
      $j(this).removeClass('hover');
   });
   
   $j('#menu ol ol').mouseenter(function(){  //cancel alle animaties als je al in een submenu zit;
      if ($j(this).parent().hasClass('active')){
         $j('#menu ol ol').clearQueue();
      } else {
         $j('#menu ol ol').clearQueue();
         $j(this).parent().addClass('open');
      }
   });
   
   $j('#menu').mouseleave(function(){  // verlaat het menu
      $j('#menu>ol>li>a.hover').removeClass('hover');
      $j('#menu ol ol').clearQueue();
      // cancel animaties en na delay hide de openstaande, behalve .active
      $j('#menu ol li').not('.active').find('ol:first').clearQueue().delay(500).animate({width:'hide'},function(){
         $j(this).removeAttr("style");
         $j('#menu>ol>li.active>a').removeClass('hide');
      });
   })
   
   $j('#menu>ol>li').not('.active').find('ol').mouseleave(function(){ // verlaat/submenu
      $j('#menu>ol>li.open').removeClass('open');
      $j('#menu>ol>li>a.hover').removeClass('hover');
      $j('#menu ol ol').clearQueue();
      $j(this).delay(100).animate({width:'hide'},function(){
         $j('#menu>ol>li.active>a').removeClass('hide');
      });
   });
 */

   // load and switch ContrastCss
   var cc = readCookie('ContrastCookie');
   if (cc) {
      loadjscssfile("/design/css/contrast.css");
   }
   $j('#pagefunctions #contrast').click(function(){
      if ($j('#contrastcss').length) {
         $j('#contrastcss').remove();
         eraseCookie("ContrastCookie");
      } else {
         loadjscssfile("/design/css/contrast.css");
         createCookie("ContrastCookie", 'highcontrast');
      }
      return false;
   });
   
   // banners
   $j('.banners .banner').css('backgroundColor','#525252').hover(function(){
      $j('img',this).fadeTo('fast',0.8);
   },function(){
      $j('img',this).fadeTo('fast',1);
   })


    //themabanners
	var bnrs = $j('#themabanners .banner').length;
	$j('#themabanners .banner:last').css('display','block').css({width:'248px'});
   	function changeBanner(){
      $j('#themabanners .banner:last').animate({width:'248px'},5000,function(){
	  	$j('#themabanners .banner:gt('+(bnrs-3)+')').css('display','block').addClass('fade');
	  	$j(this).fadeOut("slow", function(){
			$j(this).prependTo('#themabanners').hide();   
			changeBanner();
    	  })
	  	})
   	};
	//themabanners2
	var l = $j('#themabanners2 .banner').length;
	$j('#themabanners2 .banner:last').show().css({width:'248px'});
   	function changeBanner2(){
      $j('#themabanners2 .banner:last').animate({width:'248px'},5000,function(){
	  	$j('#themabanners2 .banner:eq('+(l-2)+')').show();
	  	$j(this).fadeOut("slow", function(){
			$j(this).prependTo('#themabanners2').hide();   
			changeBanner2();
    	  })
	  	})
   	};   
   
   changeBanner2();
   changeBanner();
   // tabel met wisselende rijkleur (class=rijentabel)
   $j('table.rijentabel tr:odd').addClass('alt');
   // tabel met wisselende kolomkleur (class=kolommentabel)
   $j('table.kolommentabel tr').find('td:even').addClass('alt');

   // aanpassen input-elementen
   $j('#content input[type="text"]').addClass('field');
   $j('#content input[type="password"]').addClass('field');
   $j('#content input[type="file"]').addClass('field');
   $j('#content textarea').addClass('field');
   $j('#content input[type="submit"]').addClass('button');
   $j('#content input[type="cancel"]').addClass('button');
   $j('#content input[type="button"]').addClass('button');
   $j('#content input[type="reset"]').addClass('button');
   
});

