$(document).ready(function() {
	// random image	
	var show_li = Math.floor(Math.random()*$('#random-image ul li').length);
	$('#random-image ul li:eq('+ show_li +')').removeClass('hidden');
	
	// gallery
	$('#loader').css('opacity', 0.8);
	
	$('#gallery div.thumbs div.thumb a').click(function() {
		var url = $(this).attr('href');
		$('#loader').show();
		
		image(url, function(new_image) {
			$('#loader').hide();
			$('#gallery div.large img').attr('src', new_image.src);
		});
		
		return false;
	});
	
	// archive
	var archives = $('ul.archives li');
	var archives_length = $(archives).length;
	
	$(archives).each(function (key, item) {
		if(key == 0)
			$(item).addClass('first');

		if(key == parseInt(archives_length-1))
			$(item).addClass('last');
	});
	
	$('.read-more').click(function() {
		$(this).parent().hide();
		$(this).parent().next().show();
	});
	
	// newsletter
	$('#newsletter input').click(function() {
		var value = $(this).val();
		
		if(value == "Namn" || value == "E-post")
			$(this).val("");
	});
	
	$('#submit-newsletter-form').click(function() {
		$('#newsletter-form').submit();
		return false;
	});
});

function image(src, callback) {
	var new_image = new Image();
		
	$(new_image).load(function() {
		if(typeof callback != "undefined")
			callback(new_image);
	});
	
	new_image.src = src;
}