var templock;
function showimg(url) {
  if (!document.getElementById("shadow")) {
    newdiv = document.createElement("div");
    newdiv.setAttribute("id","shadow");
    newdiv.onclick=hideimage;

    newdiv.style.filter="alpha(opacity:0)";
    newdiv.style.opacity="0";
    document.getElementsByTagName("body")[0].appendChild(newdiv);
    }
  else {
    document.getElementById("shadow").style.filter="alpha(opacity:0)";
    document.getElementById("shadow").style.opacity="0";
    document.getElementById("shadow").style.display="block";
    }
  if (!document.getElementById("fncimage")) {
    newimg = document.createElement("img");
    newimg.setAttribute("id","fncimage");
    newimg.setAttribute("src", url);
    newimg.setAttribute("height", "480");
    newimg.setAttribute("width", "640");
    newimg.onclick=hideimage;
    newimg.style.filter="alpha(opacity:0)";
    newimg.style.opacity="0";
    document.getElementsByTagName("body")[0].appendChild(newimg);
    }
  else {
    document.getElementById("fncimage").src=url;
    document.getElementById("fncimage").style.filter="alpha(opacity:0)";
    document.getElementById("fncimage").style.opacity="0";
    document.getElementById("fncimage").style.display="block";
    }
  if (isie6==1) {
    }
  else {
    window.onresize=positionfncimage;
    positionfncimage();
    }
  opacity("shadow",0,60,500);
  opacity("fncimage",0,100,500);
  }


function hideimage() {
  opacity("shadow",60,0,500);
  opacity("fncimage",100,0,500);
  if (templock== true) {
    templock=false;
    auto();
    }
  }

function positionfncimage() {
  if (window.innerWidth) {
      leftpixel= window.innerWidth / 2 - 320;
      toppixel= window.innerHeight / 2 - 240;
      }
    else if (document.documentElement.clientHeight > 0) {
      leftpixel= document.documentElement.clientWidth / 2 - 330;
      toppixel= document.documentElement.clientHeight / 2 - 240;
      }
    else {
      leftpixel= document.body.clientHeight / 2 - 320;
      toppixel= document.body.clientHeight / 2 - 240;
    }
  document.getElementById("fncimage").style.left=leftpixel+"px";
  document.getElementById("fncimage").style.top=toppixel+"px";
  }

function getradiovalue(radio) {
radio = document.getElementsByName(radio);
for (var i=0; i < radio.length; i++)
   {
   if (radio[i].checked)
      {
      var rad_val = radio[i].value;
      }
   }
   return rad_val;
}
function getElementsByClass(searchClass,node,tag) {//thank you http://www.dustindiaz.com/
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function rewrite(whatid, towrite) {
  if (document.getElementById && document.createElement) {
    document.getElementById(whatid).innerHTML=towrite;
    }
}

function findbigimage(){
bigimg= imagespath+this.src.substring(this.src.lastIndexOf("/")+3);
if (lock == true) {
  templock= true;
  auto();
  }
showimg(bigimg);
}

window.onload= function setup(){
document.getElementById("slideimage").onclick=findbigimage;
auto();
}
isie6=0;


function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

var ImgNum = 0;
var ImgLength = NewImg.length - 1;

var lock = false;
var run;
function chgImg(direction) {
if (document.images) {
ImgNum = ImgNum + direction;
if (ImgNum > ImgLength) {
ImgNum = 0;
}
if (ImgNum < 0) {
ImgNum = ImgLength;
}
document.getElementById("slideimage").src = imagespath+NewImg[ImgNum];
   }
}
function auto() {
if (lock == true) {
lock = false;
rewrite("autostop","Play Slideshow")
window.clearInterval(run);
}
else if (lock == false) {
lock = true;
rewrite("autostop","Stop Slideshow")
run = setInterval("chgImg(1)", delay);
   }
}
// deep thanks to the original author of the next two functions, found at http://brainerror.net/scripts/javascript/blendtrans/
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    if (opacity==0) object.display="none";
    else object.display="block";
}
