/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
	Written by Bugimus 
	Copyright © 1998-2001 Bugimus, all rights reserved.
	You may use this code for your own *personal* use provided you leave this comment block intact.  
	A link back to Bugimus' page would be much appreciated.  
	http://bugimus.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

var g_doImageswaps = true
var g_initv =     0.5;   // 0.5
var g_inith =     2.0;   // 2.0
var g_angleinc =    6;   // 6
var g_speed =      50;
var g_inc =      0.05;
var g_topv =      1.6;
var g_lowv =    -g_topv;
var g_toph =        2;
var g_lowh =    -g_toph;
var g_radius =    100;   // 100
var g_currenth = g_toph;
var g_currentv = g_topv;
var g_goh = 0
var g_gov = 0
var g_behindlogo = false;

// speed isn't working, i keep getting gaps in the ring from speed changes
var g_speedlo =  5;
var g_speedhi = 25;
var g_anglespeed = g_speedlo;

orb1Size = new series( "orb1Size", 75, "orb1Div" );
orb2Size = new series( "orb2Size", 75, "orb2Div" );
orb3Size = new series( "orb3Size", 75, "orb3Div" );
orb4Size = new series( "orb4Size", 75, "orb4Div" );
orb5Size = new series( "orb5Size", 75, "orb5Div" );

function loadImages() {
	if( document.images ) { 
		orb1Size.loadimage( "gfx/orbs33.gif" );
		orb1Size.loadimage( "gfx/orbs30.gif" );
		orb1Size.loadimage( "gfx/orbs27.gif" );
		orb1Size.loadimage( "gfx/orbs24.gif" );
		orb1Size.loadimage( "gfx/orbs21.gif" );
		orb1Size.loadimage( "gfx/orbs18.gif" );

		orb2Size.loadimage( "gfx/orbs33.gif" );
		orb2Size.loadimage( "gfx/orbs30.gif" );
		orb2Size.loadimage( "gfx/orbs27.gif" );
		orb2Size.loadimage( "gfx/orbs24.gif" );
		orb2Size.loadimage( "gfx/orbs21.gif" );
		orb2Size.loadimage( "gfx/orbs18.gif" );

		orb3Size.loadimage( "gfx/orbs33.gif" );
		orb3Size.loadimage( "gfx/orbs30.gif" );
		orb3Size.loadimage( "gfx/orbs27.gif" );
		orb3Size.loadimage( "gfx/orbs24.gif" );
		orb3Size.loadimage( "gfx/orbs21.gif" );
		orb3Size.loadimage( "gfx/orbs18.gif" );

		orb4Size.loadimage( "gfx/orbs33.gif" );
		orb4Size.loadimage( "gfx/orbs30.gif" );
		orb4Size.loadimage( "gfx/orbs27.gif" );
		orb4Size.loadimage( "gfx/orbs24.gif" );
		orb4Size.loadimage( "gfx/orbs21.gif" );
		orb4Size.loadimage( "gfx/orbs18.gif" );

		orb5Size.loadimage( "gfx/orbs33.gif" );
		orb5Size.loadimage( "gfx/orbs30.gif" );
		orb5Size.loadimage( "gfx/orbs27.gif" );
		orb5Size.loadimage( "gfx/orbs24.gif" );
		orb5Size.loadimage( "gfx/orbs21.gif" );
		orb5Size.loadimage( "gfx/orbs18.gif" );
	}
}

