 var sitefunctions = {
   // font resizer
	textresize : function(){
		$j("#fontsize").show(); // show text resizing links
      
		var $cookie_name = "ITC-font-size";
      
		var originalFontSize = '0.75em';
      var bigFontSize = '0.9em';
      var smallFontSize = '0.6em';
      var $getSize = $j.cookie($cookie_name);
		if($getSize) {			// if exists load saved value
			$j("#wrapper").css({fontSize : $getSize }); 
		}
		// reset link - reset cookie
		$j("#fontsize .FontSizeReset").bind("click", function() {
			$j("#wrapper").css("font-size", '');
         $j.cookie($cookie_name, null,{path: '/'}); // reset cookie
         sitefunctions.resetpage();
         return false;
		});
      // text &#8220;+" link
      $j("#fontsize .FontSizeInc").bind("click", function() {
         $j("#wrapper").css("font-size", bigFontSize);
         $j.cookie($cookie_name, bigFontSize,{path: '/'});
         sitefunctions.resetpage();
         return false;
      });
      // text &#8220;-" link
      $j("#fontsize .FontSizeDec").bind("click", function() {
         $j("#wrapper").css("font-size", smallFontSize);
         $j.cookie($cookie_name, smallFontSize,{path: '/'});
         sitefunctions.resetpage();
         return false;
      });
	},
   // functies die herhaald moeten worden na font-resizen
   resetpage : function(){
      document.location.reload();  // refreshen om uitklapmenu te herpositioneren
   }
};


/*
	Addition by Michiel Kikkert on August 12, 2009
 	---------------------------------------------------------------------------------
	
*/

var sCookieName_CourseFinder_selectbox = 'CourseFinder_selectBox_State';
var sCookieName_CourseFinder_paginator = 'CourseFinder_paginator_State';

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function getValue(parameter, value) {    	
	if ($j('#'+parameter+' option[value='+getParameterByName(parameter).toLowerCase()+ ']').length){
		  return parameter + ':' + getParameterByName(parameter);
	}	
	else
	{
	return parameter + ':';
	}   
}

function clearCookie(redirect)
{	
	$j.cookie(sCookieName_CourseFinder_selectbox, null, { expires: -1, domain: '.itc.nl', path: '/' });
	//$j.cookie(sCookieName_CourseFinder_paginator, null, { expires: -1, domain: '.itc.nl', path: '/' });
	$j.cookie(sCookieName_CourseFinder_paginator, 1, null);
	if(redirect == true){
		window.location.href = "CourseFinder";
	}
}


var pervUrl = '';
function saveCookieFromUrl(){
	if(window.location.href.indexOf('?') != -1 && prevUrl.indexOf("/study/Courses/") == -1)
	{	
		$j.cookie(sCookieName_CourseFinder_selectbox, null, { expires: -1, domain: '.itc.nl', path: '/' });
		var selectedVals = null;
		if ($j.cookie(sCookieName_CourseFinder_selectbox)) {
			selectedVals = $j.cookie(sCookieName_CourseFinder_selectbox).split('|');
		}
		else {
			selectedVals = [];
		}

		if (selectedVals.length == 5) {
			selectedVals[0] = getValue('programme', selectedVals[0]);
			selectedVals[1] = getValue('starting', selectedVals[1]);
			selectedVals[2] = getValue('domain', selectedVals[2]);
			selectedVals[3] = getValue('duration', selectedVals[3]);
			selectedVals[4] = getValue('location', selectedVals[4]);
		}
		else {
			selectedVals.push(getValue('programme'));
			selectedVals.push(getValue('starting'));
			selectedVals.push(getValue('domain'));
			selectedVals.push(getValue('duration'));
			selectedVals.push(getValue('location'));
		}
		if(selectedVals[0] != 'programme:' || selectedVals[1] != 'starting:'|| selectedVals[2] != 'domain:' || selectedVals[3] != 'duration:' || selectedVals[4] != 'location:'){		
			$j.cookie(sCookieName_CourseFinder_selectbox, selectedVals.join('|'), { expires: 0, domain: '.itc.nl', path: '/' });
		}
		
		//window.location.href = "CourseFinder";		
	}
	else if (window.location.href.indexOf('?') == -1 && prevUrl.indexOf("/study/Courses/") == -1 && prevUrl.indexOf("/CourseFinder") == -1){
		clearCookie(false);
	}

}

