Shadowbox.init({
	players:["img","html","iframe"],
	skipSetup: true
});

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

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

function init()
{
	$('#breadcrumbs li a:gt(0)').before('<span>/</span> ');
	$('.collectie #kaders a').append(' &raquo;');
	
	$('#items li').each(function(){
		if ( $(this).find("p a").length > 0 )
		{
			$(this).find("a").html('Meer informatie &raquo;');
			$(this).click(function(){
				window.location=$(this).find("a").attr("href");return false;
			});
		}
	});
	$('#reacties q').each(function(){
		$(this).css('cursor', 'pointer');
		$(this).click(function(){
				window.location=$('#reacties a').attr("href");return false;
		});
	});
	$('.slider li,.homewrap li,.pad,.homewrap div > p,div.columns div').each(function(){
		if ( $(this).find('a').attr('href') )
		{
			$(this).css('cursor', 'pointer');
			$(this).click(function(){
				window.location=$(this).find('a').attr('href');return false;
			});
		}
	});
	
	$('#prevnext .prev a').html('&laquo; vorige');
	$('#prevnext .next a').html('volgende &raquo;');
	
	$('#items li,#navigation > li,.homewrap li,.homewrap div > p, .pad,div.columns div').hover( function(){
		$(this).addClass( ( $(this).hasClass('subs') ? 'subshover': 'hover' ) );
	}, function() {
		$(this).removeClass( ( $(this).hasClass('subs') ? 'subshover': 'hover' ) );
	});

	/* 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');
	});	
	
	$('[rel=external],.external').attr('target', '_blank');
	$('.portfolio a.more').html('Lees verder &raquo;');
	
	if ( $('.slider').length > 0 )
	{
		$('.slider').each(function()
		{
			var sId	= $(this).attr('id');
			$('#' + sId).before('<div class="slidenav" id="nav' + sId + '"></div>').cycle({
			//$('#' + sId).cycle({
				fx: 'fade',
				timeout: 5000,
				pager:  '#nav' + sId,
				pause: 1 
			});
			$('.thumbholder #' + sId + ' li img').each(function(i)
			{
				var src	= $(this).attr('src').replace('slider/', 'slider/thumb/');
				$('#nav' + sId + ' a').eq(i).html('<img src="' + src + '" alt="" />');
			});
		});
	}
	
	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
    });

	
	$('#trefwoord').each( function() {
		if ( $(this).attr('title') != '' )
		{
			var sTitle	= $(this).attr('title') + '...';
			if ( $(this).val() == '' )
				$(this).val( sTitle );

			$(this).focus(function () {
				if ( $(this).val() == sTitle )
					$(this).val('');
			});
			$(this).blur(function () {
				//alert( $(this).val() );
				if ( $(this).val() == '' )
					$(this).val(sTitle);
			});
		}
	});
	$('#telnrs form').submit( function() {
		if ( $('#trefwoord').val() == $('#trefwoord').attr('title') + '...' )
			$('#trefwoord').val('');
	});
	
	$('#content > form.routeform').css('width', '520px');
	$('#content > form.routeform .submit').after('van <input type="text" style="width: 170px;" name="from" value="" /> naar ');
	
	$('form.routeform').submit( function() {
		Shadowbox.open({player:'iframe',content:'http://maps.google.nl/?q=' 
			+ ( typeof $(this).find('[name=from]').val() == 'undefined' || $(this).find('[name=from]').val() == '' ? 
				'': 'from:' + $(this).find('[name=from]').val() + ',Nederland+' )
			+ $(this).find('select').val(),title:'Plan uw route naar Wiechers Wonen'}); 
		return false;
	});

};
