// library of functions
// (c) Naz Rajan 2006
// naz@nazrajan.com

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 getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if (strHref.indexOf("?") > -1){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

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]	Mainpic
gConfig[iGallery][10]	GalleryText
*/
var tnum=1;

	document.write("<table><tr><td><table><tr><td><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=\"250\">&nbsp;</td></tr><tr><td><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=\"NR_rolloverImage(\'"+gConfig[iGallery][9]+"\', "+iGallery+", "+tnum+")\">");
			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["thumb"+pnum].src;
	imgnum = dFirstPictureOnPage+pnum-1;
	document[imgname].src = "images/spacer.gif";   // clear current picture
	document[imgname].width = gConfig[iGallery][5];  // PicWidth
	document[imgname].height = gConfig[iGallery][6]; // PicHeight
	if (imgnum>gPicture[iGallery][0]) {  // spacer used, not a thumbnail
		if (gConfig[iGallery][10]>"") {
			document.all(gConfig[iGallery][10]).innerHTML = "&nbsp;";
		}
	}
	else {	
		if (gConfig[iGallery][10]>"") {
			document.all(gConfig[iGallery][10]).innerHTML = gText[iGallery][imgnum];
		}
		document[imgname].src = imghdr + gPicture[iGallery][imgnum] + gSourceTail;
		NR_resizeImage(imgname, maxwidth, maxheight);
	}

}


function NR_rolloverImage(imgname, iGallery, pnum) {
	var imgsrc, imgnum, imghdr="images/"+gConfig[iGallery][1]+"/", imgtail=gSourceTail;

	imgnum = dFirstPictureOnPage+pnum-1;
	if (imgnum>gPicture[iGallery][0]) {  // means spacer used, not a thumbnail
		document[imgname].src = "images/spacer.gif";   // clear current picture
		if (gConfig[iGallery][10]>"") {
			document.all(gConfig[iGallery][10]).innerHTML = "&nbsp;";
		}
	}
	else {	
		document[imgname].src = imghdr + gPicture[iGallery][imgnum] + imgtail;
		if (gConfig[iGallery][10]>"") {
			document.all(gConfig[iGallery][10]).innerHTML = gText[iGallery][imgnum];
		}
	}
}

function NR_jumpToSection() {
//	var urlquery, urlterms;
//	urlquery = location.href.split("?");
	return (urlquery[1]=="x"?10:1);
}

