// JavaScript Document
/***************************************************************************************
Copyright (C) 2001 ab_ditto
This script is made by and copyrighted to ab_ditto at back.to/ab or ab_ditto@hotmail.com
This may be used freely as long as this msg is intact! 
              **************************************************************
This script has been partly rewritten by hb to accommodate Netscape 4 event handling
***************************************************************************************/
//add onload="init()" to body tag
//parameters to set
positionx=300; //startposition of the cube, x-value
positiony=150; //startposition of the cube, y-value
clength=100; //length of a cubeside
dotsize=50; //size of the dots, also of image displayed
useimage=1; //if you want to use an image as dot, set this from null to 1;
dotgif="images/stork.gif"; //path to the image used as dot
dotcolor="cccc00"; //color of the dots if there is no image
//thatīs it, nothing more to do, have fun :)

clengthh=clength/2;
imgstr=0; thediff=0;
posa=positionx+clengthh;posb=positionx-clengthh;posc=positiony+clengthh;posd=positiony-clengthh;
if (useimage){imgstr="<IMG src='"+dotgif+"' width="+dotsize+"px height="+dotsize+"px>";}
else{thediff="background-color:#"+dotcolor+"; layer-background-color:#"+dotcolor+";"; imgstr=""}

document.write(" <style type='text/css'>");
document.write(" .cube { position:absolute; z-index:7; width:"+dotsize+"px; height:"+dotsize+"px; clip:rect(0,"+dotsize+"px,"+dotsize+"px,0); }");
document.write(" #p1 { top:"+posc+"px; left:"+posa+"px; "+thediff+"}");
document.write(" #p2 { top:"+posc+"px; left:"+posa+"px; "+thediff+"}");
document.write(" #p3 { top:"+posc+"px; left:"+posb+"px; "+thediff+"}");
document.write(" #p4 { top:"+posc+"px; left:"+posb+"px; "+thediff+"}");
document.write(" #p5 { top:"+posd+"px; left:"+posa+"px; "+thediff+"}");
document.write(" #p6 { top:"+posd+"px; left:"+posa+"px; "+thediff+"}");
document.write(" #p7 { top:"+posd+"px; left:"+posb+"px; "+thediff+"}");
document.write(" #p8 { top:"+posd+"px; left:"+posb+"px; "+thediff+"}");
document.write("</style>");

document.write("<div id='p1' class='cube'>"+imgstr+"</div>");
document.write("<div id='p2' class='cube'>"+imgstr+"</div>");
document.write("<div id='p3' class='cube'>"+imgstr+"</div>");
document.write("<div id='p4' class='cube'>"+imgstr+"</div>");
document.write("<div id='p5' class='cube'>"+imgstr+"</div>");
document.write("<div id='p6' class='cube'>"+imgstr+"</div>");
document.write("<div id='p7' class='cube'>"+imgstr+"</div>");
document.write("<div id='p8' class='cube'>"+imgstr+"</div>");

Xmd= Ymd= 100;
var isNN = document.layers ? true : false;  
var isIE = document.all ? true : false;

function initCube() {
  follow=0;
  if (isIE){
    dot1=document.getElementById("p1").style;
    dot2=document.getElementById("p2").style;
    dot3=document.getElementById("p3").style;
    dot4=document.getElementById("p4").style;
    dot5=document.getElementById("p5").style;
    dot6=document.getElementById("p6").style;
    dot7=document.getElementById("p7").style;
    dot8=document.getElementById("p8").style;
    }
  if (isNN){
    dot1=document.layers.p1;
    dot2=document.layers.p2;
    dot3=document.layers.p3;
    dot4=document.layers.p4;
    dot5=document.layers.p5;
	dot6=document.layers.p6;
	dot7=document.layers.p7;
	dot8=document.layers.p8;
	}
  if (isNN){document.captureEvents(Event.MOUSEMOVE ||Event.MOUSEDOWN || Event.MOUSEUP) }
  document.onmousedown = startDrag;
  document.onmouseup = stopDrag;
  document.onmousemove = rotateIt;
}

function startDrag(e) {
  Xmdx = isNN ? e.pageX : window.event.clientX;
  Ymdy = isNN ? e.pageY : window.event.clientY;
  follow=1;
}

function stopDrag() {
  follow=null;
  positionx=positionx+mox;
  positiony=positiony+moy;
}

function rotateIt(e){
  Xmdr = isNN ? e.pageX : window.event.clientX;
  Ymdr = isNN ? e.pageY : window.event.clientY;
with (Math){
pidiv = PI/180;
diagf=clength/2*SQRT2;
dh1=-(Xmdr-Xmd)*pidiv;  dv1=-(Ymdr-Ymd)*pidiv;
mox=0;  moy=0;
if (follow){mox=Xmdr-Xmdx;  moy=Ymdr-Ymdy;}
mfx=positionx;  mfy=positiony;
pfh1=diagf*sin((045*pidiv+dh1));pfv1=diagf*cos((045*pidiv+dh1))*sin(dv1)+clengthh*sin((90*pidiv+dv1));
pfh2=diagf*sin((135*pidiv+dh1));pfv2=diagf*cos((135*pidiv+dh1))*sin(dv1)+clengthh*sin((90*pidiv+dv1));
pfh3=diagf*sin((225*pidiv+dh1));pfv3=diagf*cos((225*pidiv+dh1))*sin(dv1)+clengthh*sin((90*pidiv+dv1));
pfh4=diagf*sin((315*pidiv+dh1));pfv4=diagf*cos((315*pidiv+dh1))*sin(dv1)+clengthh*sin((90*pidiv+dv1));
pfh5=diagf*sin((045*pidiv+dh1));pfv5=diagf*cos((045*pidiv+dh1))*sin(dv1)+clengthh*sin((-90*pidiv+dv1));
pfh6=diagf*sin((135*pidiv+dh1));pfv6=diagf*cos((135*pidiv+dh1))*sin(dv1)+clengthh*sin((-90*pidiv+dv1));
pfh7=diagf*sin((225*pidiv+dh1));pfv7=diagf*cos((225*pidiv+dh1))*sin(dv1)+clengthh*sin((-90*pidiv+dv1));
pfh8=diagf*sin((315*pidiv+dh1));pfv8=diagf*cos((315*pidiv+dh1))*sin(dv1)+clengthh*sin((-90*pidiv+dv1));
}
pfx1=mfx+pfh1; pfy1=mfy+pfv1;
pfx2=mfx+pfh2; pfy2=mfy+pfv2;
pfx3=mfx+pfh3; pfy3=mfy+pfv3;
pfx4=mfx+pfh4; pfy4=mfy+pfv4;
pfx5=mfx+pfh5; pfy5=mfy+pfv5;
pfx6=mfx+pfh6; pfy6=mfy+pfv6;
pfx7=mfx+pfh7; pfy7=mfy+pfv7;
pfx8=mfx+pfh8; pfy8=mfy+pfv8;

dot1.left=pfx1+mox; dot1.top=pfy1+moy;
dot2.left=pfx2+mox; dot2.top=pfy2+moy;
dot3.left=pfx3+mox; dot3.top=pfy3+moy;
dot4.left=pfx4+mox; dot4.top=pfy4+moy;
dot5.left=pfx5+mox; dot5.top=pfy5+moy;
dot6.left=pfx6+mox; dot6.top=pfy6+moy;
dot7.left=pfx7+mox; dot7.top=pfy7+moy;
dot8.left=pfx8+mox; dot8.top=pfy8+moy;
return false;
}
//end of script