jQuery.fn.mailto = function(){
	return this.each(function(){
		var name = $(this).attr('title');
		var email = $(this).html().replace(/\s*at\s*/, "@").replace(/\s*dot\s*/, ".");
		$(this).before('<a href="mailto:' + (name ? name + ' ' : '') + '<' + email + '>" rel="nofollow">' + email + '</a>').remove();
	});
};

$().ready(function(){
	$('span.email').mailto();
	$('#shareFacebook').click(function(){
		u=location.href;
		t=document.title;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
		return false;
	});

	$('hr').each(function(){
		$(this).after('<div class="hr"></div>');
	});

	$('img.retouch').each(function(){
		title = $(this).attr('title');
		if (title == '')
		{
			title = 'Klikněte na fotku a zobrazí se vyretušovaná verze';
		}
		srcBefore = $(this).attr('src');
		dot = srcBefore.lastIndexOf('.');
		if (dot > 0)
		{
			x = $(this).position();
			if ($(this).attr('align') == 'left' || $(this).attr('align') == 'right')
			{
				cssStyle = 'float:' + $(this).attr('align') + ';';
			}
			else
			{
				cssStyle = 'left: ' + x.left + 'px;';
			}
			$(this).wrap('<div class="retouch" style="position: relative; ' + cssStyle + ' width: ' + $(this).width() + 'px;height: ' + $(this).height() + 'px;" title="Klikněte a fotka se změní"></div>');
			srcAfter = srcBefore.substr(0, dot) + '-2' + srcBefore.substr(dot, srcBefore.length);
			afterImage = $('<img class="retouched" src="' + srcAfter + '" width="' + $(this).width() + '" height="' + $(this).height() + '" align="' +  + '" alt="' + $(this).attr('alt') + '" />');
			$(this).before(afterImage);
			$(this).after('<div class="clickText">' + title + '</div>');
			$(this).after('<div class="clickTextBackground"></div>');
		}
	});
	$('div.retouch').each(function(){
		$(this).click(function(){
			imageBefore = $('img.retouch', this);
			if ($(imageBefore).css('display') == 'none')
			{
				$(imageBefore).show();
			}
			else
			{
				$(imageBefore).hide();
			}
		})
	});
});
