function randomFormula(N){
	//X[n+1]=134775813*X[n] + 1 (mod 2^32)
	return false;
}

function Random(N) {
    return Math.floor(N * (Math.random() % 1));
}

function Randum(N) {
    return (N * (Math.random() % 1)) | 0;
}

function RanSpan(MinV, MaxV) {
    return MinV + Random(MaxV - MinV + 1);
}
function getRandomNum(total){
	return Math.floor(Math.random()*total)%total;
}
function breakout(){
  if (top.location != location) {
  	document.location.href = document.location.href;
    top.location.href = document.location.href ;
  }
}
function resizeFix() {
	if (widthCheck != window.innerWidth || heightCheck != window.innerHeight){
		breakout();
	}
}
function getW(){
	if (document.layers) {
		window.onResize = resizeFix;
	}
	var widthCheck = window.innerWidth;
	widthCheck =(widthCheck)?widthCheck:screen.availWidth;
	return (widthCheck)?widthCheck:1024;
}

function fullscreen(){
	//parent.moveTo(0,0);
	//parent.resizeTo(screen.width,screen.height);
	breakout();
	self.moveTo(0,0);
	//self.resizeTo(screen.width,screen.height);
	self.resizeTo(screen.availWidth,screen.availHeight);
}

function alignwindow(tmp, XX, YY){
	var newX = (screen.width >= XX) ? (screen.width-XX)/2 : screen.width;
	var newY = (screen.height >= YY) ? (screen.height-YY)/2 : screen.height;
	tmp.resizeTo(XX,YY);
	tmp.moveTo(newX,newY);
}

function normalwindow(){
	var XX = 1000; 
	var YY = 1000;
	var newX = (screen.width >= XX) ? (screen.width-XX)/2 : screen.width;
	var newY = (screen.height >= YY) ? (screen.height-YY)/2 : screen.height;
	//parent.resizeTo(XX,YY);
	//parent.moveTo(newX,newY);
	breakout();
	self.resizeTo(XX,YY);
	self.moveTo(newX,newY);
}

function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
reloadPage(true);

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=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 toggle(arg1){
  var obj=findObj(arg1);
  if (obj != null) { 
  	obj=obj.style;
	var v=obj.visibility;
	(v=='visible')?showHideLayers(arg1, '', 'hide'):showHideLayers(arg1, '', 'show');
  }
}

function show(url, wid, heigh) {
 var address = url;
 var op_wid  = wid;
 var op_heigh = heigh;
 
 var option = "'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=" + op_wid + ",height="+ op_heigh+"'";
 var new_win = window.open(address, "NewWindow", option);
 alignwindow(new_win, wid, heigh);
 if (window.focus) {new_win.focus()}
 return false;
}

function hello(){
 var okno = new Array();
 okno [1] = ["htmls/pageA.htm", 160, 240];
 okno [2] = ["htmls/pageB.htm", 240, 320];
 okno [3] = ["htmls/pageC.htm", 260, 220];
 okno [4] = ["htmls/pageD.htm", 400, 450];
 okno [5] = ["htmls/pageE.htm", 140, 200];
 okno [6] = ["htmls/pageG.htm", 500, 352];

 var seed = getRandomNum(okno.length-1);
 show(okno[seed+1][0], okno[seed+1][1], okno[seed+1][2]); 
 return true;
}

function birdie(tmp){
 //var tmp = document;
 var birds = new Array();
 for(var i=1; i<9; i++){
  birds [i] = "slides/9%20birds/thumbnails/bird-"+i+".jpg";
 }
 
 var seed = getRandomNum(birds.length-1); 

 var strrr = birds[seed+1];
 tmp.write("<img src=" + strrr + " width=122 height=110/><br>");
 return true;
}

function writeCell(tmp, num){
//var tmp = document;
 tmp.write("<td class=\"birdcell\">");
 tmp.write("<SPAN CLASS=c"+((num%8)+1)+" onClick=getPic("+num+")>");
 birdie(tmp);
 tmp.write(" <\/SPAN>"); 
 tmp.write("<SPAN id=\"lnk"+num+"\" CLASS=c"+((num%8+1)+1)+"  onClick=getPic("+num+")>["+num+"] <\/SPAN>");

 tmp.write("<\/td>");
 //-----
 var cageNum = num;
 //tmp.write("<a href=\"javaScript:showHideLayers('cage"+cageNum+"','','show')\">[test cage] <\/a>");
 drawCage(tmp, cageNum); 
 //-----
 return true;
}

function writeNumCell(num){ 
var tmp = document;
 tmp.write("<SPAN id=\"lnk"+num+"\" CLASS=\"c"+((num%8+1)+1)+"\" onClick=getPic("+num+")>["+num+"] <\/SPAN>");
 return true;
}

function showLinks(num){
 var tmp = document;
 showLinksTMP(tmp, num);
}

