(function ($, window) {
	var defOptions = {
		cssClasses: {
			left: 'art_pic_l',
			right: 'art_pic_r',
			center: 'art_pic_c'
		}
	};
	function wrapCopyRights(jParent, optValues) {
		var jImages = jParent.find('img[data-copyright]');
		jImages.each(function () {
			var jImage = $(this), jImgParent = jImage.parent(), imageAlign, copyRights = jImage.attr('data-copyright'),
				jWrapper, jSign;
			if (!(copyRights && copyRights.length)) {
				return;
			}
			if (jImgParent.is('[class*=art_pic_]')) {
				return;
			} else if (jImgParent.is('p') && jImgParent.children().length == 1) {
				jImage.unwrap(jImgParent);
			}
			imageAlign = jImage.css('float');
			if (imageAlign != 'right' && imageAlign != 'left') {
				imageAlign = jImage.attr('style');
				imageAlign = imageAlign && imageAlign.match(/margin-left:[ ]?auto.*margin-right:[ ]?auto/) ? 'center' : 'left'
			}
			jWrapper = $('<div />').addClass(optValues.cssClasses[imageAlign]);
			jSign = $('<a />').text(copyRights.replace(/(?:http:\/\/)?(?:www.)?([a-z0-9-_]+)\.[a-z]{2,4}/, '$1'))
							  .attr('href', copyRights);
			jSign = $('<div />').text('Фото: ').append(jSign);
			jWrapper = jImage.wrap(jWrapper).parent();
			jSign.appendTo(jWrapper);
		});
	}
	
	$.fn.wrapCopyRightsImages = function (options) {
		var optValues = $.extend(true, {}, defOptions, options);
		wrapCopyRights($(this), optValues);
		return this;
	};
	
	/*$(function () {
		$('section.s_article').wrapCopyRightsImages();
	});*/
})(jQuery, window);

