Shadowbox.init({
	skipSetup: true
});

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

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

function cmsFunctions()
{	
	/* 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', '');
	});	
	
	/* links en buttons */
	$('input[type=submit]').addClass('button');	
	$('a[rel~="external"]').each (function(i)
	{
		$(this).attr('target', '_blank');
		$(this).addClass('external');
	});
	
	/*if ( $('#content').length > 0 )
		$('a[rel=lightbox]').lightBox();*/
		
	if ( typeof $('#header').attr('class') != 'undefined' )
		$('#container > div.wrapper').css('background-image', "url('" + $('#header').attr('class') + "')");
}

function init()
{
	$('#footer li:first').addClass('first');
	// dropdown nav
	$('#navigation li').hover(
		function() { $(this).addClass('iehover'); },
		function() { $(this).removeClass('iehover'); }
	);	
	
	$('#producten li').each (function(i)
	{
		var sUrl = $(this).find('a').attr('href');
		var sTitle = $(this).find('a').attr('title');
		$(this).find('a').attr('href', '#');
		$(this).find('a').removeAttr('rel');
		$(this).wrapInner('<a href="' + sUrl + '" title="' + sTitle + '" rel="shadowboxgal"></a>');
	});
	Shadowbox.setup("a[rel*='shadowbox']", {
		language: 'nl',
		enableKeys: false,
		players:  ['img', 'html', 'iframe', 'swf', 'flv'],
		autoplayMovies: false,
		continuous: true,
		counterLimit: 0,
		counterType: 'skip',
		handleOversize: 'drag'
	});
    Shadowbox.setup("a[rel*='shadowboxgal']", {
        gallery: 'gallery',
		counterLimit: 0,
		counterType: 'default',
		handleOversize: 'resize',
		continuous: true
    });
	
	pagination();

};

function pagination()
{
	var wrap = $('#producten');

	// set up click events to trigger the pagination plugins' behaviour

	$('.prev').click(function(){
		wrap.trigger('prev.evtpaginate');
		return false;
	});

	$('.next').click(function(){
		wrap.trigger('next.evtpaginate');
		return false;
	});

	// listen out for events triggered by the plugin to update the counter

	wrap.bind( 'initialized.evtpaginate', function(e, startnum, totalnum ){
		$('#count').text(startnum);
		$('#total').text(totalnum);
	});

	wrap.bind( 'finished.evtpaginate', function(e, num, isFirst, isLast ){ $('#count').text(num); } );

	wrap.evtpaginate({perPage:12}); // call the plugin! 
}
