function preload() {
// Preload all images
	preload_images('http://www.trouw.nl/trouw.nl/images/logo.gif', 'http://www.trouw.nl/trouw.nl/images/pijl.gif', 'http://www.trouw.nl/trouw.nl/images/pijl_lx.gif', 'http://www.trouw.nl/trouw.nl/images/pijlnaarlx.gif', 'http://www.trouw.nl/trouw.nl/images/4kant_middel.gif');

// Preload all backgrounds images
	preload_images('http://www.trouw.nl/trouw.nl/images/backgrounds/bckgrnd_blauw.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/bckgrnd_grijs.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/bckgrnd_wit.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/backgrounds/pixel_hor.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/pixel_ver.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/pixel_hor_red.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/pixel_ver_red.gif' , 'http://www.trouw.nl/trouw.nl/images/backgrounds/background_columns.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/backgrounds/dotlezersreacties.gif', 'http://www.trouw.nl/trouw.nl/images/backgrounds/background_webshop_banners.gif');

// Preload all menu images
	preload_images('http://www.trouw.nl/trouw.nl/images/menu/hetMenu.gif', 'http://www.trouw.nl/trouw.nl/images/menu/hetNieuws.gif', 'http://www.trouw.nl/trouw.nl/images/menu/deVerdieping.gif', 'http://www.trouw.nl/trouw.nl/images/menu/deGids.gif', 'http://www.trouw.nl/trouw.nl/images/menu/Service.gif', 'http://www.trouw.nl/trouw.nl/images/menu/rollover.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/menu/breaking_news.gif', 'http://www.trouw.nl/trouw.nl/images/menu/breaking_news_rollover.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/menu/full_hetMenu.gif', 'http://www.trouw.nl/trouw.nl/images/menu/full_hetNieuws.gif', 'http://www.trouw.nl/trouw.nl/images/menu/full_deVerdieping.gif', 'http://www.trouw.nl/trouw.nl/images/menu/full_deGids.gif', 'http://www.trouw.nl/trouw.nl/images/menu/full_Service.gif', 'http://www.trouw.nl/trouw.nl/images/menu/full_rollover.gif');

// Preload all icon images
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/AAA_active.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AAA.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AAA_active_over.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AAA_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/AA_active.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AA.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AA_active_over.gif', 'http://www.trouw.nl/trouw.nl/images/icons/AA_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/A_active.gif', 'http://www.trouw.nl/trouw.nl/images/icons/A.gif', 'http://www.trouw.nl/trouw.nl/images/icons/A_active_over.gif', 'http://www.trouw.nl/trouw.nl/images/icons/A_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/back.gif', 'http://www.trouw.nl/trouw.nl/images/icons/back_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/betaald_nieuws.gif', 'http://www.trouw.nl/trouw.nl/images/icons/betaald_nieuws_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/blijfopdehoogte.gif', 'http://www.trouw.nl/trouw.nl/images/icons/blijfopdehoogte_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/email.gif', 'http://www.trouw.nl/trouw.nl/images/icons/email_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/meerartikelen.gif', 'http://www.trouw.nl/trouw.nl/images/icons/meerartikelen_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/meerlaatstenieuws.gif', 'http://www.trouw.nl/trouw.nl/images/icons/meerlaatstenieuws_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/next.gif', 'http://www.trouw.nl/trouw.nl/images/icons/next_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/pda.gif', 'http://www.trouw.nl/trouw.nl/images/icons/pda_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/pdf.gif', 'http://www.trouw.nl/trouw.nl/images/icons/pdf_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/print.gif', 'http://www.trouw.nl/trouw.nl/images/icons/print_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/radio.gif', 'http://www.trouw.nl/trouw.nl/images/icons/radio_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/reageer.gif', 'http://www.trouw.nl/trouw.nl/images/icons/reageer_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/sluit_menu.gif', 'http://www.trouw.nl/trouw.nl/images/icons/sluit_menu_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/steluwvraag.gif', 'http://www.trouw.nl/trouw.nl/images/icons/steluwvraag_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/stuurdoor.gif', 'http://www.trouw.nl/trouw.nl/images/icons/stuurdoor_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/video.gif', 'http://www.trouw.nl/trouw.nl/images/icons/video_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/voegreactietoe.gif', 'http://www.trouw.nl/trouw.nl/images/icons/voegreactietoe_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/xml.gif', 'http://www.trouw.nl/trouw.nl/images/icons/xml2_over.gif', 'http://www.trouw.nl/trouw.nl/images/icons/xml_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/zoekgerelateerd.gif', 'http://www.trouw.nl/trouw.nl/images/icons/zoekgerelateerd_over.gif');
	preload_images('http://www.trouw.nl/trouw.nl/images/icons/zoekinsite.gif', 'http://www.trouw.nl/trouw.nl/images/icons/zoekinsite_over.gif');
}

