var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
$(document).ready(function () {  
	var bgImage = $('body').css('background-image');
	$('#abstand-single').css({'background-image': bgImage});
	$('.tx-dokumentation>.singleImage').css({'background-image': bgImage});
	oncomplete ($('.singleImage>img.image'), function (event) {  
		var docImage = $('.singleImage>img.image');
		$(docImage).removeAttr("width");
		$(docImage).removeAttr("height");
		height = $(docImage).height()+10;
		width = $(docImage).width();
		//console.log('width: '+width+' ## height: '+height);
		$('.singleImage>img.overlayImage').attr('style', 'height: '+height+'px'+' !important;');
		if(isChrome) {
			$(".singleImage>img.overlayImage").css({
				'width': width+'px',
				'height': height+'px'+' !important',
				'margin-top':'0',
				'margin-left':'-'+width+'px'
			});
		} else {
			$(".singleImage>img.overlayImage").css({
				'width': width+'px',
				'height': height+'px'+' !important',
				'margin-left':'-'+width+'px'
			});
		}
	});
});

$( window ).resize(function() {
	var bgImage = $('body').css('background-image');
	$('#abstand-single').css({'background-image': bgImage});
	$('.tx-dokumentation>.singleImage').css({'background-image': bgImage});

	var docImage = $('.singleImage>img.image');
	$(docImage).removeAttr("width");
	$(docImage).removeAttr("height");
	height = $(docImage).height()+13;
	width = $(docImage).width();
	$('.singleImage>img.overlayImage').attr('style', 'height: '+height+'px'+' !important;');
	if(isChrome) {
		$(".singleImage>img.overlayImage").css({
			'width': width+'px',
			'height': height+'px'+' !important',
			'margin-top':'0',
			'margin-left':'-'+width+'px'
		});
	} else {
		$(".singleImage>img.overlayImage").css({
			'width': width+'px',
			'height': height+'px'+' !important',
			'margin-left':'-'+width+'px'
		});
	}
});

function oncomplete (jqimg, callback) {  
	if (jqimg.get(0).complete) {  
		callback();  
	} else {  
		jqimg.bind('load', callback);  
	}  
} 