window.addEvent('load', function () {
if ($$('.round').length > 0) {
	var rounders = $$('.round');

	var corners = function (width, height) {
		var size = 'small';

		if (width < 200 || height < 200) {
			size = 'small';
		} else if (width < 300 || height < 300) {
			size = 'medium';
		}

		var styles = {
			'position': 'absolute',
			'margin': 0,
			'padding': 0
		};

		var src = BASE_URL+'/assets/img/layout/corners/'+size+'/';

		return [
			new Element('img', {'class': 'corner', 'src': src+'1.png', styles: styles}),
			new Element('img', {'class': 'corner', 'src': src+'2.png', styles: styles}),
			new Element('img', {'class': 'corner', 'src': src+'3.png', styles: styles}),
			new Element('img', {'class': 'corner', 'src': src+'4.png', styles: styles})
		];
	};

	var placeCorners = function (target) {
		var s = target.getCoordinates();

		var wrap = new Element('span', {'class': 'wrap', styles: {'width': s.width, 'height': s.height, 'float': 'left'}});
		wrap.inject(target, 'before');
		wrap.grab(target);

		wrap.setStyle('margin', target.getStyle('margin'));

		corners(s.width, s.height).each(function (corner, i) {
			corner.inject(wrap, 'top');

			var cS = corner.getSize();
			var pos = {};

			switch (i) {
				case 0:
					pos.top = -1;
					pos.left = -1;
				break;
				case 1:
					pos.top = -1;
					pos.right = -1;
				break;
				case 2:
					pos.right = -1;
					pos.bottom = -1;
				break;
				case 3:
					pos.left = -1;
					pos.bottom = -1;
				break;
			}

			corner.setStyles(pos);
		});
	};

	rounders.each(function (round) {
		placeCorners(round);
	});
}
});