$(function (){
	
	// extrenal link
	$('a[rel|=external]').click(function(){
		window.open(this.href);
		return false;
	});


	// slidshow
	var slideshow = $('#slideshow ul'),
	slides = $('li', slideshow),
	currentSlide = 0,
	ssH, ssW;
	
	$(window).resize(function() {
		ssH = $('#slideshow').height();
		ssW = $('#slideshow').width();
		
		$('img', slideshow).each(function() {
			$(this).bind("load", function() {
				centerSlide($(this));
			});
		});
		
		var topD = -currentSlide*ssH;
		$(slideshow).css("marginTop", topD);
		centerSlide($(slides).eq(currentSlide).find('img'));
	}).trigger('resize');
		
	function centerSlide(e) {
		// check if the image has a dimension
		if ($(e).height() > 0) {
			// check for and give the image type
			if (!$(e).parent().hasClass('landscape') && !$(e).parent().hasClass('portrait')) {
				var type = $(e).height() < $(e).width() ? "landscape" : "portrait";
				$(e).parent().addClass(type);
			};
		
			// center the image vertical
			var topD = (ssH - $(e).height())/2;
			$(e).addClass('active').css("marginTop", topD);
		};
	}
	
	function changeSlide() {
		currentSlide = $(slides).eq(currentSlide+1).length > 0 ? ++currentSlide : 0;
		var topD = -currentSlide*ssH;
		$(slideshow).css("marginTop", topD);
		centerSlide($(slides).eq(currentSlide).find('img'));
	}

	setInterval(changeSlide, 1500);
	
});
