var fadelay = 5000; // milliseconds between automatic image swap
var faint = 50; // milliseconds between each fade step
var fastep = 2; // percent change in each fade step
var sdir = 1;

var ci = 0;
var pi = 0;
var tid = false;
var bid = false;
var opo = 100;
var opn = 0;
var fils = 0;
var obOld = false;
var obNew = false;

var submenu=false;
var mdi = false; // window.setTimeout("prepSub()", 6000);

var vs = 0;
var vcurr = 0;
var vfram = "view1";
var vbOld = false;
var vbNew = false;
var vstp = 18;
var vow = 0;
var vnw = 0;
var vdir = 1;

function initGall()
{ vs = vws.length - 1;
  vbOld = document.getElementById("view1");
  vbNew = document.getElementById("view1");
  vbOld.style.backgroundImage = "url(" + vws[0] + ")";
  document.getElementById("caption").innerHTML = cps[0];
  bid = setInterval(playover, 9000); }

function playover()
{ ++vcurr;
  if (vcurr==vs+1) {vcurr=0;}
  return doview(); }

function moveover(n)
{ if (bid) {xbid();}
  vdir = n;
  vcurr += n;
  if (vcurr==-1) {vcurr=vs;}
  else if (vcurr==vs+1) {vcurr=0;}
  return doview(); }

function xbid()
{ clearInterval(bid); bid=false;
  document.getElementById("pauseplay").src = "images/buttonPlay.gif";
  document.getElementById("pauseplay").title = "Autoplay";
  vbOld.style.width = "0px";
  vbNew.style.width = "400px";
  vbNew.style.left = "0px"; }

function doview()
{ if (tid)
  { clearInterval(tid); tid=false;
    vbOld.style.width = "0px";
    vbNew.style.width = "400px";
    vbNew.style.left = "0px"; }
  if (vfram=="view1")
  { vfram="view2";
    vbOld = document.getElementById("view1");
    vbNew = document.getElementById("view2"); }
  else
  { vfram="view1";
    vbOld = document.getElementById("view2");
    vbNew = document.getElementById("view1"); }
  vow = 400; vnw = 0;
  vbNew.style.backgroundImage = "url(" + vws[vcurr] + ")";
  if (vdir==1)
  { vbOld.style.left = "0px"; }
  else
  { vbNew.style.left = "0px";}
  tid = setInterval(slideview, 10); }

function slideview()
{ vow -= vstp; if (vow<0) {vow=0;}
  vnw += vstp; if (vnw>400) {vnw=400;}
  if (vdir==1)
  { vbOld.style.width = vow + "px";
    vbNew.style.width = vnw + "px";
    vbNew.style.left = (400-vnw) + "px"; }
  else
  { vbOld.style.width = vow + "px";
    vbOld.style.left = (400-vow) + "px";
    vbNew.style.width = vnw + "px"; }
  if (vnw==400)
  { clearInterval(tid); tid=false;
    document.getElementById("caption").innerHTML = cps[vcurr]; } }

function pplay()
{ if (bid) { xbid(); }
  else
  { document.getElementById("pauseplay").src = "images/buttonStop.gif";
    document.getElementById("pauseplay").title = "Stop";
    moveover(1); bid = setInterval(playover, 9000); } }

function popGal()
{ if (bid) {xbid();}
  var ar=vws[vcurr].split(".");
  txt = '<img src="' + ar[0] + 'xlg.' + ar[1] + '" alt="continue" class="point" onclick="hideapop();" />';
  return showapop(txt); }

function expOrth(i)
{ var arrow=document.getElementById("orthArr"+i);
  var submn=document.getElementById("orthSub"+i);
  if (expState[i]==0)
  {expState[i] = 1; arrow.src = "images/arrow-open.gif"; submn.style.display = "block"; }
  else
  {expState[i] = 0; arrow.src = "images/arrow-closed.gif"; submn.style.display = "none"; }
  return false; }

function verifyMailer(f)
    { if (f.emName.value == "") 
	  { return popAlert("Please enter your name."); }
      else if (f.emSubj.value == "") 
	  { return popAlert("Please enter subject."); }
      else if (f.emMess.value == "") 
	  { return popAlert("Please enter message."); }
      else if (f.emCode.value == "") 
	  { return popAlert("Please enter security code."); }
	return true; }

function newCodex()
{ var f = document.mailer;
  var i = parseInt(f.cod.value) + 1;
  if (i>12) {i=1;}
  f.cod.value=i;
  if (i<10) {var n="0"+i;} else {var n=""+i;}
  document.getElementById("codex").src="images/code"+n+".gif";
  return false; }