var saveSelectState = function () {
	if(($j('#programme').val() == '') && ($j('#starting').val() == 'upcoming') && ($j('#domain').val() == '') && ($j('#duration').val() == '') && ($j('#location').val() == ''))
	{
		$j.cookie(sCookieName_CourseFinder_selectbox, null, { expires: -1, domain: '.itc.nl', path: '/' });
	}
	else
	{
		var selectedVals = [];
		selectedVals.push('programme:' + $j('#programme').val());
		selectedVals.push('starting:' + $j('#starting').val());
		selectedVals.push('domain:' + $j('#domain').val());
		selectedVals.push('duration:' + $j('#duration').val());
		selectedVals.push('location:' + $j('#location').val());
		$j.cookie(sCookieName_CourseFinder_selectbox, selectedVals.join('|'), { expires: 0, domain: '.itc.nl', path: '/' });
	}
};

var savePaginatorState = function () {
    // Check which page is active and store in a cookie
    sPaginatorState = $j('#coursepages .active').text();
    //if (sPaginatorState != '1') { // If the current page is 1, don't bother storing it in the cookie
    $j.cookie(sCookieName_CourseFinder_paginator, sPaginatorState, null);
    //}

}



var setSelectedStateFromCookie = function () {

    if ($j.cookie(sCookieName_CourseFinder_selectbox)) {
	//alert($j.cookie(sCookieName_CourseFinder_selectbox));
        selectBoxStates = $j.cookie(sCookieName_CourseFinder_selectbox).split('|');
		
        if (typeof selectBoxStates == 'object' && selectBoxStates instanceof Array) {
		
            for (var i = 0; i < selectBoxStates.length; i++) {
				if(selectBoxStates[i] != ''){
					id = selectBoxStates[i].split(':')[0];
					val = selectBoxStates[i].split(':')[1];
					val = val.toLowerCase();
					if(id != '')
					{         
						if ($j('#'+id+' option[value='+val+ ']').length){
						   $j('#' + id + ' option').attr('selected', '');
							sFilter = '[value=' + val + ']';
							$j('#' + id + ' option').filter(sFilter).attr('selected', 'selected');
						}					
					
					}
				}
			}
            $j('#programm').change();
        }		
    }
	
};

var setSelectedStateFromUrl = function(){

	if(location.search.substr(1).length > 0){
		var sUrlVars = location.search.substr(1);
		var aUrlVars = sUrlVars.split('&');
		if(aUrlVars.length > 0){
			for(i=0; i < aUrlVars.length ; i++){
				sType = aUrlVars[i].split('=')[0];
				sValue = aUrlVars[i].split('=')[1];
				$j('#'+sType +' option').attr('selected','');
				sFilter = '[value='+sValue+']';
				$j('#'+sType +' option').filter(sFilter).attr('selected','selected');
			}
		}
	}
	
}

var setPaginatorStateFromCookie = function(){
	
	if($j.cookie(sCookieName_CourseFinder_paginator)){
		iPaginator = parseInt($j.cookie(sCookieName_CourseFinder_paginator))-1; // ZERO based
		$j('#coursepages a.coursepage:eq('+iPaginator+')').click();
		
	}
}

var doCourseFinderLinks = function(){
	
	var CourseFinderLinks = $j('.coursefinderlink');
	
	$j(CourseFinderLinks).bind('click',function(oE){
		oE.preventDefault();

		var sCourse = $j(this).attr('title');
		var sCookieValue = 'Course:'+sCourse;
		$j.cookie(sCookieName_CourseFinder_paginator, null);
		$j.cookie(sCookieName_CourseFinder_selectbox, sCookieValue, { expires:0, domain: '.itc.nl' , path: '/'});
		document.location.href = $j(this).attr('href');
	});
																		  
	
}

// End addition Michiel Kikkert.


// verberg en toon de backtotop-link als de site hoger is als het window
function inittotop(){
   $j('#backtotop').remove().unbind('click')
   $j('#foot').prepend('<a id="backtotop" href="#">back to top</a>');
   $j('#backtotop').click(function(){
      $j.scrollTo( '#wrapper', 800);    // onclick - scroll naar boven
      return false;
   });   
   if ($j("#container").height() > $j(window).height()){ // check hoogte
      $j('#backtotop').show();   
   }   
}

