Shadowbox.init({
	players:["img","html","iframe"],
	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', '');
	});	
	$('a.info').html('meer informatie over dit project &raquo;');
	
	$('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');
	});
	
	$('li.skype a').attr('href', 'skype:marioolivier?call');
}

function init()
{	
	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
    });
	
	var strSplit = $('#header').attr('class').split(':');
	
	$(document).bgStretcher({
		images: [strSplit[0]], imageWidth: strSplit[1], imageHeight: strSplit[2]
	});
	
	$('.slider').each(function(i)
	{
		$(this).before('<ul id="nav' + i + '" class="nav">') 
			.cycle({ 
				fx:     'fade', 
				speed:   300, 
				timeout: 3000, 
				pager:  '#nav' + i ,
				pagerAnchorBuilder: function(idx, slide) { 
					return '<li><a href="#"><span>' + (1+idx) + '</span></a></li>'; 
				}
			});
	});
	
	$('#cyclenav').cycle({ 
		fx:     'scrollHorz', 
		speed:  'slow', 
		timeout: 0, 
        prev:    '#prev',
        next:    '#next',
		pager:  '#num' 
	});
	if ( $('#cyclenav > li').length < 2 )
		$('#nav #next, #nav #prev').css('display', 'none');	
};

	function customFB()
	{
		var showSend = false;
		FB.Event.subscribe('auth.login', function(response) {
			accessToken	= response.authResponse.accessToken;
			FB.api('/me', function(response) {
				showSend = fillFBform(response, accessToken);
			});
		});
		/*FB.Event.subscribe('auth.logout', function(response) {
			alert('You have successfully logged out!');
		});*/
		FB.getLoginStatus(function(response) {
			if (response.authResponse) {
				accessToken	= response.authResponse.accessToken;
				FB.api('/me', function(response) {
					showSend = fillFBform(response, accessToken);
				});
			}
		});
		
		if ( !showSend )
			$('#reactieform input.button').hide();
	}

function fillFBform(response, accessToken)
{
	//if ( $('input#naam').val() == '' || $('input#naam').val() == 'Anoniem' )
		$('input#naam').attr('value', response.name);
		
	//if ( $('input#emailadres').val() == '' )
		$('input#emailadres').attr('value', response.email);
		
	//if ( $('input#website').val() == '' )
	/*var userWebsite = response.website == '' ? 'http://www.facebook.com/profile.php?id=' + response.id: response.website;
		$('input#website').attr('value', response.website);*/

	if ( $('input[name=facebookid]').val() == '0' )
		$('input[name=facebookid]').val(response.id);
	
	$('input[name=timestamp]').attr('value', accessToken);
		
	$('div.fb-login-button').hide();
	$('#reactieform input.button').show();
	return true;
}
