$(document).ready(function(){

	/* image gallery
	*/

	$('.thumbs a').click(function() {

		if ($(this).hasClass('active')) return false;

		$('.loader').css('display', 'block');
		$('.thumbs a').removeClass('active');
		$(this).addClass('active').css('outline', 'none');

		var id = this.href.match(/i=(\d{2})$/);
		var id = RegExp.$1;
		var file = '/files/'+id+'.jpg';
		var e = $(this).find('img');
			var alt = e.attr('alt');
			var title = e.attr('title');

		var img = new Image();
		$(img).attr({
			src: file,
			alt: alt,
			title: title
		}).load(function() {
			$(this).hide();
			$('.image').append(this);
			$(this).fadeIn(700, function() {
				$('.image :first-child').remove();
			});			
			$('.loader').css('display', 'none');
		});

		return false;
	});

	/* external links
	   based on: http://www.learningjquery.com/2008/08/quick-tip-dynamically-add-an-icon-for-external-links
	*/

	$('a').filter(function() {
		return this.hostname && (this.hostname).split(":")[0] !== (location.hostname).split(":")[0];
	})
	.not(':has(img, div, mailto)')
	.addClass('external')
	.click(function() {
		window.open(this.href);
		return false;
	});


});