function showLinksTMP(tmp, num){
 var col = Math.floor((getW() - 192)/122);
 //var tmp = document;
 tmp.write("<table  class=\"allbirds\"><tr>");
  for (var i=1; i<=num; i++){
  writeCell(tmp, i); 
    
  if((i%col)==0){
  	//grid
  	tmp.write("<\/tr><tr>");
  }  

}
 tmp.write("<\/tr><\/table>");
 tmp.write("<BR><A HREF=\"javascript:history.go(0)\">[reload]<\/A> ");
 tmp.write("<A HREF=\"javascript:fullscreen()\">[full screen]<\/A> ");
 tmp.write("<A HREF=\"javascript:normalwindow()\">[normal view]<\/A><BR>");
 return true;
}

function randomPage(maxNum, minNum){
 var seed = getRandomNum(maxNum-1); 
 //
 if(maxNum >= minNum){
 	if (seed <= minNum){
 		hello();
 	}else{
 		getPic(seed+1);
 	}
 }else{
 	seed = getRandomNum(minNum-1); 
 	if (seed <= maxNum){
 		getPic(seed+1);		
 	}else{
 		hello();	
 	}
 }
 return true;
}
function drawCage(tmp, cNum){
	//var tmp = document;
	//no grid-----
	//var newX = (cNum-1)*125;
	////var neyY = cNum*138;
	//var neyY = 0;
	//grid-----
	var col = Math.floor((getW() - 192)/122);
	var nextCol = (cNum-1)%col;
	var nextRow = (cNum-1)/col - nextCol/col;
	
	var newX = nextCol * 122;	
	var neyY = nextRow * 142;
	//--------
	//shown
	//tmp.write("<div id=\"cage"+cNum+"\" style=\"position:absolute; left:"+(212+newX)+"px; top:"+(81+neyY)+"px; width:99px; height:200px; z-index:"+(cNum+1)+"; background-image: url(images\/cage-noBG.gif); layer-background-image: url(images\/cage-noBG.gif); border: 0px none #000000; visibility: visible;\"><\/div>");
	//hidden
	tmp.write("<div id=\"cage"+cNum+"\" style=\"position:absolute; left:"+(212+newX)+"px; top:"+(75+neyY)+"px; width:99px; height:200px; z-index:"+(cNum+1)+"; background-image: url(images\/cage-noBG.gif); layer-background-image: url(images\/cage-noBG.gif); border: 0px none #000000; visibility: hidden;\"><\/div>");
	return true;
}
function writeHeader(hpage){
	var tmp = document;
	tmp.write("<span class=\"textreg\">&gt;&gt; voidit.net :: "+hpage+" ::<\/span><hr size=\"1\"><br>");
}
function writeHeaderTMP(tmp, hpage){
	//var tmp = document;
	tmp.write("<span class=\"textreg\">&gt;&gt; voidit.net :: "+hpage+" ::<\/span><hr size=\"1\"><br>");
}

function writeFooterTMP(tmp, fpage, fnum){
      tmp.write("<P CLASS=\"c5\">");
      tmp.write("<SPAN CLASS=\"c2\" ONCLICK=\"show('http:\/\/www.voidit.net', '1152', '864')\">[voidit]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c3\" ONCLICK=\"show('IRpresents.html', '550', '570')\">[flash]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c4\" ONCLICK=\"show('http:\/\/pratt.edu\/%7Eiromendi', '600', '480')\">[html]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c5\" ONCLICK=\"show('http:\/\/stage.itp.tsoa.nyu.edu\/%7Eir306\/index.html', '800', '600')\">[mix]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c6\" ONCLICK=\"show('http:\/\/smoke.voidit.net', '1152', '864')\">[smoke]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c7\" ONCLICK=\"show('http:\/\/grids.voidit.net', '1152', '864')\">[knit]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c8\" ONCLICK=\"show('http:\/\/www.artbymobile.com', '1152', '864')\">[mobile]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c9\" ONCLICK=\"show('http:\/\/www.vydavy.com', '1152', '864')\">[vydavy]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c2\" ONCLICK=\"show('http:\/\/www.psych-o-path.com', '800', '600')\">[psix]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c3\" ONCLICK=\"show('Voidit\/zhuki.htm', '640', '480')\">[zhuki]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c4\" ONCLICK=\"show('Voidit\/laika.htm', '640', '480')\">[laika]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c5\" ONCLICK=\"show('Voidit\/Room2.htm', '400', '420')\">[pan]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c6\" ONCLICK=\"show('Voidit\/home.htm', '1152', '864')\">[home]  <\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c7\" ONCLICK=\"randomPage(" + fnum + ", '1')\"><strong>[random] <\/strong><\/SPAN>");
	  tmp.write("<SPAN CLASS=\"c8\" ONCLICK=\"show('htmls\/SendComments.html', '640', '480')\">[comment]  <\/SPAN>");
	  tmp.write("<A HREF=\"mailto:irena@voidit.net?subject=%5B%3E%3E%20voidit%20::%20" + fpage + "%5D\">[contact]<\/A>");
   	  tmp.write("<\/P>");
	return true;
}
function writeFooter(fpage, fnum){
	var tmp = document;
	writeFooterTMP(tmp, fpage, fnum);
}