$(document).ready(function(){

	/* Mark Selected Menu Item */
	$('#menu li[id="menu_' + $('body').attr('id') + '"]')
		.addClass('active')
	;

	/* Add Click on header and go to homepage functionality */
	$('#header h1 img')
		.click(function() { document.location = '/'; })
		.css('cursor', 'pointer')
	;

	/* Open External Links in a new Window */
	$('a[href^="http://"]')
		.addClass('ext')
		.attr('target', '_blank')
	;

	/* Image Ticker */
	$('#ticker')
		.cycle({ fx : 'fade', delay : -2000 })
	;

	/* Initialize Image Gallery */
	$('ul.galleria')
		.galleria({
			history   : false,
			clickNext : true,
			insert    : '#main_image',
			onImage   : function(image, caption, thumb) {
				if (!($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1)) { image.css('display','none').fadeIn(1000); }
				var _li = thumb.parents('li');
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				thumb.fadeTo('fast',1).addClass('selected');
				image.attr('title','Next image >>');
			},
			onThumb   : function(thumb) {
				var _li = thumb.parents('li');
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				thumb.hover(function() { thumb.fadeTo('fast',1); }, function() { _li.not('.active').children('img').fadeTo('fast',0.3); });
			}
		})
	;
	$(".galleria li:first").addClass('active'); 

	/* Update Layoutimage With specified Image */
	$('ul.quicklink li')
		.each(function() {
			var id = $(this).attr('id');
			if (id) {
				$(this)
					.click(function() { $.get('/ajax.php', { type : 'klus_foto', ref : id }, function(data) { $('img.layout').attr('src', data); }, 'text'); })
					.attr('title', 'Klik hier om een Preview te bekijken')
					.addClass('link')
				;
			}
		})
	;

});
