//a work in progress
var data=[],datb=[],holes=new Array(6),timezero=new Date(0);waitStart=timezero;adStart=new Date(),indexa=-1,indexb=-1,PAUSE=0,recipe='',LASTUNPAUSE=timezero;
function hole(bday,url,code,hold,xofy){this.bday=bday;this.url=url;this.code=code;this.hold=hold;this.xofy=xofy;}
function init(){
holes=new Array(6);
for(var i=0;i<holes.length;i++)holes[i]=new hole(timezero,"","",0,"");
loadCookies();
cookie2ui();
loadBaseData();
writeLowAd();
setFocus();
setTimeout("document.getElementById('welcome').innerHTML=''",60000);
}
function loadCookies(){recipe=getCookie('hjh');if(!recipe&&navigator.userAgent.toLowerCase().indexOf('firefox')>0)document.control['plugin'].checked=true;}
function saveCookies(){
var c=document.control;
var s='';
for(var i=0;i<c.length;i++){
var n=c[i].name;
if(n){
 var v=c[i].value;
 if(c[i].type&&c[i].type=='checkbox')v=c[i].checked;
 s+="<"+n+">"+v+"</"+n+">";}
}
if(recipe!=s){
 setCookie('hjh',s);
 recipe=s;
}
}
function cookie2ui(){
var c=document.control;
for(var i=0;i<document.control.length;i++){
 if(c[i].name){
  var v=getSetting(c[i].name);
  if(v){
   if(c[i].type&&c[i].type=='checkbox'){
    if(v=='true')c[i].checked=true;
    else c[i].checked=false;
   }else c[i].value=v;
  }
 }
}
}
function getSetting(s){
var a=recipe.indexOf("<"+s+">");
var b=recipe.indexOf("</"+s+">",a);
if(a<0||b<a)return '';
return recipe.substring(a+s.length+2,b);
}
function getCookie(key){
 var c=document.cookie;
 var a=c.indexOf(key+"="); //buggish?
 if(a<0)return "";
 a+=key.length+1;
 var b=c.indexOf(";",a);
 if(b<=a)return c.substring(a);
 return c.substring(a,b);
}
function setCookie(key,val){
 if(getCookie(key)==val)return;
 var d=new Date(),p=Date.parse(d);
 d.setTime(p+365*24*60*60*1000);
 var u=d.toUTCString();
 document.cookie=key+"="+val+";expires="+u;
}
var PIX=new Array(6);
function goa(){
saveCookies();
if(PAUSE){setTimeout("goa()",500);return;}

var pw=document.control['pw'].value-0;

if(!document.control['pok'].checked)pw=0;

if(pw<5){
 for(var i=0;i<6;i++)document.getElementById('p'+i).innerHTML='';
 setTimeout("goa()",2500);
 return;
}else if(pw>2000)pw='';
else pw=' width='+pw;

var pause=document.control['pp'].value-0;
if(pause<1)pause=1;else if(pause>600)pause=600;
pause*=1000;


for(var i=5;i>0;i--)PIX[i]=PIX[i-1];

if(Math.random()>.05){
 if(++indexa>data.length)indexa=0;
 PIX[0]=data[indexa];
}else PIX[0]='ad';

for(var i=0;i<6;i++){
 document.getElementById('p'+i).innerHTML='';
 if(PIX[i]=='ad')document.getElementById('p'+i).innerHTML=getAd(document.control['pw'].value-0);
 else if(PIX[i])document.getElementById('p'+i).innerHTML="<a href=\"http://NAKEDBROWSER.com/?x=h&u="+PIX[i]+"\" target=_blank onclick='pauseAll(1);setFocus()'><img"+pw+" src=\""+PIX[i]+"\" border=0 title='Click to see more'></a>";
}
if(indexa+1<data.length){var im=new Image();im.src=data[indexa+1];}

setTimeout("goa()",pause);
}

/*
hilite movie 2 seconds before changing it

(un)check mov/pic checkboxes should have immediate effect
*/

