// much of the following code related to image protection was 
// taken from http://www.quirksmode.org/js/improt.html

//var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all);
//var flag = 0;
//var msg = 'No!';
//var x, y, x1, y1, copyAttempt;

function disableRightClick() {
	if (!(document.getElementById || document.all || document.layers)) return;
		if (specialcase && document.layers) {
			document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = special;
		}
		for (i=0;i<document.images.length;i++) {
			document.images[i].onmousedown = checkIt;
			document.images[i].onmouseup = function() {return false};
			if (specialcase) {
				document.images[i].onmousemove = special;
				document.images[i].onclick = clearIt;
			}
		}
	if (ie5||ns6) {
		menuobj.style.display=''
		document.oncontextmenu=showmenuie5
		document.onclick=hidemenuie5
	}
}

function checkIt(e) {
	copyAttempt = 0;
	if (window.Event) {  // Netscape
		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;
		flag = 0;
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(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 (flag && (!isLink || ((Math.abs(x-x1) > 20) || (Math.abs(y-y1) > 20)))) {
//		alert('' +  x1 + ' ' + y1);
		copyAttempt = 1;
		flag = 0;
		return false;
	}
}

function clearIt() {
	flag = 0;
	if (copyAttempt) {
		copyAttempt = 0;
		return false;
	}
}

// the follow functions relate to DHTML context menu

function showmenuie5(e){

var firingobj=ie5? event.srcElement : e.target
//if (ns6&&firingobj.parentNode.className=="img") firingobj=firingobj.parentNode //up one node
if(firingobj.getAttribute("src")) { // only show menu for images
//	alert(firingobj.getAttribute("src"))
	if (firingobj.getAttribute('id')) {
		var i = firingobj.getAttribute('id')
	} else {
		var i = firingobj.getAttribute('src')
		var ia = i.split("/")
		i = ia[ia.length - 1]
	}
	var mitem = document.getElementById("501")
	mitem.setAttribute('url', mitem.getAttribute('url') + '&image=' + i + '&from_page=' + escape(document.location.href))
	var mitem = document.getElementById("502")
	mitem.setAttribute('url', mitem.getAttribute('url') + '&image=' + i + '&from_page=' + escape(document.location.href))
	var mitem = document.getElementById("503")
	mitem.setAttribute('url', mitem.getAttribute('url') + '&image=' + i + '&from_page=' + escape(document.location.href))

//Find out how close the mouse is to the corner of the window
	var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
	var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY

//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<menuobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
	menuobj.style.left=ie5? document.body.scrollLeft+event.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth
	else
//position the horizontal position of the menu where the mouse was clicked
	menuobj.style.left=ie5? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX

//same concept with the vertical position
	if (bottomedge<menuobj.offsetHeight)
	menuobj.style.top=ie5? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
	else
	menuobj.style.top=ie5? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY

	menuobj.style.visibility="visible"
}
return false
}

function hidemenuie5(e){
menuobj.style.visibility="hidden"
}

function highlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor="#6699CC"
//firingobj.style.backgroundColor="highlight"
firingobj.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}

function lowlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor=""
firingobj.style.color="black"
window.status=''
}
}

function jumptoie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
if (firingobj.getAttribute("target"))
window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
else
window.location=firingobj.getAttribute("url")
}
}


