(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);

/* 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 replaceFormat(source, format) {
	return source.substring(0, source.indexOf('format=') + 7) + format;
};

$(function() {
	
	// Banner
	var banner = $('#banner .element');
	
	if(banner.length > 1 ){
		banner.cycle({
			keep : true,
			interval : 10000,
			navigation : '#banner-nav',
			nextLabel : '&nbsp;',
			previousLabel : '&nbsp;'
		});
	}
	
	// Referenties
	var reference = $('#reference-right'),
		referenceelements = reference.find('.element');
	if(referenceelements.length > 1) {
		referenceelements.cycle({
			keep : true,
			navigation : '#reference-navigation',
			nextLabel : '&nbsp;',
			previousLabel : '&nbsp;'
		});
	};
	
	// Front thumbnails hover
	$('div.front-element').hover(
		function(){
			$(this).css('cursor', 'pointer');
			$(this).css('background-color', '#eee');
			$(this).find('.hover').stop(true, true).animate({
				opacity: 1.0
			});
		},
		function(){
			$(this).css('background-color', '#fff');
			$(this).find('.hover').stop().animate({
				opacity: 0
			});
		}
	);
	
	$('.front-element div').each(function(){
		var self = $(this);
		self.addClass('container');
		var img = self.find('img').clone();
		img.addClass('hover');
		var link = self.find('a');
		link.append(img);
		img.attr('src', replaceFormat(img.attr('src'), 'frontpage-hover'));
	});
	
	$('.front-element').each(function(){
		var l = $(this).find('.container a').attr('href');
		$(this).click(function(){
			window.location=l;
		});
	});
	
	// Set up menu slide
	$('#navigation  > li').menu({
		dropdown : '.subnavigation',
		effect : 'slideDown',
		duration : 150,
		ignoreDummy : true,
		swapClass : 'none'
	});
	
	$('#search input[type=text]').searchValue();
	
	// Set up image cycle 
	$('.image-view .image').cycle({
		interval : 5000,
		navigation : false,
		previous : false,
		next : false
	});
		
});