function preload_images() {
	if (document.images) {
		var imgFiles = preload_images.arguments;
		if (document.preloadArray==null) {
			document.preloadArray = new Array();
			}
		var j = document.preloadArray.length;
		for (var i=0; i<imgFiles.length; i++) {
			j = document.preloadArray.length;
			document.preloadArray[j] = new Image;
		    document.preloadArray[j].src = imgFiles[i];
		  }
	}
}

function addIconEvents(){
	var aElements = document.getElementsByTagName('A');
	for (i = 0; i < aElements.length; i ++){
		var currentElement = aElements[i];
		var hasIcons = false;

		var currentElementImages = currentElement.getElementsByTagName('IMG');
		for (j = 0; j < currentElementImages.length; j ++){
			var currentImage = currentElementImages[j];
			if (currentImage.id == 'icon' || currentImage.className == 'icon') {var hasIcons = true;}
		}

		if (hasIcons) {
			// Add event.
			if ( typeof window.addEventListener != "undefined" ) {
				currentElement.addEventListener( "mouseover", iconEvent, false );
				currentElement.addEventListener("mouseout", iconEvent, false);
			} else if ( typeof window.attachEvent != "undefined" ) {
				currentElement.attachEvent( "onmouseover", iconEvent );
				currentElement.attachEvent( "onmouseout", iconEvent );
			}
		}
	}
}

function current_onMouseOver(currentImage) {
	if (currentImage.id == 'icon' || currentImage.className == 'icon') {
		var imageSRC = currentImage.src;
		var filenamePath = imageSRC.substring(0,imageSRC.lastIndexOf("/")+1);
		var filename = imageSRC.substring(imageSRC.lastIndexOf("/")+1, imageSRC.lastIndexOf("."));

		if (filename.lastIndexOf("_over") > 0) {
			filename = filename.substring(0, filename.lastIndexOf("_over")) + '.gif';
		} else {
			filename = filename + '_over.gif';
		}
		currentImage.src = filenamePath + filename;
	}
}

function iconEvent(e){
	var currElement = (e.target) ? e.target : e.srcElement;
	if (currElement.tagName == 'IMG') {
		var currentImage = currElement;
		current_onMouseOver(currentImage);
	} else {
		var currentElementImages = currElement.getElementsByTagName('IMG');
		for (j = 0; j < currentElementImages.length; j ++){
			var currentImage = currentElementImages[j];
			current_onMouseOver(currentImage);
		}
	}
}

function swapImage(currElement, image) {
	if ( currElement && image ) {
		currElement.src = image;
	}
}

function DivShim(DivRef,IfrRef) {
	if (!document.layers) {
		var DivRef = document.getElementById(DivRef);
		var IfrRef = document.getElementById(IfrRef);
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		DivRef.style.zIndex = 500;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
	}
}