// maak de hoogte gelijk van element binnen de rij van een landingspagina
function equalheight(element){
   var y=0;
   var z=0;
   // geef de blokken een class .rowX
   $j("#wrapper.landingpage #columnwrapper .landing_block:not('#first')").each(function(){
      if (y==3){y=0;z++;}   
      y++;
      $j(this).addClass('row'+z);
   });
   // vergelijk de hoogte per .rowX
   for (x=0;x<=z;x++){
      var rij = ".row"+x
      $j(rij, '#content').each(function(){
         var h = 0;
         $j(element, rij).each(function(){
            var hoogte = $j(this).height();
            if (hoogte > h){h = hoogte};
         });
         $j(element, rij).height(h);
      });
      $j(rij+":odd .landing_block_content",'#content').css('backgroundColor','#FFFFFF').parent().addClass('odd');
      $j(rij+":even .landing_block_content",'#content').css('backgroundColor','#F3F2F0');
   }   
}

// sluit blokken op landingspagina's
function closeblok(wie){
   var h = $j(wie).parent().height();
   $j('.shadow',wie).hide();
   $j(wie)
   .removeClass('open')
   .css({overflow:'hidden'})
   .animate({height:h-12},function(){
      $j(this).parent().css('z-index','1');
      $j(this).next('.more').show();
   });
}

// openklappen blokken op landingspagina
function initlandingpage(){
   $j("#wrapper.landingpage #content .landing_block").not('#first').each(function(){
      var h = 260; // hoogte van de landingsblokken
      $j(this).height(h);
      var hc = $j('.landing_block_content', this).height();
      $j('.landing_block_content', this).css({height:h-12,position:'absolute'}) // ALLE blokken dezelfde hoogte geven
      if(hc > h){
         $j('.landing_block_content', this)
            .css({overflow:'hidden'})
            .after('<a href="#" class="more"></a>')
            .append('<a href="#" class="less"></a>')
            .append('<div class="shadow"></div>');
         $j('#content .shadow').hide().ifixpng();
         $j('.more', this).ifixpng().click(function(){ // more link opent het blok
            closeblok($j('#content .open'));
            $j(this).hide().parent().css('z-index','100').find('.landing_block_content')
               .addClass('open')
               .css({overflow:'visible'})
               .animate({height:hc},function(){
                  $j('.shadow',this).show();
               });
            return false;
         });
         $j('.less', this).click(function(){ // less link sluit het blok
            closeblok($j('#content .open'));
            return false;
         });
      };
   });
};

function csstables(){
   // tabel met wisselende rijkleur (class=rijentabel)
   $j('table.rijentabel tr:even').addClass('alt');
   // tabel met wisselende kolomkleur (class=kolommentabel)
   $j('table.kolommentabel tr').find('td:even').addClass('alt');
}


// bookmark functie
function bookmarksite(title,url){
   if (window.sidebar){ // firefox
   	window.sidebar.addPanel(title, url, "");
   } else if(window.opera && window.print){ // opera
   	var elem = document.createElement('a');
   	elem.setAttribute('href',url);
   	elem.setAttribute('title',title);
   	elem.setAttribute('rel','sidebar');
   	elem.click();
   } else if(document.all){// ie
   	window.external.AddFavorite(url, title);
   }
}

// toon coursedetails in popupje
function coursedetails(){
	oTooltips.attach();
}

// Addition by Michiel Kikkert August 12, 2009 - alternative popup function -----------------------------------------------

var oTooltips = {
	
	offsetTop: 5,
	offsetLeft: 5,

	attach: function(){
		// Find all elements that need a tooltip:
		var elTooltipsLinks = $j('#courseFinder #CFresult a.coursedetails').prev('a');
		// Attach a hover event
		elTooltipsLinks.hover(
			function(){ // on Hover
				// Find the a element that belongs to the hovered element and get the href attribute:
				var elHref = $j(this).next('a').attr('href');
				// Load the content in de popup element:
				var elPop = $j('#coursedetails');
				$j(elPop).find('.body').html("Loading...").load(elHref);
				// attach the element to the tracker so it follows the mouse:
				oTooltips.tracker(true, elPop);
				// Show the element:
				elPop.show()			
			},
			function(){ // on hover off
				// Remove the contents of the popup element:
				$j('#coursedetails .body').empty();
				// Tell the tracker to stop tracking:
				oTooltips.tracker(false);
				// hide the popup element:
				$j('#coursedetails').hide();	
			}
		);
		// Remove any existing rel and title attributes on the links to prevent double popups:
		elTooltipsLinks.attr('title' ,'');
		elTooltipsLinks.attr('rel' ,'');
	},
	
	tracker: function(track, el){
		
		if(track) {
			$j().bind("mousemove", 
					 function(e){
         				var oOffset = $j('#courseFinder').offset();
						el.css('top', oTooltips.offsetTop+e.pageY-oOffset.top);
						el.css('left', oTooltips.offsetLeft+e.pageX-oOffset.left);
					}
			);
		}else{
			$j().unbind("mousemove");
		}
			
	}
}