function pkdpValid(s)
{ var patt=/[^a-z0-9_-]/;
  s=s.toLowerCase();
  if (s.length<6 || s.length>128) {return false;}
  var x = s.split("@");
  if (x.length!=2) {return false;}
  if (x[0].length<1) {return false;}
  var a = x[0].split(".");
  for (var i=0; i<a.length; i++)
  { if (a[i].length<1) {return false;}
    if (patt.test(a[i])) {return false;} }
  if (x[1].length<4) {return false;}
  var a = x[1].split(".");
  var n = a.length-1;
  if (n==0) {return false;}
  for (var i=0; i<a.length; i++)
  { if (i==n && a[i].length<2) {return false;}
    if (a[i].length<1) {return false;}
    if (patt.test(a[i])) {return false;} }
 return true; }

function pkdpRify(f)
{ var em=f.email.value;
  if (!pkdpValid(em))
  { document.getElementById("pkdperr").innerHTML = "Invalid email address!"; return false; }
  return true; }

function prepSub(i)
 { window.clearInterval(mdi);
   if (submenu)
   { var x = "linkSubMenu"+submenu; document.getElementById(x).style.display = "none";
     submenu=false; }
   mdi = window.setTimeout(function(){hideSub(i)}, 100); }
function hideSub(i)
 { if (submenu)
   { var x = "linkSubMenu"+i; document.getElementById(x).style.display = "none";
     submenu=false;
     window.clearTimeout(mdi);
     mdi = window.setTimeout(function(){hideSub(i)}, 30000); } }
function showSub(i)
 { var x = "linkSubMenu"+i; document.getElementById(x).style.display = "block";
   submenu=i;
   window.clearTimeout(mdi);
   mdi = window.setTimeout(function(){hideSub(i)}, 30000); }

function xsbid()
{ clearInterval(bid); bid=false;
  document.getElementById("pauseplay").src = "images/buttonPlay.gif";
  document.getElementById("pauseplay").title = "Autoplay";
  doop(obOld, 0);
  doop(obNew, 100); }

function initdisp()
{ fils = fs.length - 1;
//  getRandom();
  obOld = document.getElementById("pic1");
  obNew = document.getElementById("pic2");
  doop(obOld, 0);
  obNew.style.backgroundImage = "url(" + fs[0] + ")";
  document.getElementById("scaption").innerHTML = fc[0];
  bid = setInterval(splayover, fadelay); }

function getRandom()
{ pi=ci;
  while (pi==ci)
  { ci = Math.floor(Math.random()*fils); } }

function doop(obj, o)
{ if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
  { obj.style.filter = "alpha(opacity=" + o + ")"; }
  else { obj.style.opacity = (o / 100); } }

function swapper()
{ if (tid)
  { clearInterval(tid); tid=false;
    doop(obOld, 0);
    doop(obNew, 100); }
  var x = obNew;
  obNew = obOld; opn = 0;
  obOld = x; opo = 100;
  obNew.style.backgroundImage = "url(" + fs[ci] + ")";
  document.getElementById("scaption").innerHTML = fc[ci]; 
  tid = setInterval(fader, faint); }

function fader()
{ opo -= fastep; doop(obOld, opo);
  opn += fastep; doop(obNew, opn);
  if (opo<5 || opn >95)
  { clearInterval(tid); tid=false;
    doop(obOld, 0);
    doop(obNew, 100); } }

function splayover()
{ ++ci; // alert(ci);
  if (ci==fils+1) {ci=0;}
  return swapper(); }

function smoveover(n)
{ if (bid) {xsbid();}
  sdir = n;
  ci += n;
  if (ci==-1) {ci=fils;}
  else if (ci==fils+1) {ci=0;}
  return swapper(); }

function spplay()
{ if (bid) { xsbid(); }
  else
  { document.getElementById("pauseplay").src = "images/buttonStop.gif";
    document.getElementById("pauseplay").title = "Stop";
    smoveover(1); bid = setInterval(splayover, fadelay); } }

function popUp(txt)
{ return showapop(txt); }

function showapop(txt)
{ var newdiv = document.createElement("div");
  if (txt!="") {document.getElementById("padapop").innerHTML = "";}
  newdiv.innerHTML = txt;
  var container = document.getElementById("padapop");
  container.appendChild(newdiv);
  if (!document.body.scrollTop)
  { var y = document.documentElement.scrollTop;
    var y2 = document.documentElement.scrollBottom; }
  else
  { var y = document.body.scrollTop;
    var y2 = document.body.scrollBottom; }
  document.getElementById("bkg").style.top = y + "px"; 
//  document.getElementById("bkg").style.height = (y2-y) + "px"; 
  document.getElementById("bkg").style.display = "block";
  document.getElementById("dim").style.display = "block";
  return false; }

function hideapop()
{ document.getElementById("dim").style.display = "none";
  document.getElementById("bkg").style.display = "none";
  return false; }

