var basehref;
var site_base_url;

var fancySettings = {
	'hideOnContentClick':	false,
	'cyclic'			:	true,
	'margin'			:	60,
	'centerOnScroll'	:	true,
	'overlayOpacity'	:	0.8,
	'overlayColor'		:	'#b4b0af',
	'speedIn'			:	600, 
	'speedOut'			:	200, 
	'overlayShow'		:	true,
	'showCloseButton'	:	true,
	'titlePosition' 	:	'inside',
	'titleFormat'		:	formatTitle
}

$(document).ready(function()
{
	
	// set base url var
	basehref = $('base').attr('href');
	site_base_url = basehref;
	
	/* Fancybox Using custom settings */
	$('a.thickbox:has(img)',$('div',$('#page .pagecontent'))).fancybox(fancySettings);
	
	// PIR font replacement
	$.pir.options.php = basehref+"pir.php";
	// PHP->HTML output trimmen....zucht....
	$("body div#page.homepage div.main-column .pagecontent .folder h4")
	.each(function(){
		$(this).replaceWith($('<h4/>').html( $.trim( $(this).html() ) ));
	});
	// pirren maar
	$("body div#page.homepage div.main-column .pagecontent .folder h4").pir({font: "UniversLTStd-BoldCn.otf", wrap: true});
	
	
	// print functie
	if($('#specialmenu ul.special').length){
		
		$('#specialmenu ul.special')
		.prepend(
			$('<li/>')
			.addClass('print')
			.prepend( 
				$('<a href="#print">print</a>')
				.click(function() {
					window.print();
					return false;
				})
			)
		);
			
	} else {
		$('#specialmenu')
		.prepend(
			$('<ul/>')
			.addClass('special')
			.prepend(
				$('<li/>')
				.addClass('print')
				.prepend( 
					$('<a href="#print">print</a>')
					.click(function() {
						window.print();
						return false;
					})
				)
			)
		);
	};

	// searchpanel
	$('a.button',
		$('form.search fieldset .search_wrapper')
		.append(
			$('<span/>')
			.addClass('search_wrappertext')
			.html('Zoeken...')
			.css({
				'position':'absolute',
				'top':'3px',
				'left':'22px'
			})
		)
	)
	.css({'display':'inline','cursor':'hand'})
	.hover(
	  function () {
		$(this).addClass('active');
	  }, 
	  function () {
		$(this).removeClass('active');
	  }
	)
	.click(function() {
		var sField = $('input.search_field',$(this).parent('div'));
		if(!sField.val() == ''){
			SearchFormSubmit();
		}
		return false;
	});
	
	// searchpanel
	if( $('.search_wrapper input').val() != '' ){
		$('.search_wrappertext').hide();
	}
	$('.search_wrappertext,.search_wrapper input')
	.mouseenter(function(){
		searchformUsed();
	})
	.mouseleave(function(){
		searchformStandBy()
	})
	.focus(function(){
		searchformUsed();
	})
	.focusout(function(){
		searchformStandBy()
	})
	.keydown(function(){
		searchformUsed();
	});
	// searchpanel
	function searchformStandBy(){
		if( $('.search_wrapper input').val() == '' ){
			$('.search_wrappertext').show();
		}
	}
	function searchformUsed(){
		$('.search_wrappertext').hide();
	}
	
	// submit searchform function
	function SearchFormSubmit(){
		$('form.search').submit();
		return false;
	}


	
});


function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}


function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="fancydescription">' + (title && title.length ? '<b>' + title + '</b><br/>' : '' ) + (currentArray.length > 1 ? '<span id="fancypagecount"><a href="javascript:;" onclick="$.fancybox.prev();">&#8249;&#8249; prev </a> &#160; Image ' + (currentIndex + 1) + ' of ' + currentArray.length + ' &#160; <a href="javascript:;" onclick="$.fancybox.next();"> next &#8250;&#8250;</a></span>' : '') +'</div>';
}


$.easing.custom = function (x, t, b, c, d) { 
    var s = 1.70158;  
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
}