// End addition -> 

var perpage = 16; // aantal getoonde rijen in de coursefinder
// toon nieuw aantal rijen
function showcourses(start, end, l){
   $j('#coursepages a.active').removeClass('active');  // verwijder active van pagelinks
   $j('#coursepages a.coursepage:eq('+start/perpage+')').addClass('active');  // geef active aan huidige pagelink
   $j('#courseFinder #Courses tbody tr').hide().filter(function (index) {     // verberg alles behalve de range die getoond moet worden
      return index >= start && index < end;
    }).show();
    if(start > 1){   // > page 1 de previous link tonen + functie geven
      $j('#coursepages #prevcp').show().unbind().click(function(){
         showcourses(start-perpage, end-perpage,l);
         return false;
      });
    } else {
      $j('#coursepages #prevcp').hide();
    }
    if(end >= l){ // op laatste pagina geen next link tonen + functie geven
      $j('#coursepages #nextcp').hide();
    } else {
      $j('#coursepages #nextcp').show().unbind().click(function(){
         showcourses(start+perpage, end+perpage,l);
         return false;
      });
    }
}
// paginering coursefinder Result
function coursepages(){   
   $j('#coursepages').empty();
   var start = 0;
   var end = start + perpage;
   var l = $j('#courseFinder #Courses tbody tr').length;  // aantal rijen in de coursefinder Result
   if (l>perpage){   // als er meer rijen zijn als gewenst per pagina
      var pages = Math.ceil(l/perpage);   // aantal paginas
      for (x=1;x<=pages;x++){
         var id = "page"+x;
         var pagelink = '<a href="#" class="coursepage" id="'+id+'">'+(x)+'</a> '
         $j('#coursepages').append(pagelink);
      }
      $j('#coursepages a').click(function(index){
         var index = $j('#coursepages a.coursepage').index(this); // linknummer x aantal
         var start = index*perpage;
         var end = (index+1)*perpage;
         showcourses(start, end,l);
         newwindow("#courseFinder #Courses");
         return false;
      });
      $j('#coursepages').prepend('<a href="" id="prevcp">&laquo; previous</a> '); // plaats previous link
      $j('#coursepages').append('<a href="" id="nextcp">next &raquo; </a> '); // plaats next link
      $j('#coursepages a.coursepage:first').trigger('click');
   } else {
      $j('#courseFinder #Courses tbody tr').show();
      newwindow("#courseFinder #Courses");
   }
}

// opent de CourseFinder
function openCF(){
   var h = $j('#courseFinder #CFform').outerHeight() + $j('#courseFinder #CFresult').outerHeight() + $j('#courseFinder #CFfooter').height();
   $j('#courseFinder').animate({height:h});
}

