(function($) {
	
    $.fn.tMask = function(options){

		// настройки по умолчанию
		var options = $.extend({
			radius: '50'
		},options);

		return this.each(function() {
			
			var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
			if(tmp) var isIE = document.namespaces && !window.opera ? 1 : 0;

			if(isIE){
				
				$(this).hide();

				var image =  this;
				var radius = options.radius;
				var height = image.height;
				var width = image.width;
				vml = document.createElement(['<var style="zoom:1;display: block; width:150px;height:150px;padding:0;">'].join(''));

				var path = "m 0," + radius; 
				path += " l 0," + (height-radius) + " qy " + radius + "," + height;
				path += " l " + (width-radius) + "," + height + " qx " + width + "," + (height-radius);
				path += " l " + width + "," + radius + " qy " + (width-radius) + ",0";
				path += " l " + radius + ",0 qx 0," + radius;
				path += " x e";


				data = '<v:shape stroked="f" filled="t" fillcolor="#fff" coordorigin="0,0" coordsize="' + width + ',' + height + '" path="' + path + '" style="zoom:1;padding: 0;display: block; width:' + width + 'px;height:' + height + 'px;"><v:fill src="' + image.src + '" type="frame"/></v:shape>';
				vml.innerHTML = [data].join('');
				image.insertAdjacentElement('BeforeBegin',vml);
				
			  	
				
			} else {
				
				$(this).hide();

				var canvas = document.createElement('canvas');
				canvas.setAttribute('width', options.radius*2);
				canvas.setAttribute('height', options.radius*2);
				this.parentNode.insertBefore(canvas,this);
				ctx = canvas.getContext('2d');

				// draw circle
				ctx.beginPath();
				ctx.arc(options.radius,options.radius,options.radius,0,Math.PI*2,true);
				ctx.fill();

				// set composite property
				ctx.globalCompositeOperation = 'source-atop';

				// Draw image to canvas  
				ctx.drawImage(this,0,0);
			}
			
		});
	};
})(jQuery); 