Cufon.replace('.block h2');

(function($) {

	// jQuery searchValue 1.0
	$.fn.searchValue=function(){var a=$(this);var b=a.val();a.focus(function(){if(a.val()==b)a.val('')});a.blur(function(){if(a.val()=='')a.val(b)});return this};
	
	// jQuery imageHover 1.0 - aangepast na update image URL's
	$.fn.imageHover=function(d){var d=$.extend({className:'overlay',format:'overlay',opacity:1,inSpeed:1000,outSpeed:1000},d);function hide(a){a.hide();a.css('opacity',0)};function fadeIn(a){a.stop();a.show();a.fadeTo(d.inSpeed,d.opacity)};function fadeOut(a){a.stop();a.fadeOut(d.outSpeed,function(){hide(a)})};return this.each(function(){var a=$(this);var b=a.children('img');var c=b.clone();c.attr('src',replaceFormat(c.attr('src'),d.format));c.addClass(d.className);hide(c);a.hover(function(){fadeIn(c)},function(){fadeOut(c)});a.append(c)})};

})(jQuery);

function replaceFormat(source, format) {
      var protocol='';
      if(source.indexOf('http://')>-1) {
            protocol='http://';
            source=source.replace('http://','');
      }else if(source.indexOf('https://')>-1) {
            protocol='https://';
            source=source.replace('https://','');
      }
      source=source.split('/');
      source[3]=format;
      return protocol+source.join('/');  
};

function _enhanceTabs() {
	
	var tabs = $('.tabs'),
		id = tabs.attr('id'),
		
		buttons = tabs.find('h2 a');
	
	tabs.tabs({
		addClass : 'js',
		start : start
	});

};

$(function() {
	
	// Vers van de pers
	var books = $('.new-books'),
		elements = books.find('.element');
	if(elements.length > 1) {
		elements.cycle({
			keep : true,
			navigation : '#link-navigation',
			nextLabel : '',
			previousLabel : ''
		});
	};

	// Evenementen voorpagina
	var events = $('.events'),
		elements = events.find('.element');
	if(elements.length > 1) {
		elements.cycle({
			keep : true,
			navigation : '#events-navigation',
			nextLabel : '',
			previousLabel : ''
		});
	};
	
	// Set up menu slide
	$('.navigation.main  > li').menu({
		dropdown : '.subnavigation',
		effect : 'slideDown',
		duration : 200,
		ignoreDummy : true,
		swapClass : 'none'
	});
	
	$('.navigation.main ul:last').css('left', '-165px');
	
	$('#search input[type=text]').searchValue();
	
	// Voorpagina navigatie - afbeeldingen hover
	$('ul.front li a.element').imageHover({
		format : 'front-navigation-hover',
		inSpeed : 200,
		outSpeed : 300
	});

	
	
	// Setup tabs related
	var tabs = $('.related');
	if(tabs.length > 1){
		var wrapper = $('<div class="related-wrapper" />');
		var navigation = $('<div class="tabs-navigation" />');
		var relatedtitle = $('<p id="related-wrapper-title" />');
		wrapper.insertAfter(tabs.eq(1));
		wrapper.append(navigation);
		wrapper.append(tabs);
		wrapper.append(relatedtitle);
		
		wrapper.tabs({
			title : 'h2',
			page : '.related'
		});
	};
	
	var title = $('#related-title');
	$('.related a').bind('mouseover',function(){
		title.html($(this).attr('title'));
	});
	
	var wrappertitle = $('#related-wrapper-title');
	$('.related-wrapper .related a').bind('mouseover',function(){
		wrappertitle.html($(this).attr('title'));
	});
	
	var headings = $('.related-wrapper h2').bind('click',function(){
		$('#related-wrapper-title').html('');
	});
	
	// Setup authors
	$('#books .element').each(function(){
		$(this).find('.people a:not(:last)').after(', ');
	});
	
	$('#book .result.authors a:not(:last)').after(', ');
	
	$('.new-books .element').each(function(){
		$(this).find('.details a:not(:last)').after(', ');
	});
	
	// Tell a friend
	var taf = $('#taf');
	
	$('#taf-button').click(function(event) {
		taf.toggle();
		event.preventDefault();
	});
	
	var opinion = $('#opinion');
	
	$('#opinion-button').click(function(event) {
		opinion.toggle();
		event.preventDefault();
	});
	
});
