$(document).ready(function() {
	addFontScaler();
	$(document).pngFix();
	setMenuHeight();
	setHorizontalMenuImage();	
	setNewsImage();
	fixHeight(); // Resize if necessary
	
	$("a").each( 
		function(i)
		{
			if(typeof $(this).attr('title') == "undefined" || $(this).attr('title') == '')
				$(this).attr('title', $(this).text());
		}
	);
});



/**
 *	Sets the horizontal image, next to the selected menu-item
 **/
function setHorizontalMenuImage() {
	var listItem = $('#items').find('li').filter('[class=selected]');

	if(listItem.offset().top > 0) {
		var pixels = 0;
		$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
		
		if($.browser.msie && $.browser.version < 8)
			pixels = 149;
		else if($.browser.msie || $.browser.opera || $.browser.chrome)
			pixels = 148;
		else
			pixels = 148;
				
		var listHeight = listItem.offset().top - $("#subject").height() - pixels;
		$("#horizontalMenu").css("top", listHeight);
		$("#horizontalMenu").css("width", "6px");
	}
	else {
		$("#horizontalMenu").css("width", "0px");
	}
}

/**
 *	Sets the height of the menu, so that the vertical line is shown correctly
 **/
function setMenuHeight() {
	var menuHeight = $("#items").height() + $("#subject").height() - 45;
	var tabTop = $(".horizontal").position().top;

	if (menuHeight < tabTop)
		menuHeight = tabTop;

	$("#verticalMenu").height(menuHeight);
}

/**
 *	Set the news item image on the correct location
 **/
function setNewsImage() {
	try {
		var left = $("#sidebar").position().left - $("#main").position().left;
		$("#newsimage").css("left",left);
		$("#newsimage").css("top",100);
		$("#newsimage").css("z-index",$("#sidemenushadow").css("z-index")+1);
	} catch(e) {}
}

function fixHeight()
{
	// The size
	var size = 635;
	// Get the content div
	var content = document.getElementById('content');
	if(content != null)
	{
		// The diff
		var diff = content.clientHeight - size;
		// We need to expand sidebar and menu
		if(diff > 0)
		{
			// Get the bottom div section for the menu
			var bottom = document.getElementById('bottom');
			if(bottom != null)
			bottom.style.height = (bottom.clientHeight + diff) + "px";

			// Get the sidebar div
			var sidebar = document.getElementById('sidebar');
			if(sidebar != null)
			{
			sidebar.style.height = (sidebar.clientHeight + diff) + "px";

			var shadow = document.getElementById('sidemenushadow');
			if(shadow != null)
				shadow.style.height = (shadow.clientHeight + diff) + "px";
			}
		}
	}
}

/**
 *	Adds the three characters that the visitor can use to resize the text
 **/
function addFontScaler() {
	// Add the font scaler
	$("#scaler").fontScaler({
		target: '#content',
		fixed: {
			size1: '100',
			size2: '150',
			size3: '200',
			title1: 'Normaal',
			title2: 'Gemiddeld',
			title3: 'Groot'
		},
		store: true
	});

	// Add a custom event after changing font size
	$("a#fs_normal").bind("click", function(e){ window.setTimeout("fixHeight()", 350); });
	$("a#fs_medium").bind("click", function(e){ window.setTimeout("fixHeight()", 350); });
	$("a#fs_large").bind("click", function(e){ window.setTimeout("fixHeight()", 350); });
}


// serves printversion
function printWindow() 
{
   window.print();
}

/**
 *	Removes the first two '<br />'-elements from the div with id=content
 *	Should only be called on the pages of the newsarchive
 **/
function removeBreaks() {
	try {
		$("#content>br:first").remove("br");
		$("#content>br:first").remove("br");
	}
	catch(e) {}
}

