$(document).ready(function() 
{
	init();
});

function createEmailBySplit(splitString)
{
	var eParts 		= base64_decode(splitString.split(' ')[1]).split('|');
	return eParts[0] + '@' + eParts[1] + '.' + eParts[2];
}

function init()
{
	$('#nav li:last').addClass('last');
	$('#breadcrumbs li a').before('<span>&raquo;</span> ');
	
	/* emailadressen beschermen */
	$('span.eprotecttext').each( function(i)
	{
		$(this).text( createEmailBySplit( $(this).attr('class') ) );
	});	
	$('span.eprotectlink').each( function(i)
	{
		var mailtoLink	= '<a href="mailto:' + createEmailBySplit( $(this).attr('class') ) + '">' + $(this).text() + '</a>';
		$(this).html(mailtoLink);
		$(this).removeAttr('title');
	});	
	
	if ( ( window.location + '' ).indexOf('sProductSearch=') !== -1)
	{
		$('#text').html('<h1>Search results</h1><img src="/beheer/file/img/ico/loading18.gif" alt="" /> <strong>Loading...</strong>');
		sSearch	= ( window.location + '' ).split('sProductSearch=')[1];
		$.get('/file/js/productsearch.php', { sProductSearch: sSearch, url: $('form#productsearch').attr('action') },
			function(data){
				$('#text').html('<h1>Search results</h1>' + data);
			});
	}
	
	$('form#productsearch').submit( function () {
		var sSearch	= $('input[name=sProductSearch]').val();
		
		window.location = $('#nav li:eq(2)').find('a:first').attr('href') + '?sProductSearch=' + sSearch;
		
		return false;
	} );
	
	/* links en buttons */
	$('a[rel=external]').each( function(i)
	{
		$(this).attr('target', '_blank');
		$(this).addClass('external');
	});
	if ( $('#content').length > 0 )
		$('a[rel=lightbox]').lightBox();
	
	$('#nav > li').hover( function () {
		$(this).addClass('hover');
		$(this).find('> a').addClass('hover');
	}, function () {
		$(this).removeClass('hover');
		$(this).find('> a').removeClass('hover');
	} );
	
	$('#slider').cycle({ 
		fx:    'fade', 
		timeout: 6000,
	 });

};
