$(document).ready(function() 
{
	init();
});

function createEmailBySplit(splitString)
{
	var eParts 		= base64_decode(splitString).split('|');
	return eParts[0] + '@' + eParts[1] + '.' + eParts[2];
}

// backwards compatible
function doPopup(sTarget, iHeight, iWidth)
{
	iHeight	= iHeight ? iHeight: 350;
	iWidth	= iWidth ? iWidth: 300;
	window.open('', sTarget, 
		'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=' + iWidth + ', height=' + iHeight);
}

function protectEmailadresses()
{
	$('span.eprotecttext').each( function(i)
	{
		$(this).text( createEmailBySplit( $(this).attr('alt') ) );
		$(this).attr('alt', '');
	});	
	$('span.eprotectlink').each( function(i)
	{
		var mailtoLink	= '<a href="mailto:' + createEmailBySplit( $(this).attr('alt') ) + '">' + $(this).text() + '</a>';
		$(this).html(mailtoLink);
		$(this).attr('alt', '');
		$(this).attr('title', '');
	});	
}

function init()
{
	/* emailadressen beschermen */
	protectEmailadresses();
	
	/* content replacing */
	var sContent	= $('#content').html();
	$('#content').remove();
	$('#main hr:last').before('<div id="content" style="position: relative;">' + sContent + '</div>');
	
	/* links en buttons */
	$('input[type=submit]').addClass('button');
	$("input[name*='jaar'],input[name*='aantal'],input[name*='rente']").css('width', '27px');
	//$("input:parent:contains('EUR')").css('background-color', '#fc0');
	$('input[type=text]').each( function(i)
	{
		if ( $(this).parent().html().indexOf('EUR', 0) >= 0 )
			$(this).css('width', '50px');
	});
	
	// IE6 : fixed with for anchors
	if ( jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 )
	{
		$('#navigation a').each( function(i)
		{
			$(this).css('width', parseInt( $(this).text().length * 8 ) + 'px');
		});
	}
	
	$('div.sub ul a, ul.sub a').each( function(i)
	{
		$(this).append(' &gt;');
	});
	
	$('#blocks li').each( function(i)
	{
		if ( $(this).find('a').attr('href') )
		{
			$(this).css('cursor', 'pointer');
			$(this).click(function() {
				window.location=$(this).find('a').attr('href');return false;
			});
		}
	});

	/*var sSub	= $('div.sub').html();
	$('div#sub').html( sSub + '&nbsp;<hr class="clear" />' );*/
	if ( $('div#sub').length == 0 )
		$('div#sub').css('padding-bottom', '0px');
		
	/*$('div.sub').hide().remove();*/
	$('#container').append('<div id="hide" style="height: ' + document.getElementById("sub").offsetHeight + 'px;"></div>');
	
	$('a[@rel=external]').each( function(i)
	{
		$(this).attr('target', '_blank');
		if ( $(this).find('img').length == 0 )	// afbeeldingen moeten de class niet meekrijgen
			$(this).addClass('external');
	});
	$('#form table.show tr:odd').addClass('odd'); // form row coloring
	
	if ( $('#content').length > 0 )
		$('a[rel=lightbox]').lightBox();
	
};
