var u,this_wait,picdoc,num_pix=0,MOBILE="";
function go(){
 u=getURL();
 picdoc=parent.pix.document;
 writeStart();
}
function writeStart(){
 picdoc.open("text/html","replace");
 picdoc.write("<html><body link=0000FF vlink=0000FF topmargin=0 marginheight=0 marginwidth=0 leftmargin=0><tt><center><form action=''>o <a href='javascript:parent.main.first()'>go to first in series</a>"+
  " o <a href=http://rawdataserver.com/cgi-bin/a/my.cgi target=_top>favorites</a>"+
  " o <a href=http://aminaked.com/ target=_top>aminaked</a>"+
  " <nobr>o <a href='javascript:void(parent.main.showDirectory())'>directory</a> "+
  "<input type=button value=' < ' onclick='parent.main.changeDirectory(\""+u+"\",-1)'>"+
  "<input type=button value=' > ' onclick='parent.main.changeDirectory(\""+u+"\",1)'></nobr>"+
  "</form><br>");
 if(u==""){picdoc.write("<font color=FF0000 size=+1>URL required. Example:<br><br>http://hostA.com/series.html?url=http://hostB.com/pic1.jpg</font>");picdoc.close();
 }else writePix();
}
function writePix(){
 var mobw="",mobsp=" ";
 if(MOBILE!=""){mobw=" width=480";mobsp="<br>";}
 var h="<a href='http://NAKEDBROWSER.com/"+MOBILE+"?u="+u+"' target=_top><img src='"+u+"' border=0"+mobw+"></a>"+mobsp+"<a href='javascript:parent.main.keepPic(\""+u+"\")'>keep this pic</a>"+mobsp;

var ad="";
if(num_pix==0||num_pix==21)ad=getAd(0);
else if(num_pix==3||num_pix==9){if(MOBILE=="")ad=getAd(728);}
else if(num_pix==15||num_pix==25)ad=getAd(300);
//else if(num_pix==6||num_pix==12)h="<table><tr><td>"+getAd(120)+"</td><td>"+h+"</td></tr></table>";
//else if(num_pix==15||num_pix==18)h="<table><tr><td>"+getAd(160)+"</td><td>"+h+"</td></tr></table>";
//else if(num_pix==30){ad=getAd(300);ad="<table><tr><td>"+ad+"</td><td>"+ad+"</td></tr></table>";}

 picdoc.write(ad+h+"<br><br>");

 this_wait=0;
 u=changeURL(u,1,false);
 wait();
}
function getAd(w){
var h=0;
if(w==468)h=60;
else if(w==728)h=90;
else if(w==300)h=250;
else if(w==120||w==160)h=600;
else return "<IFRAME SCROLLING=NO FRAMEBORDER=0 WIDTH=99% HEIGHT=50 MARGINWIDTH=0 MARGINHEIGHT=0 SRC=/dude/series/firefoxad.html></IFRAME>";
return "<IFRAME FRAMEBORDER=0 WIDTH="+w+" HEIGHT="+h+" MARGINWIDTH=0 MARGINHEIGHT=0 SRC=firefoxad"+w+"x"+h+".html SCROLLING=NO></IFRAME><br><br>";
}
function wait(){
 this_wait++;
 if(this_wait>20)
  picdoc.write("<font size=+4>looks like there's no more :( <a href='javascript:parent.main.more()'>TRY ANYWAY!</a></font>");
 else if(++num_pix>34){
  picdoc.write("<a href='javascript:parent.main.more()'><b><font size=+4>MORE PIX >></font></b></a>");
  picdoc.close();
 }else{

writePix();

/*
//if(picdoc.images[picdoc.images.length-1].complete)
   writePix();
//else setTimeout("wait()",1000);
*/

 }
}
function showDirectory(){
 var r=u.match(/^(.*\/)/);
 if(r==null){
  alert("Sorry, can't figure out how to get the directory information from this URL.");
  return;
 }
 window.open(r[1],"","");
}
function changeDirectory(url,n){
 u=changeURL(url,n,true);
 if(u!=url)more();
}
function changeURL(url,goNumber,dir){
 var a,b,n,r=url.match(/^(.*\D)(\d+)(.*)/);
 a=r[1];
 n=r[2];
 b=r[3];
 if(dir){
  var y=url.indexOf("://");
  y=url.indexOf("/",y+3);
  var search=a.substring(y);
  var myResult=search.match(/^(.*\D)(\d+)(.*)/);
  if(myResult==null||myResult.length<3){
   alert("Sorry, can't figure out how to change this URL to go to the next directory.");
   return url;
  }
  a=url.substring(0,y)+myResult[1];
  n=myResult[2];
  b=myResult[3]+r[2]+r[3];
 }
 var lenWithZeros=(""+n).length;
 var lenNoZeros=((n-0)+"").length;
 var original_number=n;
 n=(goNumber-0)+(n-0);
 if(n<0){
  if(goNumber<-1)goToPic(-1*original_number,dir);
  else alert("Sorry, won't go negative.");
  return url;
 }
 var nString=""+n;
 while(lenWithZeros>nString.length)
  nString="0"+nString;
/*
 var newNumberLengthNoZeros=((nString-0)+"").length;
 if(lenNoZeros>newNumberLengthNoZeros){
  alert("NOTE! We're adding a zero to the URL. So instead of this:\n\n"
  +a+n+b+"\n\nthe URL is now this:\n\n"+a+nString+b
  +"\n\nAdding the zero(s) may not be necessary. If no picture shows up next,"
  +"\ndelete the zero(s) in your browser's location field & try again.");
 }
*/
 var newURL=a+nString+b;
 return newURL;
}
function first(){
 u=getURL();
 var r=u.match(/^(.*\D)(\d+)(.*)/);
 if(r==null||r.length<3){
  alert("Sorry, can't figure out how to go to the first pic in the series.");
  return;
 }
 var a=r[2],z=r[3],b="",zeros_then_one=false;
 if(a.length>1&&a.indexOf("1")==a.length-1){
  var zeros=true;
  for(var j=0;j<a.length-1;j++){
   if(a.charAt(j)!="0"){
    zeros=false;
    break;
   }
  }
  zeros_then_one=zeros;
 }
 if(zeros_then_one)b="1";
 else{
  for(var i=0;i<a.length-1;i++)b+="0";
  b+="1";
/*
  var t="We will now try to load the series from the first picture,\nhowever, the picture may not exist on this server.";
  if(b.charAt(0)=="0")t+="\n\nOR it may not be named "+b+z+". If pictures do not appear,\nyou can click this link AGAIN to load 1"+z+". (No zero.)";
  alert(t);
*/
 }
 u=r[1]+b+r[3];
 more();
}
function getHost(){
 var u=parent.location.href,i=u.indexOf("?");
 if(i>-1)u=u.substring(0,i);

var mobile_hack="";
if(MOBILE!="")mobile_hack="m";

 return u+"?"+mobile_hack+"url=";
}
function getURL(){
 var url=parent.location.href,i=url.indexOf("url=");
 MOBILE=url.indexOf("murl=");
 if(MOBILE>0)MOBILE="m/";
 else MOBILE="";
 if(i>-1){
  url=url.substring(i+4);
  while(true){
   var apos=url.indexOf("'");
   if(apos<0)break;
   var a=url.substring(0,apos),b=url.substring(apos+1);
   url=a+"%27"+b;
  }
  return url;
 }
 return "";
}
function more(){parent.setLocation(getHost()+u);}
function keepPic(url){window.open("http://rawdataserver.com/cgi-bin/a/my.cgi?add="+url,"","height=205,width=515,location=no,resizable=yes,menubar=yes,personalbar=no,status=no,toolbar=no");}