var imgct=5, src=[], url=[], imagenames=[], cti=0, dur = 3, blend_speed = 1, ads=[], ct=0;

for (i=0;i<PortCt;i++)
 {
 var newsrc = "/scripts/prpv.dll?photo?s=100&c="+bgc+"&i="+PhotoID+"PORT", newid = new String(i);
 for(j=0;j<(6-newid.length);j++){newsrc+="0";}
 src[i] = [newsrc+newid];
 url[i]="javascript:ZoomPhoto('/scripts/prsm.dll?Portfolio?client="+PhotoID+"&c="+CbID+"&start="+newid+"&max="+PortCt+"')"
 }

//if(PortCt==7)imgct=4;
//if(PortCt<7)imgct=3
//if(PortCt<5)imgct=5;
imgct=4;

for (i=0;i<imgct;i++)
 {
 var newsrc="porth", newid=new String(i);
 for (j=0;j<(2-newid.length);j++){newsrc+="0";}
 imagenames[i] = [newsrc+newid];
 }


function ZoomPhoto(url)
{
  window.open(url,'portfolio13','resizable=yes,width=488,height=550')
}


function switchAd()
 {

 var ni=(imgct+cti)%(imgct), n=(ct+1)%src.length;
 if (document.all)
   {
   document[imagenames[ni]].style.filter="blendTrans(duration=blend_speed)"
   document[imagenames[ni]].style.filter="blendTrans(duration=crossFadeDuration)"
   document[imagenames[ni]].filters.blendTrans.Apply()   
   }
 if (ads[n] && (ads[n].complete || ads[n].complete==null))
   {
   document[imagenames[ni]].src = ads[ct=n].src;
//   alert('imagenames index='+ni+' ads index='+ct);
   if (document.all)
     {
     document[imagenames[ni]].filters.blendTrans.Play()
     }
   document.anchors[ni].href = url[ct];
   }

 ads[n=(ct+1)%src.length] = new Image;
 ads[n].src = src[n];
 if(imgct!=4)
  {
  cti=(ni+imgct-2);
  }
  else
  {
  switch(ni)
   {
   case 0:
    cti=2;
    break;
   case 1:
    cti=3;
    break;
   case 2:
    cti=1;
    break;
   case 3:
    cti=0;
    break;
    }
 }
 setTimeout("switchAd()",dur*1000);
}

function pagePreload()
{
 if (document.images&&PortCt!=0)
  {
  j=(PortCt<5) ? PortCt:4;
  if(PortCt<5)
   {
   for (i=0;i<j;i++)
    {
    document[imagenames[i]].src=src[i];
    document.anchors[i].href=url[i];
    }
   }
   else
   {
    document[imagenames[0]].src=src[2];
    document.anchors[0].href=url[2];
 
    document[imagenames[1]].src=src[0];
    document.anchors[1].href=url[0];
 
    document[imagenames[2]].src=src[3];
    document.anchors[2].href=url[3];   
 
    document[imagenames[3]].src=src[1];
    document.anchors[3].href=url[1];
 
    j--;
    startShow(j);
   }
  }
}

function startShow(j)
{
 if(PortCt>4)
  {
   if (document[imagenames[j]] && (document[imagenames[j]].complete || document[imagenames[j]].complete==null))
    {
    cti=2;
    ct=4;
    setTimeout("switchAd()",dur*1000);
    }
    else
    {
    startShow(j);
    }
   }
}
