$(document).ready(function($) {

	$.fn.rightClick = function(handler) {
		$(this).each( function() {
			$(this).mousedown( function(e) {
				var evt = e;
	
				$(this).mouseup( function() {
					$(this).unbind('mouseup');
					if( evt.button == 2 ) {
						handler.call( $(this), evt );
						return false;
					} else {
						return true;
					}
				});
			});
			$(this)[0].oncontextmenu = function(evt) {
				return false;
			}
		});
		return $(this);
	}

	function excludeGrantedTags(event) {
		if($.inArray(event.target.tagName,['TEXTAREA','INPUT']) > -1){
			event.stopImmediatePropagation();
			return true;
		}
		return false;
	}

	var $body = $("html");
	return $body.each(function() {
		var $this = $(this);
		$this.rightClick( function(event) {
			if(!excludeGrantedTags(event)) {
				window.alert("Testi e immagini di questo sito sono proprieta' esclusiva di GRISPORT S.p.A.");
				return false;
			}
			return true;
		});
		$this.mousedown(function(event) {
			return excludeGrantedTags(event);
		});
		$this.bind('selectstart', function(event) {
			return excludeGrantedTags(event);
		});
		$this.css({
			'MozUserSelect':'-moz-none',
			'cursor':'default'
		}).attr("unselectable","on");
	});


});
