$(document).ready(function() {
	var root = $('#Logo a').attr('href');
	
	// Open links in new window:
	$('a[href]').click(function() {
		var link = $(this).attr('href');
		
		if (link.indexOf('#') == 0) {
			return true;
		}
		
		if (link.indexOf(root) < 0) {
			window.open(link);
			
			return false;
		}
	});
	
	// Email article:
	$('#actionEmailArticle').click(function() {
		var id = $(this).attr('href').match(/[0-9]+/);
		
		window.open(root + '/email-article/' + id + '/', "Email","location=0,status=0,scrollbars=1,width=400,height=620");
		
		return false;
	});
	
	// Print article:
	$('#actionPrintArticle').click(function() {
		window.print();
		
		return false;
	});
	
	// Lightbox:
	$(function() {
		$('a[rel*=lightbox]').lightBox();
	});
	
	// Slideshow:
	$(function() {
		$('.slideshow_unstyled').addClass('slideshow');
		
		$('ul.slideshow').galleria({
			history		: false,
			clickNext	: true,
			insert		: '#slideshow-main_image',
			onImage		: function(image, caption, thumb) {
				if(!($.browser.mozilla && navigator.appVersion.indexOf("Win") != -1)) {
					image.css('display','none').fadeIn(1000);
				}
				
				caption.css('display','none').fadeIn(1000);
				
				thumb
					.parents('li')
					.siblings()
					.children('img.selected')
					.fadeTo(500, 0.3);
				
				thumb
					.fadeTo('fast', 1)
					.addClass('selected');
				
				image.attr('title', 'Next image >>');
			},
			onThumb : function(thumb) {
				var item = thumb.parents('li');
				
				thumb.css({
					display:	'none',
					opacity:	item.is('.active') ? '1' : '0.3'
				}).fadeIn(1500);
				
				thumb.hover(
					function() {
						thumb.fadeTo('fast', 1);
					},
					function() {
						item.not('.active')
							.children('img')
							.fadeTo('fast', 0.3);
					}
				)
			}
		});
	});
});
