window.onload = function() {

	//set active nav-item
	var	current_location = document.location.toString();

	/**
	 *@todo don't forget to change the domainname when site goes live.
	 */
	var domain 		= 'http://www.nimo.nl/';

	//breadcrumbs
	var breadcrumbs = $('breadcrumbs');

	//breadcrumb seperator
	var seperator   = new Element('span', {html: '&nbsp;&raquo;&nbsp;'});

	//we are at the homepage no need to check al anchors
	if(current_location == domain) {

		$$('#nav .ul .li a')[0].addClass('active');
	}
	else {

		var pages = current_location.split('/');
		var path  = domain;


		//loop the main-nav items to check where we are.

		$$('#nav .ul .li a').each(function(el){


			if(current_location.contains($(el).href) && $(el).href != domain) {

				//set the link to active
				$(el).addClass('active');

				if($(el).get('html') == "<span>Open programma 2009</span>" || $(el).get('html') == "<span>Open programma 2010</span>" || $(el).get('html') == "<SPAN>Open programma 2009</SPAN>" || $(el).get('html') == "<SPAN>Open programma 2010</SPAN>")
				{
					InjectieHtml = "<span>Open programma</span>";
				}
				else
				{
					InjectieHtml = $(el).get('html');
				}
				//build breadcrumb trail
				if($(el).get('html') != "<span>Open programma 2010</span>" || $(el).get('html') != "<SPAN>Open programma 2010</SPAN>")
				{
					$(seperator).clone().inject(breadcrumbs, 'bottom');
					new Element('a', {title: $(el).title, href: $(el).href, html: InjectieHtml}).inject(breadcrumbs, 'bottom');
				}
				//append the third level if there is one
				if($(el).href != current_location) {

					$(seperator).clone().inject(breadcrumbs, 'bottom');

					//use document title as a title and label for the link
					var label = $$('title').get('html').toString().replace('Nimo.nl - ', '');
					if(pages[3] == "news") path	  = path+pages[3]+'/'+pages[4];
					else path	  = path+pages[3]+'/'+pages[4]+'/'+pages[5];

					new Element('a', {title: label, id: 'breadcrumb_third_level', href: path, html: label}).inject(breadcrumbs, 'bottom');
				}

				//append the fourth / fifth level if there is one
				if(pages.length > 6) {

					var previous_breadcrumb;

					pages.each(function(page){

						if(pages.indexOf(page) > 5) {

							$(seperator).clone().inject(breadcrumbs, 'bottom');
							new Element('a', {title: page, href: path+'/'+page, html: page.capitalize()}).inject(breadcrumbs, 'bottom');
						}
					});
				}

			}
		});
	}
}

function externalLinks() {
	 if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName("a");
	 for (var i=0; i<anchors.length; i++) {
	   var anchor = anchors[i];
	   if (anchor.getAttribute("href") &&
		   anchor.getAttribute("rel") == "external")
		 anchor.target = "_blank";
	 }
}