function JSFX_FloatTopDiv(wrapper)
{
	/*
	Floating Menu script-  Roy Whittle (http://www.javascript-fx.com/)
	Script featured on/available at http://www.dynamicdrive.com/
	This notice must stay intact for use
	*/

	//Enter "frombottom" or "fromtop"
	var verticalpos="fromtop";
	var startX = 15,
	startY = 75;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if ( el ) {
			if(d.layers)el.style=el;
			el.sP=function(x,y){this.style.left=x;this.style.top=y;};
			el.x = startX;
			if (verticalpos=="fromtop")
			el.y = startY;
			else{
			el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			el.y -= startY;
			}
			return el;
		}
	}
	window.stayTopLeft=function(scrollHistory) {
		// Solution for form select elements problem.
		DivShim('menu_wrapper', 'DivShim');

		if (!document.documentElement.scrollTop)
			scrollY = document.body.scrollTop;
		else
			scrollY = document.documentElement.scrollTop;

		if (scrollHistory && scrollHistory != scrollY) {
			// The menu is scrolling.
			menu('close');
		}

		if (scrollY > startY) {
			this_startY = 0;
		} else if (scrollY < startY) {
			this_startY = startY - scrollY;
		} else {
			this_startY = startY;
		}

		if (verticalpos=="fromtop"){
			var pY = ns ? pageYOffset : document.body.scrollTop;
			ftlObj.y += (pY + this_startY - ftlObj.y)/8;
		} else {
			var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			ftlObj.y += (pY - this_startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft(scrollY)", 1);
	}
	ftlObj = ml(wrapper);
	if ( ftlObj ) {	stayTopLeft(); }
}

function menu(action) {
		var closed = document.getElementById('closed_menu');
		var opened = document.getElementById('opened_menu');

		if (closed && opened) {
			if (action == 'close') {
				opened.style.visibility = 'hidden';
				opened.style.display = 'none';
				closed.style.visibility = 'visible';
				closed.style.display = 'block';
			} else if (action == 'open') {
				closed.style.visibility = 'hidden';
				closed.style.display = 'none';
				opened.style.visibility = 'visible';
				opened.style.display = 'block';
			}
		}
		return false;
}

/*
	http://www.alistapart.com/articles/alternate/
*/
function setActiveStyleSheet(title, setOver) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("media") == 'all' ) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  setActiveIcon(setOver);
}

function setandPrint(element, bla) {
	if (element && bla) {
		currentElement = document.getElementById(element);
		if (currentElement) {
			currentElement.className = bla;
		}
	}
	window.print();
}

function setActiveIcon(setOver) {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if ( a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") ) {

			var currentImage = document.getElementById(a.getAttribute("title"));
			if (currentImage) {
				var imageSRC = currentImage.src;
				var filenamePath = imageSRC.substring(0,imageSRC.lastIndexOf("/")+1);
				var filename = imageSRC.substring(imageSRC.lastIndexOf("/")+1, imageSRC.lastIndexOf("."));
				if (filename.lastIndexOf("_over") > 0) {
					filename = filename.substring(0, filename.lastIndexOf("_over"));
				}
				if (!a.disabled && setOver) {
					// Stylesheet is on.
					filename = filename + '_over.gif';
				}
				else {
					filename = filename + '.gif';
				}
				currentImage.src = filenamePath + filename;
			}
		}
	}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("media") == 'all' && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function stylesheetCookie(action) {
	if ( action == 'read' ) {
		var cookie = readCookie("style");
		var title = cookie ? cookie : getPreferredStyleSheet();
		if (title) {
			setActiveStyleSheet(title, true);
		}
	}
	else if ( action == 'write' ) {
		var title = getActiveStyleSheet();
		if (title) {
			createCookie("style", title, 365);
		}
	}
}

function onloadFunctions() {
	menu('close');
	JSFX_FloatTopDiv("menu_wrapper");
	stylesheetCookie('read');
	addIconEvents();
	//preload();
}

window.onunload = function(e) {
	stylesheetCookie('write');
}

function trouwPopUp(URL,TITLE,TOOLBAR,SCROLLBAR,LOCATIONBAR,STATUS,MENUBAR,RESIZABLE,POPUPWIDTH,POPUPHEIGHT) {
	var pup=window.open(URL,"popup","toolbar="+TOOLBAR+",scrollbars="+SCROLLBAR+",location="+LOCATIONBAR+",status="+STATUS+",menubar="+MENUBAR+",resizable="+RESIZABLE+",width="+POPUPWIDTH+",height="+POPUPHEIGHT+"");
	pup.focus;
	}