$(document).ready(function() {
	// Blog entry clickable
	$('.blog-grid dl').click(function() {
		window.location = $('dd > a', this).attr('href');
	});
	$('.blog-grid dl').css('cursor', 'pointer');

	// Blog images
	$('.blog-display .blog-body').before($('.blog-display .blog-image').remove().clone());
	var lastClicked = null;
	var defaultOpacity = 0.5;
	$('.blog-display .blog-images ul li').each(function(i) {
		$('img', this).css('opacity', defaultOpacity);
		$('a', this).click(function() {
			$('.blog-display .blog-images img').css('opacity', defaultOpacity);
			$('img', this).css('opacity', '1');
			$('.blog-display .blog-image dl').hide();
			if(i != lastClicked) {
				window.location.hash = '#'+ $(this).attr('id').replace('thumb-', '');
				$('.blog-display .blog-image dl').eq(i).show();
				lastClicked = i;
			}
			else {
				$('img', this).css('opacity', defaultOpacity);
				lastClicked = null;
			}
			return false;
		});
	});
	if(window.location.hash.length > 0) {
		$('.blog-display .blog-images ul li a[id="thumb-'+ window.location.hash.replace('#', '') +'"]').trigger('click');
	}
	else {
		$('.blog-display .blog-images ul li:first a').trigger('click');
	}
	if($('.blog-display .blog-images ul li').length < 2) {
		$('.blog-display .blog-images').hide();
	}


	if((rh(0) == '' || rh(0) == 'galleriat') && $('#bars').length > 0) {
		$('#bars a img').each(function(){
			$(this).css('opacity', '0.4');
			$(this).animate({opacity: 0.01, easing: 'linear'}, 2500);
		}).hover(function(){	
			$(this).css('opacity', '0.4');
		},function(){
			$(this).css('opacity', '0.01');
		});
	}









	// Mask emails
	$(".email").each(function(){
		var email = $(this).text();
		var parts = email.split("(at)");
		for(i in parts){
			parts[i] = $.trim(parts[i]);
		}
		$(this).html('<a href="mailto:'+ parts[0] +'@'+ parts[1] +'" title="Send email: '+ parts[0] +'@'+ parts[1] +'">'+ parts[0] +'@'+ parts[1] +'</a>');
	});

	// Separators in navi
	$('#navi li:not(:last)').after('<li> | </li>');
});