// library of functions
// (c) Naz Rajan 2006-2007
// naz@nazrajan.com
// Version 2007.0306

function disableRightClick(e)
{
  var message = "Right click has been disabled";
  
  if(!document.rightClickDisabled) // initialize
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
    {
      alert(message);
      return false;
    }
  }
  else
  {
    alert(message);
    return false;
  }
}
disableRightClick();

function NR_menu(iMenu,iActive) {
var i;
	document.write("<table><tr height=\""+mHeight[iMenu]+"\">");
	for (i=1;i<=mItem[iMenu][0];i++) {
		document.write("<td align=\""+mAlign[iMenu]+"\"");
		if (iActive==i) {
			document.write("class=\"menuon\">"+mItem[iMenu][i]+" ");
		}
		else {
			document.write("><a href=\""+(null==mHref[iMenu][i]?"":mHref[iMenu][i])+"\" class=\"menu\" ");
			document.write((null==mMouseclick[iMenu][i]?"":(mMouseclick[iMenu][i]==""?"":" onClick=\""+mMouseclick[iMenu][i]+"\"")+" "));
			document.write((null==mMouseover[iMenu][i]?"":(mMouseover[iMenu][i]==""?"":" onMouseOver=\""+mMouseover[iMenu][i]+"\"")+" "));
			document.write((null==mMouseout[iMenu][i]?"":(mMouseout[iMenu][i]==""?"":" onMouseOut=\""+mMouseout[iMenu][i]+"\"")));
			document.write(">"+mItem[iMenu][i]+"</a>");
		}
		document.write((null==mBelowText[iMenu][i]?"":(mBelowText[iMenu][i]==""?"":"<br><span class=\"menutext\">"+mBelowText[iMenu][i]+"</span>")));
		if (mDirection[iMenu]==0) {
			document.write((i==mItem[iMenu][0]?"":mSeparator[iMenu])+"</td>");
		}
		else {
			document.write("</td>"+(i==mItem[iMenu][0]?"":"</tr><tr height=\""+mHeight[iMenu]+"\">"));
		}
	}
	document.write("</tr></table>");

}

function NR_menu(iMenu,iActive) {
var i;

	document.write("<table><tr><td bgcolor=\""+mBGColor[iMenu][0]+"\"><table border=\"0\"><tr border=\"0\" height=\""+mHeight[iMenu]+"\">");
	for (i=1;i<=mItem[iMenu][0];i++) {
		document.write("<td align=\""+mAlign[iMenu]+"\""+(null==mClass[iMenu][i]?"":(null==mBGColor[iMenu][i]?"":" bgcolor=\""+mBGColor[iMenu][i]+"\" ")));
		if (iActive==i) {
			document.write("class=\""+(null==mClass[iMenu][i]?"menuon":mClass[iMenu][i]+"on")+"\">"+mItem[iMenu][i]+" ");
		}
		else {
			if (mHref[iMenu][i]=="#") {
				document.write("><span class=\""+(null==mClass[iMenu][i]?"menu":mClass[iMenu][i])+"\">"+mItem[iMenu][i]+"</span>");
			}
			else {
				document.write("><a href=\""+(null==mHref[iMenu][i]?"":mHref[iMenu][i])+"\" class=\""+(null==mClass[iMenu][i]?"menu":mClass[iMenu][i])+"\" ");
				document.write((null==mMouseclick[iMenu][i]?"":(mMouseclick[iMenu][i]==""?"":" onClick=\""+mMouseclick[iMenu][i]+"\"")+" "));
				document.write((null==mMouseover[iMenu][i]?"":(mMouseover[iMenu][i]==""?"":" onMouseOver=\""+mMouseover[iMenu][i]+"\"")+" "));
				document.write((null==mMouseout[iMenu][i]?"":(mMouseout[iMenu][i]==""?"":" onMouseOut=\""+mMouseout[iMenu][i]+"\"")));
				document.write(">"+mItem[iMenu][i]+"</a>");
			}
		}
		document.write((null==mBelowText[iMenu][i]?"":(mBelowText[iMenu][i]==""?"":"<br><span class=\"menutext\">"+mBelowText[iMenu][i]+"</span>")));
		if (mDirection[iMenu]==0) {
			document.write((i==mItem[iMenu][0]?"":mSeparator[iMenu])+"</td>");
		}
		else {
			document.write("</td>"+(i==mItem[iMenu][0]?"":"</tr><tr height=\""+mHeight[iMenu]+"\">"));
		}
	}
	document.write("</tr></table></td></tr></table>");

}