function initWeaver() {
	loadImages()

	orb1 = new circleObject( "orb1Div", "orb1Div", 430,171, g_radius, g_angleinc,   0, 1, g_speed, g_inith, g_initv )  // horizontal=2.0, vertical=0.5
	orb2 = new circleObject( "orb2Div", "orb2Div", 290,121, g_radius, g_angleinc,  72, 1, g_speed, g_inith, g_initv )  // horizontal=2.0, vertical=0.5
	orb3 = new circleObject( "orb3Div", "orb3Div", 67,145, g_radius, g_angleinc, 144, 1, g_speed, g_inith, g_initv )  // horizontal=2.0, vertical=0.5
	orb4 = new circleObject( "orb4Div", "orb4Div", 70,203, g_radius, g_angleinc, 216, 1, g_speed, g_inith, g_initv )  // horizontal=2.0, vertical=0.5
	orb5 = new circleObject( "orb5Div", "orb5Div", 300,220, g_radius, g_angleinc, 288, 1, g_speed, g_inith, g_initv )  // horizontal=2.0, vertical=0.5
/*	orb2f = new circle( "orb2fDiv", radius, angleinc,  72, 1, speed, inith, initv )
	orb3f = new circle( "orb3fDiv", radius, angleinc, 144, 1, speed, inith, initv )
	orb4f = new circle( "orb4fDiv", radius, angleinc, 216, 1, speed, inith, initv )
	orb5f = new circle( "orb5fDiv", radius, angleinc, 288, 1, speed, inith, initv )
*/
	orb1.show();
	orb2.show();
	orb3.show();
	orb4.show();
	orb5.show();

	moveObjects()
	setTimeout("autoflipIt()", 5000);
}

function circleObject(objectName,divString,x,y,radius,angleinc,anglestart,direction,speed,horizontal,vertical) {
	this.radius = radius
	this.angleinc = angleinc
	this.anglestart = anglestart
	this.angle = anglestart
	this.direction = direction
	this.speed = speed
	this.vertical = vertical
	this.horizontal = horizontal
	this.active = 0
	this.upVertical = true
	this.inFront = true
	this.swapped = false
	this.circle = circleMove
	this.incx = incX;
	this.decx = decX;
	this.incy = incY;
	this.decy = decY;

//       movingObject(objectName,divString,xinit,yinit,speed,dragOn,divLink,dragimgObjectname,dragimgPlacement) {
//	this.mo = new movingObject(eval(objectName+".mo"),"orb1Div",0,0,60,false)

	this.IE5=this.NN4=this.NN6=false
	if(document.all)this.IE5=true
	else if(document.layers)this.NN4=true
	else if(document.getElementById)this.NN6=true
	
	var netscapestring=""
	var tmp
	var bgn, end
	var i
	var divstring=divString

	i=0
	bgn=0
	end=0
	do { 
		i++
		tmp = ""
		netscapestring += "document."
		end = divstring.indexOf(",")
		if( end > -1 ){
			tmp = divstring.substring(bgn,end)
			divstring = divstring.substring(end+1,divstring.length)
		} else {
			end = divstring.length
			tmp = divstring.substring(bgn,end)
			divstring = null
		}
		netscapestring += tmp
		if(divstring)netscapestring += "."
	} while( divstring )

	if(this.NN4)this.obj=eval(netscapestring)
	if(this.IE5)this.obj=eval("document.all."+tmp+".style")
	if(this.NN6)this.obj=eval("document.getElementById(\""+tmp+"\")"+".style")

	this.show = showDiv
	this.hide = hideDiv
	this.clip = clipDiv
	this.setzindex = setZindex
	this.getzindex = getZindex
	this.getx = getX
	this.gety = getY
	this.setx = setX
	this.sety = setY
	this.getwidth = getWidth
	this.getheight = getHeight
	this.warp = warpTo

	this.centerX = x - this.horizontal*this.radius*Math.cos(this.angle*Math.PI/180)
	this.centerY = y + this.vertical*this.radius*Math.sin(this.angle*Math.PI/180)
}

function incX() {
	if( this.horizontal<g_toph ) this.horizontal+=g_inc;
}

function decX() {
	if( this.horizontal>g_lowh ) this.horizontal-=g_inc;
}

function incY() {
	if( this.vertical<g_topv ) this.vertical+=g_inc;
}

function decY() {
	if( this.vertical>g_lowv ) this.vertical-=g_inc;
}
function circleMove() { 
	this.angle += this.direction*this.angleinc
	if(this.angle>359)this.angle=0;
	this.setx( this.centerX + this.horizontal*this.radius*Math.cos(this.angle*Math.PI/180) )
	this.sety( this.centerY - this.vertical*this.radius*Math.sin(this.angle*Math.PI/180) )
}

