/**
 * Protects images from dragging and right-click copying
 * Adapted from http://www.quirksmode.org/js/improt.html
 */

var imageProtectSpecialCase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var imageProtectFlag = 0;
var msg = 'This image is protected by copyright.\nWe request you not to copy it.';
var x,y,x1,y1,copyAttempt;

document.oncontextmenu = new Function("return false");

function initImageProtect()
{
	if (!(document.getElementById || document.all || document.layers)) return;
	if (imageProtectSpecialCase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = imageProtectSpecial;
	}
	for (i=0; i < document.images.length; i++)
	{
		document.images[i].onmousedown = imageProtectCheckIt;
		document.images[i].onmouseup = function() {return false};
		if (imageProtectSpecialCase)
		{
			document.images[i].onmousemove = imageProtectSpecial;
			document.images[i].onclick = imageProtectClearIt;
		}
	}
}

function imageProtectCheckIt(e)
{
	copyAttempt = 0;
	if (window.Event && e.screenX)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		imageProtectFlag = 0;
		return false; // NN4 only
	}
	if (imageProtectSpecialCase) imageProtectFlag = 1;
	return false;
}

function imageProtectSpecial(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (imageProtectFlag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		imageProtectFlag = 0;
		alert(msg);
		return false;
	}
}

function imageProtectClearIt()
{
	imageProtectFlag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}
