/* protects the document against right-click + dragging; includes overlay over images */
$(document).ready(function() {
/*
	var isMouseDown = false;
	$(document).bind("contextmenu",function(e){
		return false;
	}); 
	$("img").mouseup(function(e){
		e.stopPropagation();
		isMouseDown = false;
		return false;
    });
	$("img").mouseleave(function(e){
		e.stopPropagation();
		isMouseDown = false;
 		return false;
    });
	$("img").mousedown(function(e){
		e.stopPropagation();
		isMouseDown = true;
		if(e.ctrlKey) {
			showCopyright($(this));
	    }
 		return false;
   });
	$("img").mousemove(function(e){
		e.stopPropagation();
		if(isMouseDown == false) return;
		    showCopyright($(this));
 		return false;
    });
*/
/*
 	$(document).bind("contextmenu",function(e){
		return false;
	}); 
	$("img").mousedown(function(e){
		if(e.ctrlKey) {
			showCopyright($(this));
		}
		return false;
	});
*/
	var isMouseDown = false;
	$(document).bind("contextmenu",function(e){
		return false;
	}); 
	$("img").mouseup(function(e){
		e.stopPropagation();
		isMouseDown = false;
		return false;
    });
	$("img").mouseleave(function(e){
		e.stopPropagation();
		isMouseDown = false;
 		return false;
    });
	$("img").mousedown(function(e){
		e.stopPropagation();
		isMouseDown = true;
		if(e.ctrlKey) {
			showCopyright($(this), true);
	    }
 		return false;
   });
	$("img").mousemove(function(e){
		e.stopPropagation();
		if(isMouseDown == false) return;
		    showCopyright($(this), false);
 		return false;
    });
   function showCopyright(i,messge) {
		if ( $("#copyright-overlay:visible").length == 0 ) {
			$("#copyright-overlay").stop(true, true);
			var theType = i.attr("src");
			x = theType.split(".");
			y = x.length;
			theType = x[y-1];
			if (theType == 'jpg') {
				var w = i.width();
				var h = i.height();
				if ( h > 170 || w > 170 ) {
					var o = i.offset();
					var t = o.top;
					var l = o.left;
					if ( h > 72 ) {
						var m = ((h/2)-36);
					} else {
						var m = 0;
					}
					$("#copyright-overlay").css("left", l);
					$("#copyright-overlay").css("top", t);
					$("#copyright-overlay").css("width", w);
					$("#copyright-overlay").css("height", h);
					$("#copyright-overlay p").css("margin-top", m);
					if(messge == true) {
						$("#copyright-overlay p").css("display", "block");
						$("#copyright-overlay").fadeIn("slow");
						$("#copyright-overlay").animate({opacity: 0.6}, 1500);
					    $("#copyright-overlay").fadeOut("slow");
					} else {
						$("#copyright-overlay p").css("display", "none");
						$("#copyright-overlay").fadeIn("fast");
						$("#copyright-overlay").animate({opacity: 0.6}, 1);
					    $("#copyright-overlay").fadeOut("fast");
					}
				}
		    }
	    }
	    return false;
    }
});


/*
in Head:
	<link rel="stylesheet" type="text/css" rel="stylesheet" media="screen" href="/Resources/css/protection.css" />
before Body end:
		<div id="copyright-overlay"><p>&copy;&nbsp;copyright<br />Jonathan&nbsp;Buckley <?php echo date('Y'); ?></p></div>
		<script type="text/javascript" src="/Resources/js/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" src="/Resources/js/protection_overlay.js"></script>
*/
