var port =[], dur = 4, blend_speed = 2, crossFadeDuration =2, photos=[], ct=0, imgct=1, timer, running=false;
var splash = [], splashes = [], sct=0, simgct=1;
function pagePreload()
{

 for (i=0;i<PortCt;i++)
  {
  var newsrc = PhotoID+"PORT", newid = new String(i);
  for(j=0;j<(6-newid.length);j++){newsrc+="0";}
  newsrc+=newid;
  loadpid(newsrc);
  }

 if (document.images && document.portimg)
  {
    if (port.length==0)
      {
      var defsrc = new String('/scripts/prpv.dll?photo?s='+siz+'&c='+bgc+'&i=0000PORT000000')
      document.portimg.src = defsrc;
      }
    else
      {
	   for (i=0;i<port.length;i++)
        {
        if(port[i]&&(port[i].cap||port[i].cop))
         {
         if (document.portimg.src.substr(document.portimg.src.indexOf('i='),document.portimg.src.length)==port[i].src.substr(port[i].src.indexOf('i='),port[i].src.length))showCap(i);
         }
        }
      document.portimg.src = port[0].src;
      }
  }

 

 if (document.images && document.portimg && port.length>0)
  {
   timer = setTimeout('showPort()',dur*1000);
  }
 if (document.images && document.splashimg && splash.length>0)
  {
   timer = setTimeout('showSplash()',dur*1000);
  }
}


function showCap(Cap)
{
  for (i=0;i<port.length;i++)
   {
   MM_showHideLayers("Cap"+i,'','hide')
   }
  MM_showHideLayers("Cap"+Cap,'','show')
}

function wCaps()
{
var vApp = navigator.appVersion, lHeight=32;
if (vApp.indexOf('Macintosh')!=-1)lHeight = lHeight*.6875;
for (i=0;i<port.length;i++)
 {
 var wLayer = new String('\<div class="regular" id="Cap'+new String(i)+'" style="position:absolute; width:340px; height:'+new String(lHeight)+'px; z-index:1; left: 35px; top: 422px; visibility: hidden"\>'+port[i].cap+'\<BR\>\<font size="-2" face="arial" color="#000000"\>'+port[i].cop+'\</font\>\</div\>');
 document.write(wLayer);
 }
}

function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}

function MM_showHideLayers() { //v3.0A Modified by Al Sparber and Massimo Foti for NN6 Compatibility

  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}

function loadport(src, url, cap, cop)
{
 this.src = src;
 this.url = url;
 this.cap = cap;
 this.cop = cop;
}

function loadsplash(src)
{
 this.src = src;
}

function loadpid(pid, cap, cop)
{
 if (pid)
   {
   var src='/scripts/prpv.dll?photo?s='+siz+'&c='+bgc+'&i=',zoom='javascript:ZoomPhoto("/scripts/prsm.dll?Portfolio?client='+PhotoID+'&c='+CbID+'&max='+PortCt+'&start=';
   port[port.length] = new loadport(src+pid, zoom+pid.substring(8,pid.length)+'")',cap,cop);
   }
}

function loadsrc(src)
{
 if (src)
   {
   splash[splash.length] = new loadsplash(src);
   }
}

function ZoomPhoto(url)
{
if(port.length>0)
   {
   NewWindow = window.open(url,'NikonPortfolio','resizable=yes,width=600,height=600');
   NewWindow.top.focus();
   }
}

function switchPort(step)
{

 if(document.portimg && port.length>0)
  {
  timer=clearTimeout(timer);
  if (running)
   {
   if (ct+step<0)ct=port.length;
   ct=(ct+step);
   running=false;
   }
  if (ct==1 && photos.lenght==2 && step==1)ct++;
  if (ct+step<0)ct=port.length;
  ct=(ct+step);
  if (ct>port.length-1) ct=0;
  showCap(ct);
  if (! photos[ct])
   {
    photos[ct] = new Image;
    photos[ct].src = port[ct].src;
   }
   document.portimg.src = port[ct].src;
   if(document.anchors[0])
   {
   document.anchors[0].href = port[ct].url;
   }
  if (document.images && ! running)
   {
   timer = setTimeout('showPort()',dur*1000);
   }
 }
}

function showSplash()
 {
 if(document.splashimg && splash.length>0)
 {
  if (sct<0)sct=splash.length;
  if (sct>splash.length-1) sct=0;
  if (document.all)
    {
    document.splashimg.style.filter="blendTrans(duration=blend_speed)";
    document.splashimg.style.filter="blendTrans(duration=crossFadeDuration)";
    document.splashimg.filters.blendTrans.Apply() ;  
    }
  if (splashes[sct] && (splashes[sct].complete || splashes[sct].complete==null))
    {
    document.splashimg.src = splashes[sct].src;
    if (document.all)
      {
      document.splashimg.filters.blendTrans.Play();
      }
    }
    if(sct==0) sct=splash.length;
    if(sct==splash.length) sct=0;
    if (++sct>splash.length-1) sct=0;
    splashes[sct] = new Image;
    splashes[sct].src = splash[sct].src;
    timer = setTimeout('showSplash()',dur*1000);
 }
}

function setPort(pno)
{
 if(document.portimg && port.length>0)
 {
  timer=clearTimeout(timer);
  running=false;
  ct = pno-1;
  showCap(ct);
  if (! photos[ct])
   {
    photos[ct] = new Image;
    photos[ct].src = port[ct].src;
   }
   document.portimg.src = port[ct].src;
   if(document.anchors[0])
   {
   document.anchors[0].href = port[ct].url;
   }
  if (document.images && ! running)
   {
   timer = setTimeout('showPort()',dur*1000);
   }
  }
}


function showPort()
 {
 if(document.portimg && port.length>0)
 {
  if (ct<0)ct=port.length;
  if (ct>port.length-1) ct=0;
  showCap(ct);
  if (document.all)
    {
    document.portimg.style.filter="blendTrans(duration=blend_speed)";
    document.portimg.style.filter="blendTrans(duration=crossFadeDuration)";
    document.portimg.filters.blendTrans.Apply() ;  
    }
  if (photos[ct] && (photos[ct].complete || photos[ct].complete==null))
    {
    document.portimg.src = photos[ct].src;
    if (document.all)
      {
      document.portimg.filters.blendTrans.Play();
      }
    if(document.anchors[0])
     {
     document.anchors[0].href = port[ct].url;
 	}
    running=true;
    }
    if(ct==0) ct=port.length;
    if(ct==port.length) ct=0;
    if (++ct>port.length-1) ct=0;
    photos[ct] = new Image;
    photos[ct].src = port[ct].src;
    timer = setTimeout('showPort()',dur*1000);
 }
}

function checkMMDDYYYY()
{
 if(document.dateform.s.value=="mm/dd/yyyy" || document.dateform.s.value == "")
  {
  alert('Please enter a valid date before pressing find.');
  document.dateform.s.value="mm/dd/yyyy";
  return false; 
  }
  else
  {
  return true;
  }
}

function ClearThis(vDateName)
{
var enteredstring = new String(vDateName.value);
if(!(enteredstring.indexOf('mm')!=-1&&enteredstring.indexOf('all events')!=-1))
 {
 vDateName.value = "";
 }
}