function NR_movetocenter(bglayer,maxw) {
var	sw=screen.width, sh=screen.height;
	if (sw>sh) {  
		document.getElementById(bglayer).style.left=((sw-maxw)/2);
		if (document.getElementById(bglayer).style.left<0) {document.getElementById(bglayer).style.left=0;}
		if (sh>768) {
			document.getElementById(bglayer).style.top=((sh-750)/2);
			if (document.getElementById(bglayer).style.top<0) {document.getElementById(bglayer).style.top=0;}
		}
	}
	else {
		document.getElementById(bglayer).style.left=0;
		document.getElementById(bglayer).style.top=0;
	}
}

function NR_geturl() {
	var urlquery, urlterms;
	urlquery = location.href.split("?");
	return urlquery[1];
}

function NR_FormatTitle(strText) {
	var strHTML, i=0;
	i = strText.indexOf('/');
	strHTML = strText.substr(0,i) + '<br><div class=\'body\'>';
	strText = strText.substr(i+1, strText.length-i);
	i = strText.indexOf('/');
	strHTML = strHTML + strText.substr(0,i) + '<br>' + strText.substr(i+1, strText.length-i) + '</div>';
	return strHTML;
}

function NR_replaceString(str,strfind,strrepl) {
	while(1 == 1) {
		if(str.indexOf(strfind)==-1) return str;
			str = str.replace(strfind,strrepl);
	}
}

function NR_gallery(iGallery) {
/*
gConfig[iGallery][1]	SourceFolder
gConfig[iGallery][2]	FirstPicture
gConfig[iGallery][3]	GalleryRows
gConfig[iGallery][4]	GalleryCols
gConfig[iGallery][5]	PicWidth
gConfig[iGallery][6]	PicHeight
gConfig[iGallery][7]	ThumbWidth
gConfig[iGallery][8]	ThumbHeight
gConfig[iGallery][9]	ScrollbarPos (L/B/N)
gConfig[iGallery][10]	Mainpic
gConfig[iGallery][11]	GalleryText
gConfig[iGallery][12]	0=onMouseOver, 1=OnClick
gConfig[iGallery][13]	GalleryClickEvent function name
gConfig[iGallery][14]	Spare for custom use
*/
var tnum=1;



	document.write("<table><tr><td><table><tr><td valign=\"top\"><a onClick=\"NR_scrollImages("+iGallery+",-1);\"><img name=\"scrollup\" src=\"images/scrollup.gif\" width=\"19\" height=\"14\" ");
	document.write("border=\"0\"></a></td></tr><tr><td height=\""+((gConfig[iGallery][3]*gConfig[iGallery][8])-20)+"\">&nbsp;</td></tr><tr><td valign=\"bottom\"><a onClick=\"NR_scrollImages("+iGallery+",1);\"><img name=\"scrolldown\" src=\"images/scrolldown.gif\" width=\"19\" height=\"14\" border=\"0\"></a></td></tr></table></td><td><table>");
	for (r=1; r<=gConfig[iGallery][3]; r++) {
		document.write("<tr><td width=\""+(gConfig[iGallery][4]*(gConfig[iGallery][7]+10))+"\" height=\""+(gConfig[iGallery][8]+10)+"\">");
		for (c=1; c<=gConfig[iGallery][4]; c++) {
			document.write("<img name=\"thumb"+tnum+"\" src=\"images/"+gConfig[iGallery][1]+"/"+gThumbHeader+gPicture[iGallery][tnum]+gSourceTail);
			document.write("\" width=\""+gConfig[iGallery][7]+"\" height=\""+gConfig[iGallery][8]+"\" ");
			document.write("onMouseOver=\"");
			if (gConfig[iGallery][13]>"") {document.write(gConfig[iGallery][13]+"();")}
			document.write("NR_rolloverImage(\'"+gConfig[iGallery][10]+"\', "+iGallery+", "+tnum+")\" ");
			if (gConfig[iGallery][13]>"") {document.write(" onClick=\""+gConfig[iGallery][13]+"(\'"+gClick[iGallery][((r-1)*gConfig[iGallery][4])+c]+"\');\" ")}
			document.write(">");
			document.write("<img src=\"images/spacer.gif\" width=\"10\" border=\"0\">");
			tnum++;
		}
		document.write("</td></tr>");
	}
	document.write("</table></td></tr></table>");
}

