/***************************************************************************************
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! 
***************************************************************************************/
//parameters to set
positionx=50; //startposition of the cube, x-value
positiony=50; //startposition of the cube, y-value
clength=30; //length of a cubeside
dotsize=3; //size of the dots
useimage=null; //if you want to use an image as dot, set this from null to 1;
dotgif="dot.gif"; //path to the image used as dot
dotcolor="999999"; //color of the dots if there is no image
//thatīs it, nothing more to do, have fun :)

clengthh=clength/2;
posa=positionx+clengthh;posb=positionx-clengthh;posc=positiony+clengthh;posd=positiony-clengthh;
if (useimage){thediff=";'><IMG src='"+dotgif+"' width="+dotsize+"px height="+dotsize+"px>";}
else{thediff="; background-color:#"+dotcolor+";'>";}

document.write("<style type='text/css'>");
document.write(".cube { position:absolute; width:"+dotsize+"px; height:"+dotsize+"px; clip:rect(0,"+dotsize+"px,"+dotsize+"px,0); }");
document.write("</style>");

document.write("<div id='p1' class='cube' style='top:"+posc+"px; left:"+posa+"px"+thediff+"</div>");
document.write("<div id='p2' class='cube' style='top:"+posc+"px; left:"+posa+"px"+thediff+"</div>");
document.write("<div id='p3' class='cube' style='top:"+posc+"px; left:"+posb+"px"+thediff+"</div>");
document.write("<div id='p4' class='cube' style='top:"+posc+"px; left:"+posb+"px"+thediff+"</div>");
document.write("<div id='p5' class='cube' style='top:"+posd+"px; left:"+posa+"px"+thediff+"</div>");
document.write("<div id='p6' class='cube' style='top:"+posd+"px; left:"+posa+"px"+thediff+"</div>");
document.write("<div id='p7' class='cube' style='top:"+posd+"px; left:"+posb+"px"+thediff+"</div>");
document.write("<div id='p8' class='cube' style='top:"+posd+"px; left:"+posb+"px"+thediff+"</div>");


function startit(e){
	if(navigator.appName == "Netscape"){event=e;}
	Xmd = event.clientX
	Ymd = event.clientY
	follow=0;
	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;
	}

function pickup(e){
	if(navigator.appName == "Netscape"){event=e;}
	follow=1;Xmdx = event.clientX;Ymdy = event.clientY;}

function rotateit(e){
if(navigator.appName == "Netscape"){event=e;}
with (Math){
	pidiv = PI/180;
	diagf=clength/2*SQRT2;
	dh1=-(event.clientX-Xmd)*pidiv;dv1=-(event.clientY-Ymd)*pidiv;
	mox=0;moy=0;
	if (follow){mox=event.clientX-Xmdx;moy=event.clientY-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;
	}

function setdown() {follow=null;positionx=positionx+mox;positiony=positiony+moy;}

document.onmousedown=pickup;document.onmousemove=rotateit;document.onmouseup=setdown;onload=startit;