function gob(){
saveCookies();
if(PAUSE){setTimeout("gob()",500);return;}
var pause=document.control['mp'].value-0;if(pause<1)pause=1;else if(pause>600)pause=600;pause*=1000;
var now=new Date();
if(now-waitStart<pause){
 setTimeout("gob()",500);
 return;
}
waitStart=now;
var num_movies=getNumMovies();
var oldest=now,oldi=-1;
for(var i=0;i<holes.length;i++){
 if(i<num_movies){if(holes[i].hold<1&&now-holes[i].bday>pause&&holes[i].bday<oldest){oldest=holes[i].bday;oldi=i;}}
 else if(holes[i].url!=""){holes[i].url="";holes[i].hold=0;document.getElementById('m'+i).innerHTML="";}
}
if(oldi<0){
 setTimeout("gob()",500);
 return;
}
if(num_movies>1&&now-adStart>100000&&now-LASTUNPAUSE>pause){
 adStart=now;
 holes[oldi].url='a';
 holes[oldi].hold=0;
 holes[oldi].bday=now;
 document.getElementById('m'+oldi).innerHTML="<table width="+mWidthHack+"<tr><td>"+getAd(mWidthHack)+"</td></tr></table>";
 setTimeout("gob()",500);
 return;
}
nextForHole(oldi);
setTimeout("gob()",500);
}
function nextForHole(n){
holes[n].hold=0;
if(++indexb>datb.length){
// requestData("http://rawdataserver.com/cgi-bin/a/mm.cgi?hjh=1");
 indexb=0;
}
var r=parseMovieData(datb[indexb]);
holes[n].code=r[0];
holes[n].xofy=r[1];
holes[n].url=r[2];
writeHole(n);
}
function getNumMovies(){var n=document.control.nm.value-0;if(!document.control['mok'].checked)n=0;return n;}
var mWidthHack=200;
function writeHole(mnum){
var hole=holes[mnum];
hole.bday=new Date();
var num_movies=getNumMovies();
var movie_cols=2;if(num_movies>4)movie_cols=3;
var movie_rows=1;if(num_movies>2)movie_rows=2;
var w=0,h=40;
if(navigator.userAgent.indexOf('MSIE')<0){w=self.innerWidth;h=self.innerHeight;}
//else if(navigator.userAgent.indexOf('MSIE 7.0')>-1){w=document.body.clientWidth;h=document.body.clientHeight;}
else{w=document.body.clientWidth;h=document.body.clientHeight;}
w-=2;//scrollbar
w-=4;//uihackz
if(num_movies>1){
 w-=25;//scrollbar
 if(document.control['pok'].checked)w-=document.control['pw'].value;
 w=w/movie_cols;
 if(w<250)w=250;
}
mWidthHack=w;
//var h=w*.75+40;//40 for movie controls (15 quicktime, 40 MSIE) but non-IE can use MS crap
h-=25*movie_rows;//for movie controls
h=h/movie_rows;
var wh='';
if(w>2000||h>2000)wh='';
else wh=" width="+w+" height="+h;
var u=hole.url;
var c=hole.code;
var held='';
if(hole.hold)held='On';
var html="<embed src='"+u+"' autostart=true autostart loop=true"+wh+"></embed>";
var ie7bs='';
if(navigator.userAgent.indexOf('MSIE 7.0')>-1)ie7bs=" CLASSID='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'";
if(document.control['plugin'].checked)html="<OBJECT"+wh+ie7bs+"><PARAM NAME=FileName VALUE='"+u+"'><PARAM NAME=URL VALUE='"+u+"'><PARAM NAME=AutoStart VALUE=1><PARAM NAME=AutoSize VALUE=1><PARAM NAME=ShowStatusBar VALUE=1><PARAM NAME=DisplaySize VALUE=0><PARAM NAME=ShowControls VALUE=1><PARAM NAME=ShowPositionControls VALUE=0><embed src='"+u+"'"+wh+" TYPE='video/x-ms-asf-plugin' SHOWCONTROLS=1 SHOWPOSITIONCONTROLS=0 SHOWSTATUSBAR=1 AUTOSIZE=1 DISPLAYSIZE=0 loop=true playcount=9999"+wh+"></embed></object>";
var controls="<br>&nbsp;<font face=arial><a href=\"javascript:void(more("+mnum+",'first'))\" class=nFirst>|&lt;</a> <a href=\"javascript:void(more("+mnum+",-1))\" class=nPlain>&lt;back</a> <a href=\"javascript:void(more("+mnum+",1))\" class=nNext>next&gt;</a> ^ <a href=\"javascript:void(skip("+mnum+"))\" class=nSkip>skip</a> / <a href=\"javascript:void(hold("+mnum+"))\" class=nHold"+held+" id=hold"+mnum+">hold</a> ^ <a href=\"http://NAKEDBROWSER.com/?u=http://NAKEDBROWSER.com/mm/"+c+".jpeg\" target=_blank onclick='pauseAll(1);setFocus()' class=nPlain>popup</a> ^ <a href=javascript:void(s(\"http://NAKEDBROWSER.com/mm/"+c+".jpeg\")) class=nPlain>keep</a> ^ <b>"+hole.xofy+"</b></font>";
html+=controls;
document.getElementById('m'+mnum).innerHTML="";
document.getElementById('m'+mnum).innerHTML=html;
}
function pauseAll(p){
if(p||PAUSE<1){PAUSE=1;document.control[0].value="CONTINUE SLIDESHOW";document.getElementById('pauseAlert').innerHTML="<font color=FF0000 size=+4><b>&nbsp;SLIDESHOW PAUSED</b></font>";}
else{PAUSE=0;waitStart=timezero;LASTUNPAUSE=new Date();document.control[0].value="Pause Slideshow";document.getElementById('pauseAlert').innerHTML="";}
}
function setFocus(){document.control[0].focus();}
function setFocusUIhackz(){document.uihackz[0].focus();}
function writeLowAd(){
//if(!PAUSE)
document.getElementById('lowad').innerHTML='<table><tr><td bgcolor=FFFFFF>Thank you for your support!<iframe width=200 src=ad2.html frameborder=0 scrolling=no></iframe></td></tr></table>';
//setTimeout("writeLowAd()",120000);
}
function getAd(w){
if(w<300||Math.random()<.1){
 if(w)w=" width="+(w-0);
 return "<div align=center><iframe src=ad.html frameborder=0 scrolling=no"+w+"></iframe></div>";
}else return "<div align=center><iframe src=ad300x250.html frameborder=0 scrolling=no width=300 height=315></iframe></div>";
}
function requestData(url){
 var r=false;
 if(window.XMLHttpRequest){
  try{r=new XMLHttpRequest();}
  catch(e){r=false;}
 }else if(window.ActiveXObject){
  try{r=new ActiveXObject("Msxml2.XMLHTTP");}
  catch(e){
   try{r=new ActiveXObject("Microsoft.XMLHTTP");}
   catch(e){r=false;}
  }
 }
 if(r){
  r.open("GET",url,true);
  r.onreadystatechange=function(){if(r.readyState==4&&r.status==200)receiveData(r.responseText)}
  r.send(null)
 }
}
function receiveData(d){
 if(d.indexOf("a(d);}</s")>0)processPicData(d);
 else if(d.indexOf("b(d);}</s")>0)processMovieData(d);
 else processMore(d);
}
function loadBaseData(){requestData("http://rawdataserver.com/pb/pornborg0.html");}
function processPicData(d){
requestData("http://rawdataserver.com/cgi-bin/a/mm.cgi?hjh=1");
d="data"+d.substring(d.indexOf("="));
eval(d.substring(0,d.indexOf("']")+3));
data.sort(new Function("return .5-Math.random()"));
goa();
}
function processMovieData(d){
d="datb"+d.substring(d.indexOf("="));
eval(d.substring(0,d.indexOf("']")+3));
datb.sort(new Function("return .5-Math.random()"));
gob();
}
function skip(n){setFocusUIhackz();nextForHole(n);

//yoyo report bad mm if (new Date())-holes[n].bday<9!!!!!!!!!!!!!!!!

}
function parseMovieData(u){
var r=new Array(3);
var s=u.indexOf(";");
r[0]=u.substring(0,s);
u=u.substring(s+1);
s=u.indexOf(";");
r[1]=u.substring(0,s);
r[2]=u.substring(s+1);
return r;
}
function hold(n){
if(holes[n].hold){document.getElementById('hold'+n).style.backgroundColor='white';holes[n].hold=0;}
else{document.getElementById('hold'+n).style.backgroundColor='red';holes[n].hold=1;}
setFocusUIhackz();
}
function more(n,go){
setFocusUIhackz();requestData("http://rawdataserver.com/cgi-bin/a/mm.cgi?more="+holes[n].url+"&id="+holes[n].code+"&go="+go+"&m="+n);}
function processMore(d){
var r=parseMovieData(d);
var n=r[0];//hack
holes[n].xofy=r[1];
holes[n].url=r[2];

//yoyo move hidden button to middle area w/ all controls...and unhide it!?

 writeHole(n);
}
function s(u){setFocusUIhackz();void(window.open('http://rawdataserver.com/cgi-bin/a/my.cgi?add='+u,'','height=205,width=515,resizable=yes,location=no,menubar=yes,personalbar=no,status=no,toolbar=no'));}