function zabezpeciObrazky()
{
	$("img[id^='original_image_']").each(function () {
		var this_id = $(this).attr('id');
		var splitted = this_id.split('_');
		var index = splitted.length - 1;
		var cloaking_selector = '#cloaking_' + splitted[index];
		$(cloaking_selector).attr('width', $(this).width());
		$(cloaking_selector).attr('height', $(this).height());
		$(cloaking_selector).css('position', 'absolute');
		var position = $(this).position();
		$(cloaking_selector).css('top', position.top);
		$(cloaking_selector).css('left', position.left);
	});		
}
/* 
	Repairs div height for each box.
	We are doing this becouse product title can be long.
*/
function fixImages()
{
	$(".wraptocenter").each(function() {
		var a = $(this).parent().children(":first").height() + $(this).parent().children(":first").position().top;
		var b = $(this).parent().parent().children(":last").position().top;
		$(this).css('height', b - a - 10);
		var without_px = $(this).css('height').replace('px','');
		var width_without_px = $(this).css('width').replace('px','');
		$(this).children(":first").children(":first").attr('src', $(this).children(":first").children(":first").attr('src').replace(/mv\=180/g, 'mv=' + (without_px - 10)));
		$(this).children(":first").children(":first").attr('src', $(this).children(":first").children(":first").attr('src').replace(/ms\=180/g, 'ms=' + (width_without_px - 20)));
	});
}
$(window).load(function () {
	zabezpeciObrazky(); /* Warning: This can reduce performance */
	fixImages();
});