function orbitObjects() {
	var ta
	with(orb1) { 
		if(angle<180&&inFront){setzindex(41);inFront=false;}else if(angle>180&&!inFront){setzindex(61);inFront=true;}
		if((ta=getAngleindex(angle))>=0 && g_doImageswaps) orb1Size.showimage('ORB1',ta)
	}
	with(orb2){
		if(angle<180&&inFront){setzindex(42);inFront=false;}else if(angle>180&&!inFront){setzindex(62);inFront=true;}
		if((ta=getAngleindex(angle+g_angleinc))>=0 && g_doImageswaps) orb2Size.showimage('ORB2',ta)
	}
	with(orb3){
		if(angle<180&&inFront){setzindex(43);inFront=false;}else if(angle>180&&!inFront){setzindex(63);inFront=true;}
		if((ta=getAngleindex(angle+g_angleinc*2))>=0 && g_doImageswaps) orb3Size.showimage('ORB3',ta)
	}
	with(orb4){
		if(angle<180&&inFront){setzindex(44);inFront=false;}else if(angle>180&&!inFront){setzindex(64);inFront=true;}
		if((ta=getAngleindex(angle+g_angleinc*3))>=0 && g_doImageswaps) orb4Size.showimage('ORB4',ta)
	}
	with(orb5){
		if(angle<180&&inFront){setzindex(45);inFront=false;}else if(angle>180&&!inFront){setzindex(65);inFront=true;}
		if((ta=getAngleindex(angle+g_angleinc*4))>=0 && g_doImageswaps) orb5Size.showimage('ORB5',ta)
	}

	orb5.circle();
	orb4.circle();
	orb3.circle();
	orb2.circle();
	orb1.circle()

/*	orb5f.angleinc=anglespeed; 
	orb4f.angleinc=anglespeed; 
	orb3f.angleinc=anglespeed; 
	orb2f.angleinc=anglespeed; 
	orb1.angleinc=anglespeed; 
*/
}
function getAngleindex(angle) {
	var i=0
	if( angle==36 )      i=4
	else if( angle==72 ) i=5
	else if( angle==108 )i=4
	else if( angle==144 )i=3
	else if( angle==180 )i=2
	else if( angle==216 )i=1
	else if( angle==252 )i=0
	else if( angle==288 )i=1
	else if( angle==324 )i=2
	else if( angle==360 )i=3
	else i=-1
	return i
}
function moveObjects() {

	orbitObjects();

	if( !g_helpOn ) {
		g_currenth=-(2*g_toph*((o[1].getx()-90)/110)-g_toph)
		g_currentv=-(2*g_topv*((o[2].getx()-290)/110)-g_topv)
	}

	// Adjust to new axis values according to inc value.
	if( orb1.horizontal<g_currenth ) { orb1.incx();orb2.incx();orb3.incx();orb4.incx();orb5.incx(); }
	if( orb1.horizontal>g_currenth ) { orb1.decx();orb2.decx();orb3.decx();orb4.decx();orb5.decx(); }
	if( orb1.vertical<g_currentv ) { orb1.incy();orb2.incy();orb3.incy();orb4.incy();orb5.incy(); }
	if( orb1.vertical>g_currentv ) { orb1.decy();orb2.decy();orb3.decy();orb4.decy();orb5.decy(); }

	// What elevation orbs should have when over the logo in middle.  Toggle behindlogo global.
	if( g_behindlogo ) {
		oBack.setzindex(100)   // send orbs in front of logo
		oBack.show()
	} else if( Math.abs(Math.max(Math.abs(orb1.horizontal),Math.abs(orb1.vertical))) < 1.0 ) { 
//		oBack.setzindex(0)     // send orbs in front of logo
		oBack.hide()     // send orbs in front of logo
	} else { 
		oBack.setzindex(50)    // send orbs behind logo
		oBack.show()
	}
//	setTimeout("moveObjects()", 1000 );
	setTimeout("moveObjects()", orb1.speed )
}

function autoflipIt() {
	flipIt()
	setTimeout("autoflipIt()", 15000 )
}

function flipIt() {
	o[1].setx( 200-(o[1].getx()-90)  )
	o[2].setx( 400-(o[2].getx()-290)  )
}

