/*circumpix display system: &copy; John McAllister 2009, panavista.eu*/
var hand="right",wait=30,step=2,Tx,Tl,Tm,Tt,Tb,Vf,Vw,Vh,Vx,Lx,Vt,Iw,D,Ix,path,Mix=[],Mx=[],Pix=[],Pw=[],H=[],Hw=[],Hg=[],R=[],Tv=[],Pp=[],Ppw=[],Mw=[],Xw=[],Sn=Fp=maxi=mini=set=fast=dice=end=stop=spin=0,done=true,base=((window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight)-700)/2,Sw=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,Sm=Sw/2,setGap=60,pre=new Image(),guest="",domain="www.panvista.eu/?",logo,lS,hL,sL,Ml,eK,qK,wK,mK,nM,fM,eM,mM,bM;
(function(){var S=["<style>#wrap{bottom:",base<2?2:base,"px}#linklist{height:",base<12?657-Math.abs(base*2):721,"px}#menubox{height:",base<12?536-Math.abs(base*2):598,"px}#Vdiv{left:",Sw>1800?Sm-900:0,"px;width:",Sw>1800?1800:Sw,"px}",base<2?"#Wdiv{top:182px}#email{top:100px}":null,"</style>"];document.write(S.join(""));Sw=Sw>1800?1800:Sw})();
function Vista(n,m){maxi=mini&&Pix[n][3][0]&&!m?false:true;var count=!maxi?1:Pix[n][2].length;path=Pix[n][1];Vw=Vh=0;Tv=[];location.replace("#"+Guest()+"."+n+"."+spin);clearInterval(D);Get("Vdiv").innerHTML="";Vf.clip="rect(auto "+Sm+"px auto "+Sm+"px)";Ix=n+1;Get("m"+n).className="seen";H.push(n);bM.display=Hg.length>=2?"none":"block";if(!maxi)Pp[n][2]=null;else Pp[n][0]=null;Show(true);lS.innerHTML="<img src=\"load.gif\" />";nM.display=lS.style.display="block";if(Pix[n][4]){set=Pix[n][4][0]=="set"?true:false;if(Pix[n][4][1])hand=Pix[n][4][1]}for(var v=0;v<count;v++){Tv[v]=!maxi?Pix[n][3]:Pix[n][2][v];Vw+=Tv[v][1];Vh=Math.max(Vh,Tv[v][2])}Vh+=Vh%2;if(set)Vw+=(count*setGap);Iw=Vw;hand=hand=="right"?"left":"right";if(hand=="right"&&!set)Tv.reverse();if((maxi||spin||(mini&&Iw>Sw))&&Pix[n][2].length!==1){for(var q=0,extra=spin?0:Sm;extra<Sw;q++){Tv[count+q]=Tv[q];extra+=Tv[q][1];Vw+=Tv[q][1]}if(set)Vw+=(q*setGap)}var vista=Make("div");vista.id="vista";if(hand=="right")vista.dir="rtl";vista.style.width=Vw+"px";vista.style.height=Vh+"px";vista.style.top=320-Vh/2+"px";Get("Vdiv").appendChild(vista);Vt.color="rgb(96,96,96)";Get("legend").innerHTML=Pix[n][0];Vt.bottom=354-Vh/2+"px";Vx=Get("vista").style;Tm=Sm-Vw;Tx=Sm;Tl=Sm-Iw+Vh/2;var data=Tv.shift(),tile=Make("img");tile.onload=Boot;tile.onerror=Show;tile.src=path+data[0];tile.width=data[1];tile.height=data[2];if(set)tile.className="gaps";if(mini&&!m){var anchor=Make("a");anchor.href="#";anchor.title="Click for full-size view";anchor.onclick=function(){Mag();return false};anchor.onmouseover=State;anchor.appendChild(tile);vista.appendChild(anchor)}else vista.appendChild(tile)}
function Tiles(){if(Tv.length>0){var data=Tv.shift(),tile=Make("img");tile.onload=function(){setTimeout(Tiles,0)};tile.onerror=Show;tile.src=path+data[0];tile.width=data[1];tile.height=data[2];if(set)tile.className="gaps";if(mini&&Tv.length<2){var anchor=Make("a");anchor.href="#";anchor.title="Click for full-size view";anchor.onclick=function(){Mag();return false};anchor.onmouseover=State;anchor.appendChild(tile);Get("vista").appendChild(anchor)}else Get("vista").appendChild(tile)}else Cache()}
function Boot(){stop=done=end=false;if(Sw>Iw){if(Tv.length<1){end="slot";Tt=Tb=320;Lx=320-Vh/2;Vx.left=(Sw-Vw)/2+"px";Cache();D=setInterval(Slot,wait)}else{setTimeout(Tiles,0);Lx=(Sw-Iw)/2;D=setInterval(Slip,wait)}}else{setTimeout(Tiles,0);Roll()}lS.innerHTML="";lS.style.display=nM.display=eM.display="none";Toggle()}
function Roll(){if(Sw>Iw){if(end==true)D=setInterval(Slit,wait);else D=end=="slot"?setInterval(Slot,wait):setInterval(Slip,wait)}else if(Tx>0)D=setInterval(Draw,wait);else if(Tx>Tm&&Tx<=Tl&&!spin)D=setInterval(End,wait);else D=spin?setInterval(Spin,wait):setInterval(Run,wait)}
function Draw(){if(Tx>0&&!(Tx>Sm)){Tx-=step;Vf.clip="rect(auto "+(Sw-Tx)+"px auto "+Tx+"px)";Vx[hand]=Tx+"px";if(Tx<98)Vt.color="rgb("+Tx+","+Tx+","+Tx+")"}else if(Tx>Sm){if(Tv.length>0){step*=-1;Tx-=step}else Vista(Ix-1)}else{Vf.clip="rect(auto auto auto auto)";clearInterval(D);D=spin?setInterval(Spin,wait):setInterval(Run,wait)}}
function Slip(){var c;if(Tx>Lx&&!(Tx>Sm)){Tx-=step;Vf.clip="rect(auto "+(Sw-Tx)+"px auto "+Tx+"px)";Vx[hand]=Tx+"px";c=Tx-Lx;if(c<98)Vt.color="rgb("+c+","+c+","+c+")"}else if(Tx>Sm){step*=-1;Tx-=step}else{clearInterval(D);if(spin){Tx-=step;Vx[hand]=Tx+"px";D=setInterval(Spin,wait)}else{Tt=320-Vh/2;Tb=320+Vh/2;Lx=320;Vf.clip="rect("+Tt+"px auto "+Tb+"px auto)";end=true;D=setInterval("clearInterval(D);D=setInterval(Slit,wait)",4000)}}}
function Run(){if(Tx>=Tl&&Tx<=0){Tx-=step;Vx[hand]=Tx+"px"}else if(Tx>=Tl){step*=-1;Tx-=step}else{clearInterval(D);Lx=Tt=320-Vh/2;Tb=320+Vh/2;Vf.clip="rect("+Tt+"px auto "+Tb+"px auto)";D=setInterval(End,wait)}}
function End(){var c;if(Tt<Tb&&Tt>=0){Tx-=step;Tt+=step;Tb-=step;Vx[hand]=Tx+"px";Vf.clip="rect("+Tt+"px auto "+Tb+"px auto)";c=Tt-Lx;if(c<98)Vt.color="rgb("+c+","+c+","+c+")"}else{clearInterval(D);if(step<0)D=setInterval(Run,wait); else{done=true;Next()}}}
function Slot(){var c;if(Tt>Lx){Tt-=2;Tb+=2;Vf.clip="rect("+Tt+"px auto "+Tb+"px auto)";Vx.top=Tt+"px";c=Tt-Lx;if(c<98)Vt.color="rgb("+c+","+c+","+c+")"}else{clearInterval(D);end=true;D=setInterval("clearInterval(D);D=setInterval(Slit,wait)",4000)}}
function Slit(){var c;if(Tt<Tb){Tt+=2;Tb-=2;Vf.clip="rect("+Tt+"px auto "+Tb+"px auto)";Vx.top=Tb-Vh+"px";c=Tt-Lx;if(c<98)Vt.color="rgb("+c+","+c+","+c+")"}else{clearInterval(D);done=true;Next()}}
function Spin(){if(Tx>=-Iw&&Tx<=0){Tx-=step;Vx[hand]=Tx+"px"}else Tx=Tx>0?Tx-Iw:-step}
function Exit(){clearInterval(D);Get("Vdiv").innerHTML="";lS.innerHTML="<img src=\"load.gif\" />";lS.style.display="block";Tv=[];Vt.display=Vf.display=Kbox.display=Ml.display="none";SayBye()}
function List(){clearInterval(D);dice=false;stop=true;Sn=0;Show(false);location.replace("#"+Guest()+".menu."+spin)}
function Hide(){Show(true);location.replace("#"+Guest()+"."+(Ix-1)+"."+spin);if(!done&&stop){stop=false;Toggle();Roll()}}
function Show(b){eM.display=b&&!done?"none":"block";Ml.display=hL.display=b?"none":"block";sL.display=b?"block":"none"}
function Twist(){spin=spin?0:1;Get("once").style.display=spin?"block":"none";Get("spin").style.display=spin?"none":"block";location.replace("#"+Guest()+".menu."+spin);Get("legend").innerHTML=Get("Vdiv").innerHTML="";Tv=[];done=true}
function Flip(){mini=mini?0:1;Get("maxi").style.display=mini?"block":"none";Get("mini").style.display=mini?"none":"block";Get("legend").innerHTML=Get("Vdiv").innerHTML="";Tv=[];done=true}
function Mag(){Vista(Ix-1,true)}
function Preview(ref,num){Sn=Mix[num][1];Hg.push([Fp,ref]);Vista(ref)}
function Past(){if(Sn>0)Sn++;Hg.pop();if(Hg[Hg.length-1][0]==Fp)Vista(Hg[Hg.length-1][1]);else{Wrap(Fp);Fp=Hg[Hg.length-1][0];Unwrap(Hg[Hg.length-1][0]);Vista(Hg[Hg.length-1][1])}}
function Next(){if(dice){if(R.length>0){var ref=R.pop();Hg.push([Fp,ref]);Vista(ref)}else List()}else if(Sn>0){Sn--;if(Sn==0)List();else{Hg.push([Fp,Ix]);Vista(Ix)}}else if(Ix<Pix.length){Hg.push([Fp,Ix]);Vista(Ix)}else{Hg.push([Fp,0]);Vista(0)}}
function Slow(){if(wait==20){wait=40;if(!stop){clearInterval(D);Roll()}}else if(Math.abs(step)>1)step=step>0?step-1:step+1;else wait+=20;if(!stop){clearInterval(D);Roll()}fM.display="none"}
function Fast(){if(wait>=40){wait-=20;if(!stop){clearInterval(D);Roll()}}else step=step>0?step+1:step-1;if((Math.abs(step)>2&&!fast)||Math.abs(step)>=4)fM.display="block"}
function Turn(){step*=-1;if(stop)Hold()}
function Hold(){stop=stop?false:true;Toggle();if(stop)clearInterval(D);else Roll()}
function Toggle(){wK.display=stop?"none":"block";mK.display=stop?"block":"none"}
function Guest(){return(Fp==Files.length-1&&guest)?guest:Fp}
function Start(){ObjVars();fast=new Date()-then<2000?true:false;fM.display=fast?"none":"block";function Home(){for(var i=1,j=Files.length;i<j;i++){Files[0][3].push(i)}}if(location.hash||location.search){var bobs=location.hash?location.hash:location.search,bits=bobs.slice(1).split(".");if(isNaN(parseInt(bits[0]))){Files.push(["Guest feature","sets/"+bits[0]+".js",0,[]]);guest=bits[0];bits[0]=Files.length-1;if(bits.length==1)bits.push(0);}Home();Logo(bits[1]);Fp=parseInt(bits[0]);if(bits[2]==1||bits[2]=="spin")Twist();if(bits[2]=="mini")Flip();DataScript(Files[parseInt(bits[0])][1])}else{Home();Logo();DataScript(Files[0][1])}}
function Logo(mark){var fade=0,ms=(logo.opacity==0)?0:1,pace=setInterval(Fade,20);function Load(){if(Files[Fp][2]&&mark!=-1){Hg.push([Fp,parseInt(mark)]);Vista(parseInt(mark))}else setTimeout(Load,200)};function Throw(){if(Files[Fp][2])Dice();else setTimeout(Throw,200)};function Fade(){if(fade<100){fade+=1;if(ms)logo.filter="alpha(opacity="+fade+")";else logo.opacity=(fade/100)}else{clearInterval(pace);if(mark!=null){Kbox.display="block";if(mark=="menu"||mark==-1)List();else if(mark=="dice")Throw();else Load()}else setTimeout(Splash,1000)}}}
function Splash(){var tone=97,Wdiv=Get("Wdiv").style;Wdiv.display="block";lS.innerHTML="";lS.style.display="none";Reveal();function Reveal(){if(tone<224){setTimeout(Reveal,20);tone+=2;Wdiv.color="rgb("+tone+","+tone+","+tone+")"}else Kbox.display="block"}}
function Dice(){var T=[],Rx;R=[];dice=true;Get("dice").onmouseout();for(var i=0;i<Pix.length;i++)T.push(i);for(var j=H.length-1;j>=0;j--)T[(H[j])]=null;for(var k=T.length;k>0;k--){Rx=(Math.floor(Math.random()*k));if(T[Rx]!=null)R.push(T[Rx]);T[Rx]=null;T.sort();T.length--}Next()}
function ObjVars(){Vf=Get("Vdiv").style;logo=Get("logo").style;lS=Get("load");qK=Get("quit").style;eK=Get("mail").style;hL=Get("hide").style;sL=Get("menu").style;Vt=Get("legend").style;Ml=Get("linklist").style;Kbox=Get("knobBox").style;wK=Get("stop").style;mK=Get("move").style;nM=Get("loadMask").style;fM=Get("fastMask").style;eM=Get("lastMask").style;bM=Get("backMask").style}
function Menu(){var ref=0,mx,w,x,y,z,Mt=[];if(Files.length>1){Mt.push(menuname,Files[Fp][0],"</span><ul>",choices);if(Fp!=0){Mt.push("<li><a href=\"#\"title=\" Menu Selection \"onclick=\"Select(0);return false\">",Files[0][0],"</a></li>")}for(z=0;z<Files[Fp][3].length;z++){Mt.push("<li><a href=\"#\"title=\" Menu Selection \"onclick=\"Select(",Fp+Files[Fp][3][z],");return false\">",Files[Fp+Files[Fp][3][z]][0],"</a></li>")}Mt.push("</ul></div>")}for(x=0,mx=Mix.length;x<mx;x++){Mt.push("<div><ul><a class=\"menutitle\" href=\"#\"title=\" Step through this section \" onclick=\"Preview(",ref,",",x,");return false\">",Mix[x][0],"</a>");for(y=ref,yx=ref+Mix[x][1];y<yx;y++){Mt.push("<li><a id=\"m",y,"\"href=\"#\"title=\"",Pix[y][0],"\"onclick=\"Hg.push([",Fp,",",y,"]);Vista(",y,");return false\">",Pix[y][0],"</a></li>");Pp.push([Pix[y][1]+Pix[y][2][0][0],Pix[y][1]+Pix[y][2][Pix[y][2].length-1][0],Pix[y][1]+Pix[y][3][0]])}ref+=Mix[x][1];Mt.push("</ul></div>")}Get("menubox").innerHTML=Mt.join("");Links();Files[Fp][2]=true;bM.display="block";Ix=0}
function State(){this.blur();window.status="";return true}
function Links(){for(var l=document.links.length-1;l>=0;l--){document.links[l].onmouseover=document.links[l].onmouseout=State};for(var x=0;x<5;x++){document.links[x].onmouseover=function(){Get("tips").innerHTML=this.title;Get("tips").style.display="block";this.blur();window.status="";return true};document.links[x].onclick=State;document.links[x].onmouseout=function(){Get("tips").style.display="none";this.blur();window.status="";return true}}}
function Select(mp){Wrap(Fp);Get("menubox").innerHTML=loader;Get("Vdiv").innerHTML=Get("legend").innerHTML="";Tv=[];done=true;Fp=mp;location.replace("#"+Guest()+".menu."+spin);if(Files[mp][2])Unwrap(mp);else DataScript(Files[mp][1])}
function Wrap(mp){var m,p,h,w;dice=false;Mw[mp]=Get("menubox").innerHTML;Xw[mp]=Ix;Mx[mp]=[];for(m=Mix.length;m>0;m--)Mx[mp].push(Mix.pop());Pw[mp]=[];for(p=Pix.length;p>0;p--)Pw[mp].push(Pix.pop());Hw[mp]=[];for(h=H.length;h>0;h--)Hw[mp].push(H.pop());Ppw[mp]=[];for(w=Pp.length;w>0;w--)Ppw[mp].push(Pp.pop())}
function Unwrap(mp){var m,p,h,w;Get("menubox").innerHTML=Mw[mp];Ix=Xw[mp];for(m=Mx[mp].length;m>0;m--)Mix.push(Mx[mp].pop());for(p=Pw[mp].length;p>0;p--)Pix.push(Pw[mp].pop());for(h=Hw[mp].length;h>0;h--)H.push(Hw[mp].pop());for(w=Ppw[mp].length;w>0;w--)Pp.push(Ppw[mp].pop());Links()}
function Gram(){if(!stop&&!done)Hold();qK.display=nM.display="block";Ml.display=eK.display="none";var email=Make("div");email.id="email";email.innerHTML=Inner();Get("wrap").appendChild(email)}
function Send(){location.href="mailto:"+Get("who").value+mailurl+encodeURIComponent(Get("text").value)+click+domain+Guest()+"."+(Ix-1)+"."+spin+guide;Quit()}
function Quit(){Get("wrap").removeChild(Get("email"));if(location.hash.indexOf("menu")!=-1)Ml.display="block";else if(stop&&!done)Hold();qK.display=nM.display="none";eK.display="block"}
function Cache(){var foot,fetch;if(dice&&R.length>0)fetch=R[R.length-1];else fetch=Ix<Pix.length?Ix:0;if(mini){if(Pp[fetch][2]){pre.src=Pp[fetch][2];Pp[fetch][2]=null}}else if(Pp[fetch][0]){foot=Pix[fetch][4][1]?Pix[fetch][4][1]:hand;pre.src=foot=="right"?Pp[fetch][0]:Pp[fetch][1];Pp[fetch][0]=null}}
function Refit(){var sW=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,base=((window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight)-700)/2,sM=sW/2;Get("wrap").style.bottom=base<2?2+"px":base+"px";Get("linklist").style.height=base<12?657-Math.abs(base*2)+"px":721+"px";Get("menubox").style.height=base<12?536-Math.abs(base*2)+"px":598+"px";Vf.width=sW>1800?1800+"px":sW+"px";Vf.left=sW>1800?sM-900+"px":0+"px";Sw=sW>1800?1800:sW;Sm=Sw/2;if(Sw>Iw)Vx.left=(Sw-Vw)/2+"px"}
function DataScript(file){if(Get("data"))document.body.removeChild(Get("data"));var script=Make("script");script.id="data";document.body.appendChild(script);script.src=file}
function Get(id){return document.getElementById(id)}
function Make(tag){return document.createElement(tag)}
window.onload=Start;window.onresize=Refit;