function NR_scrollImages(iGallery,sdirection) {
var t, n, imgname, imgsrc;
var imghdr="images/"+gConfig[iGallery][1]+"/", irows=gConfig[iGallery][3], icols=gConfig[iGallery][4];
	if (sdirection==0) {
		dFirstPictureOnPage=NR_jumpToSection();
		n=dFirstPictureOnPage;
	}
	else {
		n = dFirstPictureOnPage+(icols*sdirection);
  		n = (n<gConfig[iGallery][2]?gConfig[iGallery][2]:n);   // no scroll after reaching start
	}
	if (n<=gPicture[iGallery][0]) {  // no scroll if reached end
		dFirstPictureOnPage = n;
   		for (t=1; t<=(irows*icols); t++) {
			imgname = "thumb" + t;
			if (n>gPicture[iGallery][0]) {
			  	imgsrc = "images/spacer.gif";
				document[imgname].alt = dSitename;
			}
			else {
				imgsrc = imghdr + gThumbHeader + gPicture[iGallery][n] + gSourceTail;
				document[imgname].alt = "Click here to see a larger version of this image \r\n(picture "+n+", file "+gPicture[iGallery][n]+")";
			}
			document[imgname].src = imgsrc;
			n++;
		}
	}
}

function NR_showImage(imgname, iGallery, pnum) {
var imgsrc, imgnum, imghdr="images/"+gConfig[iGallery][1]+"/", i;

	imgsrc = document.getElementById("thumb"+pnum).src;
	imgnum = dFirstPictureOnPage+pnum-1;
	document.getElementById(imgname).src = "images/spacer.gif";   // clear current picture
	document.getElementById(imgname).width = gConfig[iGallery][5];  // PicWidth
	document.getElementById(imgname).height = gConfig[iGallery][6]; // PicHeight
	if (imgnum>gPicture[iGallery][0]) {  // spacer used, not a thumbnail
		if (gConfig[iGallery][11]>"") {
			document.getElementById(gConfig[iGallery][11]).innerHTML = "&nbsp;";
		}
	}
	else {	
		if (gConfig[iGallery][11]>"") {
			document.getElementById(gConfig[iGallery][11]).innerHTML = gText[iGallery][imgnum];
		}
		document.getElementById(imgname).src = imghdr + gPicture[iGallery][imgnum] + gSourceTail;
		NR_resizeImage(imgname, maxwidth, maxheight);
	}

}

function diagnosegallery() {
//	alert(gConfig[1][10]);
//	alert(dFirstPictureOnPage);
//	alert(gPicture[1][0]);
//	alert(document.getElementById(gConfig[1][10]).src);
alert("DIAGNOSIS");
}

function NR_rolloverImage(imgname, iGallery, pnum) {
	var imgsrc, imgnum, imghdr="images/"+gConfig[iGallery][1]+"/", imgtail=gSourceTail;
//diagnosegallery();

	imgnum = dFirstPictureOnPage+pnum-1;
	if (imgnum>gPicture[iGallery][0]) {  // means spacer used, not a thumbnail
		document.getElementById(imgname).src = "images/spacer.gif";   // clear current picture
		if (gConfig[iGallery][11]>"") {
			document.getElementById(gConfig[iGallery][11]).innerHTML = "&nbsp;";
		}
	}
	else {	
		document.getElementById(imgname).src = imghdr + gPicture[iGallery][imgnum] + imgtail;
		if (gConfig[iGallery][11]>"") {
			document.getElementById(gConfig[iGallery][11]).innerHTML = gText[iGallery][imgnum];
		}
	}
}

function NR_jumpToSection() {
//	var urlquery, urlterms;
//	urlquery = location.href.split("?");
	return (urlquery[1]=="x"?10:1);
}

