try{Typekit.load();}catch(e){};
(function($) {
	$.fn.blank = function() {
		return this.click(function(e) {
			window.open(this.href);
			e.preventDefault();
			e.stopPropagation();
		});
	};
	// blurs element on click
	$.fn.blurry = function() {
		return this.click(function() { $(this).blur(); });
	};
	$.fn.imprint = function(){
	  return this.click(function(e) {
			window.open(this.href,'Imprint','width=270,height=535,screenX=50,screenY=50,left=50,top=50,scrollbars=yes');
			e.preventDefault();
			e.stopPropagation();
		});
	}	
	$.fn.addlink = function() {
			$(this).click(
				function() {
					var link =  $(this).find('a').attr('href');
					self.location.href = link;
				}
			);

		};
	var changeInterval;
	$.fn.animatedGallery = function () {
		var id = 0,
			count = 0,
			animated_gallery = $(this),
			imgs = animated_gallery.children('.scalable'),
			currentImg = imgs.filter('.show').length > 0 ? imgs.filter('.show') : imgs.first();
			imgs.css({opacity: 0.0});
			currentImg.css({opacity: 1.0}).addClass('show');

			changeInterval = setInterval(function gallery() {

				var current = animated_gallery.find('.scalable.show') ? animated_gallery.find('.scalable.show') : animated_gallery.find('.scalable:first');

				var next = ((current.next().length) ? ((current.next().hasClass('caption'))? animated_gallery.find('scalable:first') : current.next()) : animated_gallery.find('.scalable:first'));
			//	var caption = next.find('div').html();
				//Set the fade in effect for the next image, show class has higher z-index
					next.css({opacity: 0.0})
					.addClass('show')
					.animate({opacity: 1.0},1500);
					//Hide the current image
					current.animate({opacity: 0.0}, 1500)
					.removeClass('show');
			},9000);
	};

})(jQuery);

$(function() { 
	var $winwidth = $(window).width();
	var 
		Saf = /a/.__proto__=='//',
		chrome = /source/.test((/a/.toString+''));
	$('a[href^="http://"]').blank();
	$('a').blurry();
	$('.container .gallery').animatedGallery();
	$('.imprint').imprint();
	$('.news-link').addLink();
});