function newwindow(div){
   $j('a.newwindow',div).attr('target','_blank');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// gebruik $j als jquery variabele zodat deze niet conflicteerd met de scripts uit de smartsite formulieren generator
var $j = jQuery.noConflict();  

function loadCourseFinder(readurl)
{	

	$j('#wrapper.coursefinder #courseFinder #CourseFinderLists').load('_ajax_coursefinderlists.html', function() {	
		//Only read the url on initial load
		if(readurl)
		{	
			saveCookieFromUrl();						
		}
		
	
		if ($j.cookie(sCookieName_CourseFinder_selectbox)) { // We have a cookie so use the cookie value
			//set the right selected of the boxes
			setSelectedStateFromCookie();	
			
			//if there is a cookie make sure the clear button works right
			$j('#courseFinder #coursefinderbtn').css('background-image', 'url(/design/images/button_coursefinder_clear.png)');	
			
			$j('#courseFinder #coursefinderbtn').click(function(EO) {
			  EO.preventDefault();
			  clearCookie(true);
			  loadCourseFinder(0);
			});			
			
		}	
		else {
		//no cookie so the clear button is not active. The href attribute is removed the remove the 'hand' of the pointer on hover
		$j('#courseFinder #coursefinderbtn').removeAttr("href");
		$j('#courseFinder #coursefinderbtn').click(function(EO) {		
			  EO.preventDefault();
			});	
		}

		// study: coursefinder on selectbox change		
		$j('#courseFinder #CFform select').change(function () {
			saveSelectState(); 
			//after a change we want to show the first page
			$j.cookie(sCookieName_CourseFinder_paginator, 1, null);			
			loadCourseFinder(0);					
		});

		// Bind the links using 'live' in de Coursefinder results so it will save the state of the selectboxes on click
		//$j('#Courses a[href]').live('click', saveSelectState);
		$j('#Courses a[href]').live('click', savePaginatorState);

		// Bind external coursefinder links:
		//doCourseFinderLinks();
				
		var coursefinderpage = '_ajax_coursefinderresult.html';
		$j('#wrapper.coursefinder #courseFinder #CFresult').load(coursefinderpage, function () {
			csstables();
			coursedetails();
			coursepages();
			// Addition!!
			setPaginatorStateFromCookie(); // Sets the correct page if set in cookie.
			$j('#courseFinder #CFfooter').ifixpng();
			$j('#courseFinderButton').addClass('open');
			openCF();
		});
		
	});	
}



$j(document).ready(function(){

   // font resizer
   sitefunctions.textresize();	

   // toon de backtotop-link als de site hoger is als het window
   inittotop();

   // bewerk tabellen
   csstables();
   
   // externe links
   newwindow("#columnwrapper");

   // images met onderschrift
   $j('#content div.image').each(function(){
      var w = $j('img', this).width();
      if ($j('img', this).css('borderRightWidth')=='1px'){
         w = w+2;
      }
      $j(this).width(w).find('div').width(w-20).show();
   });
   $j('#content #resumepicture').append('<span></span>').ifixpng();
   
  // Resume - publications
 // $j('#wrapper.organisation #publicationtypes li:not(.active)').css('opacity','0.5').find('a').click(function(){
   //   $j('#wrapper.organisation #publicationtypes li.active').removeClass('active').css('opacity','0.5');
   //   var puburl = $j(this).attr('href');
   //   var titel = $j(this).html();
   //   $j('#wrapper.organisation #publications').html('Loading...').load(puburl, function(){
   //      $j("#wrapper.organisation #publications a[href*=.ppt]").addClass("file ppt");
   //      $j("#wrapper.organisation #publications a[href*=.pdf]").addClass("file pdf");
   //      $j("#wrapper.organisation #publications a[href*=dx.doi.org]").addClass("file html");
   //      $j("#wrapper.organisation #publications a[href*=.pdf],#wrapper.organisation #publications a[href*=http]").click(function(){
   //       window.open(this.href);
   //       return false;
   //      });
   //   });
   //   $j(this).parent().addClass('active').css('opacity','1');
   //   $j('#wrapper.organisation #publications').prev('h2').find('span').html(titel);
   //   return false;
   //});
  // $j('#wrapper.organisation #publicationtypes li:first a').trigger('click');


	if($j('#wrapper.research #researchPublications').length != 0){
		$j("#wrapper.research #researchPublications:not(:has(#theseslist)) a").addClass("file html");
		$j("#wrapper.research #researchPublications a[href*=.pdf]").attr('class',"file pdf");
		$j("#wrapper.research #researchPublications a[href*=.zip]").attr('class',"file zip");
		$j("#wrapper.research #researchPublications a[href*=.pdf],#wrapper.research #researchPublications a[href*=http]").click(function () {
			window.open(this.href);
			return false;
		});
	}

	if($j('#publicationtypes').length != 0){		
		var y = getParameterByName('y');
		var l = getParameterByName('l');
		//set the active year in de submenu on the right
		if(y != ''){
			var fullYear = parseInt(y) + 2000;
			$j('#submenu li a[innerHTML='+fullYear.toString()+']').addClass('active');
		} 
		
		$j('#publicationtypes li:not(.active)').css('opacity', '0.5');	
		if($j('#publicationtypes #l'+l).length != 0){
			$j('#publicationtypes #l'+l).addClass('active').css('opacity', '1');
		}
		else{		
			$j('#publicationtypes li:first').addClass('active').css('opacity', '1');	
		}
		
		$j("#publications:not(:has(#theseslist)) a").addClass("file html");
		$j("#publications a[href*=.pdf]").attr('class',"file pdf");
		$j("#publications a[href*=.zip]").attr('class',"file zip");
		$j("#publications a[href*=.pdf],#publications a[href*=http]").click(function () {
			window.open(this.href);
			return false;
		});
	}

	// Library - Latest Additions
	if($j('#wrapper.library #publications_additions').length != 0){
		$j("#wrapper.library #publications_additions:not(:has(#theseslist)) a").addClass("file html");
		$j("#wrapper.library #publications_additions a[href*=.pdf]").attr('class',"file pdf");
		$j("#wrapper.library #publications_additions a[href*=.zip]").attr('class',"file zip");
		$j("#wrapper.library #publications_additions a[href*=.pdf],#wrapper.library #publications_additions a[href*=http]").click(function () {
			window.open(this.href);
			return false;
		});
	}
	
	// Academic output 2
	if($j('#wrapper.library #publicationtypes').length != 0){
		var l = getParameterByName('l');
		var y = getParameterByName('y');
		var p = getParameterByName('p');
		
		//set the active year in de submenu on the right
		if(y != ''){
			var fullYear = parseInt(y) + 2000;
			$j('#submenu li a[innerHTML='+fullYear.toString()+']').addClass('active');
		} 
		else{
			$j('#submenu li:first a').addClass('active');
		}
		
		//hide msc theses for 2000 and 2001
		if(y == '0' || y == '1'){
			$j('#wrapper.library #publicationtypes #l20').hide();
		}
		
		$j('#wrapper.library #publicationtypes li:not(.active)').css('opacity', '0.5');		
		if($j('#wrapper.library #publicationtypes #l'+l).length != 0){
			$j('#wrapper.library #publicationtypes #l'+l).addClass('active').css('opacity', '1');
		}
		else{		
			$j('#wrapper.library #publicationtypes li:first').addClass('active').css('opacity', '1');	
		}	
		
		$j("#wrapper.library #publications:not(:has(#theseslist)) a").addClass("file html");
		$j("#wrapper.library #publications a[href*=.pdf]").attr('class',"file pdf");
		$j("#wrapper.library #publications a[href*=.zip]").attr('class',"file zip");
		$j("#wrapper.library #publications a[href*=.pdf],#wrapper.library #publications a[href*=http]").click(function () {
		window.open(this.href);
		return false;
	});
	}	







   
   // study: coursefinder
   
 //  $j('#courseFinder #CFform select').change(function(){
   //   var coursefinderpage = '_ajax_coursefinderresult.html';
     // var postdata = "";
      //$j('#courseFinder #CFform select option:selected').each(function(){
      //   //postdata+= $j(this).parent().attr('id')+':'+$j(this).attr('value')+',';
       //  postdata+= $j(this).parent().attr('name')+'='+$j(this).attr('value')+'&';
      //});
      //eval("postdata");
      ////alert(coursefinderpage+'?'+postdata);
      //$j('#wrapper.coursefinder #courseFinder #CFresult').load(coursefinderpage+'?'+postdata,function(){
       //  csstables();
        // coursedetails();
         //coursepages();
         //$j('#courseFinder #CFfooter').ifixpng();
         //$j('#courseFinderButton').addClass('open');
         //openCF();
        // //alert ('results refreshed with postdata:\n'+postdata);
      //});
   //});

   // open coursefinder 
   
   /*
   ****** Addition made to allow for saving coursefinder state in Cookie and to restore the state on initial load
   */
   
   //// Bind the links using 'live' in de Coursefinder results so it will save the state of the selectboxes on click
	//$j('#Courses a[href]').live('click',saveSelectState);
	//$j('#Courses a[href]').live('click',savePaginatorState);
	
	//// Bind external coursefinder links:
	//doCourseFinderLinks();
	
	//// Now set the selectboxes on initial load to the correct values.
	
	//if($j.cookie(sCookieName_CourseFinder_selectbox)){ // We have a cookie so use the cookie value
	//	setSelectedStateFromCookie();
	//}
	
   
  // var coursefinderpage = '_ajax_coursefinderresult.html';
   //   var postdata = "";
    //  $j('#courseFinder #CFform select option:selected').each(function(){
    //     postdata+= $j(this).parent().attr('name')+'='+$j(this).attr('value')+'&';
   //   });
    //  eval("postdata");
    //  $j('#wrapper.coursefinder #courseFinder #CFresult').load(coursefinderpage+'?'+postdata,function(){
   //   csstables();
   //   coursedetails();
   //   coursepages();
	  // Addition!!
	//  setPaginatorStateFromCookie(); // Sets the correct page if set in cookie.
   //   $j('#courseFinder #CFfooter').ifixpng();
    //  $j('#courseFinderButton').addClass('open');
   //   openCF();
 //  });

      
   // IE6 png-fix voor de aardbol
   $j('#navigation h2').ifixpng(); 

   // show more content
   $j("#content a.showmore").show().after('<a href="#" class="showless">less</a>').click(function(){
      var loadurl = $j(this).attr('href');
      $j(this).hide().parents('div:first').after('<div class="content_extra ajaxdetails">loading detailed information...</div>');
      $j('#content .ajaxdetails').hide().load(loadurl,function(){
         $j(this).slideDown('slow',function(){
               $j('#content .showless').show().click(function(){
                  $j(this).hide();
                  $j('#content .ajaxdetails').slideUp(function(){
                     $j('#content .ajaxdetails').remove();
                     $j("#content .showmore").show();
                  });
                  return false;
               });         
         });
      });
      return false;
   });
   
   // uitklapbaar inlogform
   $j('#loginform').hide();
   $j('#showlogin').show().toggle(function(){
      $j('#loginform').slideDown(function() {
        $j('#loginform #username').focus();
      });
      $j('#showlogin').html('Close');
   },function(){
      $j('#loginform').slideUp();
      $j('#showlogin').html('Login');
   });
   
   // geef de kruimelpad items zonder link transparantie
   $j('#path .nolink').css('opacity','0.7')
   
   // interne links op inlog-landingspagina van Alumni
   $j('#wrapper.alumni #content #loggedinlinks #events').click(function(){
      $j.scrollTo( '#alumni_events', 800); 
      return false;
   });
   $j('#wrapper.alumni #content #loggedinlinks #news').click(function(){
      $j.scrollTo( '#alumni_news', 800); 
      return false;
   });
   
   // landingpage: gelijke hoogtes maken voor h2;
   if($j('#wrapper.landingpage').length){
      equalheight('h2');
   }
   
   // landingpage: maak twee koloms lijsten van class='tweekoloms' door ze halverwege te splitsen
   $j('#content .tweekoloms').each(function(){
      var extraclass = "" + $j(this).attr('class');
      extraclass = extraclass.replace(/tweekoloms/,"");
      var aantal = Math.ceil(($j('li', this).length)/2);
      $j('li:gt('+aantal+')',this).remove().clone().insertAfter(this).wrapAll("<ul class='"+extraclass+" tweekoloms twee'></ul>");
   })

   // landingpage: openklappen blokken 
   initlandingpage();      
   
   
   // tabbed content op news pagina's en home
   var links = $j('#content div.tabbed h2.tab').remove().clone().wrapInner('<a href="#"></a>');
   $j('#content div.tabbed').prepend(links);
   $j('#content div.tabbed ol.tablist').hide();
   $j('#content div.tabbed h2.tab:last').css('border','0px')
   $j('#content div.tabbed h2.tab a').click(function(){  
      $j('#content div.tabbed h2.tab a.active').removeClass('active');
      var id = '#tab'+$j(this).parent().attr('id');
      $j('#content div.tabbed ol.tablist').hide();
      $j(id, '#content div.tabbed').show();
      $j(this).addClass('active');
      return false;
   });
   $j('#content div.tabbed h2.tab:first a').trigger('click');
   
   
   
   // home visuals
   $j('#wrapper.home h1').ifixpng();
   var homevis1 = $j('#wrapper.home #homevisual1 a').attr('href'); 
   $j('#wrapper.home #homevisual1').css("background-image","url("+homevis1+")");
   var homevis2 = $j('#wrapper.home #homevisual2 a').attr('href'); 
   $j('#wrapper.home #homevisual2').css("background-image","url("+homevis2+")");
   var homevis3 = $j('#wrapper.home #homevisual3 a').attr('href'); 
   $j('#wrapper.home #homevisual3').css("background-image","url("+homevis3+")");

   
   // hover op listpagina's
   $j('#wrapper.listpage #content ul li').hover(function(){
      $j(this).addClass('hover');
   },function(){
      $j(this).removeClass('hover');
   }).click(function(){
      var href = $j('h2 a', this).attr('href')
      document.location = href;
      return false;
   });

   
   // image op listpages
   var listvisual = $j('#wrapper.listpage #themebarimage').attr('href'); 
   if (listvisual){
      $j('#wrapper.listpage #themebar').css("background-image","url("+listvisual+")");
   }
   
   
   // .uitklap lijst - gebruik opacity om ie6 problemen te voorkomen
   $j('#page ul.foldout ul').hide().prev('a').toggle(function(){
      $j('#page ul.foldout .open:first a').trigger('click');
      $j(this).parent().addClass('open').find('ul').animate({height:'show',opacity:'show'});
   },function(){
      $j(this).parent().removeClass('open').find('ul').slideUp();
   });
  
   // .uitklap lijst openhouden als er een jaar geopend wordt via een andere pagina - ?year=2005
   year=0;
   q='';
   q=window.location.search.substring(1).split('&');
   archivetype='';
   for(x in q)
   {
       qp=q[x].split('=');
	     if(qp[0]=='archivetype')
	     {
	         archivetype = qp[1];
	     }
   }
   
   if (!archivetype){
      $j('#page ul.foldout:first li:first a').trigger('click');
   }
   
   if (archivetype){
   	for(x in q)
   	{
      	p=q[x].split('=');
	if(p[0]=='year' && parseInt(p[1])!=NaN) {
        	var openjaar = '#' + archivetype + 'year'+ p[1];
        	$j('#page ul.foldout ' + openjaar).trigger('click');
      }
   }
   }
  
   // plaats pagina functies Print en Bookmark (behalve op home)
   if(!$j('#wrapper.home').length){
      $j('#page').append(' <div id="pagefunctions"><a href="javascript:print();" class="print">print this page</a></div><!-- /pagefunctions --> ');
      //  <a href="" class="bookmark">bookmark this page</a> weggehaald
      $j('#pagefunctions .bookmark').click(function(){
         bookmarksite(document.title, document.location);
         return false;
      });
   };
   
   // sitemap 
   $j('#wrapper.sitemap #content ol>li.main:even').addClass('even');
   $j('#wrapper.sitemap #content ol>li.main ul ul').parent().find('span').hover(function(){
      $j(this).addClass('hover');
   },function(){
      $j(this).removeClass('hover');   
   }).addClass('opener');
   $j('#wrapper.sitemap #content ol>li.main ul ul').each(function(){
      var elementHeight = $j(this).outerHeight(); 
      $j(this).hide();
      $j(this).parent().find('.opener').toggle(function(){
         $j(this).parent().addClass('open').find('ul').animate({height:elementHeight,opacity:'show'});
      },function(){
         $j(this).parent().removeClass('open').find('ul').slideUp(function(){
            $j(this).height('');
         });
      });      
   });
   
 
   // new window script
   //$j("#columnwrapper a[href*=.pdf],#columnwrapper a[href*=http]:not('[href*=#]')").live("click", function(){
   $j("#columnwrapper a[href*=.pdf],  #columnwrapper a.newwindow").live("click", function(){
	if (! $j(this).parents().filter('.tweekoloms').length){
	   	window.open(this.href);
   		return false;
	}
   });
   
	
	//save the prev url in a cookie so the coursefinder can check te prev url to determite if the querystring values should be used.
	//if ($j.cookie("prevUrl")) 
	//{
//		prevUrl = $j.cookie("prevUrl");
//	}


//save the prev url in a cookie so the coursefinder can check the prev url to determite if the querystring values should be used.
	if ($j.cookie("prevUrl")) 
	{
		prevUrl = $j.cookie("prevUrl");
	}
	else{
		prevUrl = '';
	}


	$j.cookie("prevUrl", window.location.pathname, { expires: 0, domain: '.itc.nl', path: '/' });

	//We only need to load the coursefinder if this is the coursefidner page
	if($j('#wrapper.coursefinder #courseFinder #CourseFinderLists').length != 0){
		loadCourseFinder(1);	
	}

});

