$(document).ready(function() 
{
	init();
});

function createEmailBySplit(splitString)
{
	var eParts 		= base64_decode(splitString).split('|');
	return eParts[0] + '@' + eParts[1] + '.' + eParts[2];
}

function init()
{
	$('#footer ul li:last').addClass('last');
	$('#breadcrumbs li a').before('<span>&raquo;</span> ');
	
	var chars = 0;
	$('#breadcrumbs li a').each( function (i)
	{
		chars += $(this).text().length;
	});
	if ( chars > 63 )
	{
		var items	= $('#breadcrumbs li').length - 1;
		for ( var i = 2; i < items; i++ )
		{
			var text	= $('#breadcrumbs a').eq(i).text();
			$('#breadcrumbs a').eq(i).html( ( text.length > 4 ? text.substr(0, 3) + '&hellip;': text ) );
		}
		if ( chars >= 85 && $('#breadcrumbs a').eq(items).text().length > 36 )
			$('#breadcrumbs a').eq(items).html( $('#breadcrumbs a').eq(items).text().substr(0, 34) + '&hellip;' )
	}
	
	$('ul#navigation ul a').each( function(i)
	{
		var tekst = $(this).html();
		if ( tekst.length > 17 )
			$(this).html( tekst.substring(0, 16) + '&hellip;' );
	});
	
	$('div#formklant0,div#formklant1').css( {marginLeft: '50px', display: 'none'} );
	$('input.alklant[name=alklant]').each
	(
		function(i)
		{
			var val = $(this).val();
			$(this).focus( function ()
			{
				$('div#formklant' + ( val == 0 ? 0: 1 ) ).css('display', 'block')
				$('div#formklant' + ( val == 0 ? 1: 0 ) ).css('display', 'none')
			});
			
			if ( $(this).attr('checked') == true )
				$('div#formklant' + ( val == 0 ? 0: 1 ) ).css('display', 'block')
		}
	);
	
	/* emailadressen beschermen */
	$('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', '');
	});	
	
	$('a[@rel=external]').each( function(i)
	{
		$(this).attr('target', '_blank');
		$(this).addClass('external');
	});
	
	if ( $('#content').length > 0 )
		$('a[rel=lightbox]').lightBox();
		
	$('#winkelwagen input[type=text]').blur( function() { $('form#winkelwagen').submit(); } )
	$('input.error').after(' <img src="/beheer/file/img/ico/warning.gif" />');
	
};