$(document).ready(function() 
{
	init();
});

function createEmailBySplit(splitString)
{
	var eParts 		= base64_decode(splitString.split(' ')[1]).split('|');
	return eParts[0] + '@' + eParts[1] + '.' + eParts[2];
}

function init()
{
	/*$('a.skip').focus( function () { $(this).addClass('focus'); });
	$('a.skip').blur( function () { $(this).removeClass('focus'); });*/
	
	/* 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');
	});	
	$('#defaulttpl,#textrighttpl').css('height', parseInt( $('#defaulttpl img,#textrighttpl img').attr('alt') ) + 'px');
	
	/* links en buttons */
	$('input[type=submit]').addClass('button');
	$('a[rel=external]').each( function (i)
	{
		if ( !$(this).find('img').attr('src') )
		{
			var aText 		= $(this).html();
			var lastSpace	= aText.lastIndexOf(' ');
			if ( lastSpace > 0 )
				$(this).html( aText.substring(0,lastSpace) + ' <span class="external">' + aText.substring(1+lastSpace) + '</span>' );
			else
				$(this).html( '<span class="external">' + aText + '</span>' );
		}
	});	
	
	$('#hometext > ul:first,#hometext > ol:first').addClass('home');
	$('ul.home li:last,ol.home li:last').addClass('last');
	$('#hometext .home li').each( function(i)
	{
		if ( typeof $(this).find('a').attr('href') != 'undefined' )
		{
			var href	= $(this).find('a').eq(0).attr('href');
			var text	= $(this).find('a').eq(0).text();
			$(this).find('a').eq(0).replaceWith( $(this).find('a').eq(0).text() ); // link weer verwijderen
			$(this).prepend('<a href="' + href + '" class="more"><span>' + text + '</span></a>');			
		}
	});
	
	$('#newsticker').liScroll({travelocity: 0.05}); 
	
	if ( $('#largeheader').length > 0 )
		$('#header').css('background-image', "url('/file/img/web/rte/" + $('#largeheader').attr('class') + "')");
	else if ( $('#headers').length > 0 )
	{
		$('.imgs').cycle({
			fx: 'fade',
			timeout: 5000
		});
	}

	/*$('#headers div,#headers li').each( function(i)
	{
		$(this).css('background', "url('/file/img/web/rte/" + $(this).attr('class') + "') no-repeat left top");
	});*/
	
	$('a[rel=external]').each( function(i)
	{
		$(this).attr('target', '_blank');
		$(this).addClass('external');
	});
	if ( $('#content').length > 0 )
		$('a[rel=lightbox]').lightBox();
		
	$('#navigation > li').hover( function () {
		$(this).addClass('hover');
		$(this).find('> a').addClass('hover');
	}, function () {
		$(this).removeClass('hover');
		$(this).find('> a').removeClass('hover');
	} );
	
	if ( $('iframe').length > 0 && $('iframe:eq(0)').attr('src').indexOf('buienradar') >= 0 )
	{
		$('#container').prepend('<div id="marker"></div>');
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6 ) {
			$('div#marker').attr('id', 'markerie6');
		}
	}
	
	$('#content').append('<div id="totop"><a href="#container"><span>Return to top</span></a></div>')
	
	if ( $('#slideshow').length > 0 && $('#slideshow li').length > 4 )
	{
		$('#carouselwrap').after('<a href="#" class="carouselprev" title="Vorige"><span>vorige</span></a>'
							+ '<a href="#" class="carouselnext" title="Volgende"><span>volgende</span></a>');
		
		$('.carousel').jCarouselLite({
			visible: 4,
			scroll: 4,
			btnNext: ".carouselnext",
			btnPrev: ".carouselprev"
			/*hoverPause:true,
			auto: 2000,
			speed:400*/
		});
	}

};
