var cornerRadius = 8;

function curvyImage(image) {
	if (!image.offsetWidth || !image.complete) {
		window.setTimeout(function() { curvyImage(image); }, 1);
		return;
	}

	$(image).after('<div class="curvyCorner"></div>');
	var curvyCornerImgDiv = $(image).next();
	curvyCornerImgDiv.css({
		width: $(image).width() + 'px',
		height: ($(image).height() - (2 * cornerRadius)) + 'px',
		background: 'url(' + $(image).attr('src') + ')',
		float: $(image).css('float'),
		marginTop: ((($(image).css('margin-top').replace('px', '') * 1) + cornerRadius)) + 'px',
		marginRight: $(image).css('margin-right'),
		marginBottom: $(image).css('margin-bottom'),
		marginLeft: $(image).css('margin-left')
	});
	$(image).remove();
	curvyCornerImgDiv.curvy(cornerRadius + 'px');
}

$(window).load(function() {
	$('body').addClass('fx');

	$('body.startseite #topmeldungen .meldung .meldung-text').curvy(cornerRadius + 'px');

	$('div.box').curvy(cornerRadius + 'px').css({
		marginTop: 8 + 'px',
		marginBottom: 32 + 'px'
	});
	$('div.feature').curvy(cornerRadius + 'px').css({
		marginTop: 8 + 'px',
		marginBottom: 32 + 'px'
	});


	$('body div.userUIForm').curvy(cornerRadius + 'px');
	$('body.newsletterregistrierung div#content form').curvy(cornerRadius + 'px');
	$('body.gefoerderteprojekte div#content form').curvy(cornerRadius + 'px');

	$('div#content img').not('img.newsfeed').each(function() { curvyImage(this); });

	$('tbody tr td a').each(function() {
		$(this).css({textDecoration: 'none', color: 'black', backgroundImage: 'none', paddingLeft: 0, fontWeight: 'normal'});
		$(this).parent().parent()
			.css({cursor: 'pointer'})
			.click(function() {
				document.location.href = $(this).find('a').attr('href');
			});
	});

	$('li, input, tr').mouseover(function() { $(this).addClass('hover'); });
	$('li, input, tr').mouseout(function() { $(this).removeClass('hover'); });
});
