/****************************************
Original script by Thomas Brattli released at DHTMLCentral.com
Script updated with many enhancments for use with this site by the site author austin_collins@yahoo.com
Copyright (C) 2002 
*****************************************/

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bws=new lib_bwcheck()


/***************************************************************************
Object constructors; making Cross-browser object of the buttons
****************************************************************************/
//Debug function ******************
function lib_message(txt){alert(txt); return false} 

//Lib objects  ********************
function lib_obj(obj,nest,o){ 
	if(!bws.bw) return lib_message('Old browser')
	nest=(!nest) ? "":'document.'+nest+'.'										
   	if(o&&bws.ns4){ this.evnt=o;
		}else{
		 this.evnt=bws.dom? document.getElementById(obj):bws.ie4?document.all[obj]:bws.ns4?eval(nest+"document.layers." +obj):0;	
	}
	if(!this.evnt) return lib_message('The layer does not exist ('+obj+') - \nIf your using Netscape please check the nesting of your tags!')
	this.css=(bws.dom||bws.ie4)?this.evnt.style:this.evnt; 
	this.ref=(bws.dom||bws.ie4)?document:this.css.document;
	this.x=this.css.left||this.css.pixelLeft||this.evnt.offsetLeft||0; 
	this.y=this.css.top||this.css.pixelTop||this.evnt.offsetTop||0
	this.w=this.evnt.offsetWidth||this.css.clip.width||this.ref.width||this.css.pixelWidth||0; 
	this.h=this.evnt.offsetHeight||this.css.clip.height||this.ref.height||this.css.pixelHeight||0
	this.vis=this.css.visibility
	/*this.c=0 //Clip values
	if((bws.dom || bws.ie4) && this.css.clip) {
		this.c=this.css.clip; 
		this.c=this.c.slice(5,this.c.length-1); 
		this.c=this.c.split(' '); 
		for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
	}
	this.ct=this.css.clip.top||this.c[0]||0; 
	this.cr=this.css.clip.right||this.c[1]||this.w||0
	this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
	this.cl=this.css.clip.left||this.c[3]||0*/
	this.obj = obj + "Object"; 	
	eval(this.obj + "=this")
	return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bws.ns4||window.opera?"":"px";

//Moving object to **************
lib_obj.prototype.moveIt = function(x,y){this.x=x; this.y=y; this.css.left=x+px; this.css.top=y+px;} 

//Showing object ************
lib_obj.prototype.showIt = function(){this.css.visibility=(bws.ns4)?"show":"visible"} 
lib_obj.prototype.hideIt = function(){this.css.visibility=(bws.ns4)?"hide":"hidden"} 

//Document size object ********
function lib_doc_size(){ 
	this.x=0;this.x2=bws.ie && document.body.offsetWidth-20||innerWidth||0;
	this.y=0;this.y2=bws.ie && document.body.offsetHeight-5||innerHeight||0;
	if(!this.x2||!this.y2) return message('Document has no width or height') 
	this.x50=this.x2/2;this.y50=this.y2/2;
	return this;
}

/***************************************************************************
Main variables
****************************************************************************/
//The radius for the circle
var radius=400
//Start angle
var startAngle=90
//Speed in milliseconds
var circleSpeed=40
//angle to move per timeout
var moveAngle=3

var currentAngle=startAngle


/***************************************************************************
Initiating the buttons and starts the circlemove
****************************************************************************/
var xcenter,ycenter,menuState,circleGoing;
function circleMenuInit(num){
	page = new lib_doc_size()
	//Making a simple object for the divCont
	//Making an array to hold the button objects
	oBut = new Array()
	//Making button objects, arguments: divName,nested div,anglestop
	for(var i=0; i<5; i++){
		oBut[i] = new lib_obj('div'+i)
	}
	radius=page.x50/10*8
	//Setting stop angles for each button and direction
	oBut[0].stop = 90
	oBut[0].cw = true
	oBut[1].stop = 70
	oBut[1].cw = true
	oBut[2].stop = 50
	oBut[2].cw = true
	oBut[3].stop = 70
	oBut[3].cw = false
	oBut[4].stop = 50
	oBut[4].cw = false
//	oBut[5].stop = -210
//	oBut[5].cw = false
	//Moves the button; ie5 bugfix
	oBut[0].moveIt(page.x50/6*4-20,200)
	//Starts the circlemove
	xcenter = oBut[0].x - radius*Math.cos(startAngle*Math.PI/180)
	ycenter = oBut[0].y + radius*Math.sin(startAngle*Math.PI/180)
//	oCont.showIt() //Showing cont layer
for(var i=0; i<5; i++){
		oBut[i].showIt()
	}

	circleGo(radius,-moveAngle,currentAngle,xcenter,ycenter,'menuState=1;showlinks()')

}
/***************************************************************************
Moves the buttons in a circle
****************************************************************************/
function circleGo(radius,angleinc,angle,xcenter,ycenter,fn) {
var andagain=false, stopangle
	//if angleinc < endangle-angle (no matter if it's positive or negative numbers)
//	if ((Math.abs(angleinc)<Math.abs(endangle-angle))) {
		circleGoing=true
		angle += angleinc
		var cwx = xcenter + radius*Math.cos(angle*Math.PI/180)
		var ccwx = xcenter - radius*Math.cos(angle*Math.PI/180)
		var y = ycenter - radius*Math.sin(angle*Math.PI/180)
		for(var i=1; i<oBut.length; i++){
		//creates oposite angle for ccw	motion
			stopangle=oBut[i].stop //+ ((oBut[i].cw)?0:(oBut[i].stop>0)?-180:180)
			//if angle are bigger then the stop angle of each button
			if (angle>=stopangle && angle<=startAngle){
			 oBut[i].moveIt((oBut[i].cw)?cwx:ccwx,y)
			 currentAngle=angle
			 andagain=true
			 }
		}
		if(andagain){
			setTimeout("circleGo("+radius+","+angleinc+","+angle+","+xcenter+","+ycenter+",'"+fn+"')",circleSpeed)
	}else{
	 	circleGoing = false
		eval(fn)
	}
}
/***************************************************************************
When click on the buttons
****************************************************************************/
var zIndex = 5
function mclick(num,lnk){
for(var i=0; i<oLab.length; i++){
	oLab[i].hideIt()
}
	//If it's not moving already
	if (!circleGoing){
		//Added feature; the clicked buttons stays on top!
		zIndex ++
		oBut[num].css.zIndex = zIndex
		//Checks the state of the menu and circles it the right way
		var m = (oBut[0].y-80)/5
		m=page.x2/5/m
		if (menuState) circleGo(radius,moveAngle,currentAngle,xcenter,ycenter,'movetoheader("'+ lnk +'",'+ m +')')
		//else moveFromCenter(lnk)
	}
}	

function movetoheader(lnk,m){
	/*if (oBut[0].y>80){
		for (var i=0; i<oBut.length; i++){
			oBut[i].moveIt(oBut[i].x+(i*m-m*2),oBut[i].y-5)
		}
		setTimeout("movetoheader('"+ lnk +"',"+ m +")",circleSpeed/2)
	}else{	
		menuState = 0
		for(var i=0; i<oBut.length; i++){
			oBut[i].hideIt()
		}*/
		if(lnk && String(lnk)!="undefined") location.href = lnk
//	}
}

//Moving the buttons to the center
function moveCenter(lnk){

	if (oBut[0].y<95){
		for (var i=0; i<oBut.length; i++){
			oBut[i].moveIt(oBut[i].x+(i-2.5),oBut[i].y+3)
		}
		setTimeout("moveCenter('"+ lnk +"')",30)
	}else{	
		menuState = 0
		//if(lnk && String(lnk)!="undefined") location.href = lnk
	}
}
//Moving the buttons from center
function moveFromCenter(lnk){
	if (oBut[0].y>6){
		for (var i=0; i<oBut.length; i++){
			oBut[i].moveIt(oBut[i].x-(i-2.5),oBut[i].y-3)
		}
		setTimeout("moveFromCenter('"+ lnk +"')",30)
	}else{	
		circleGo(radius,-moveAngle,currentAngle,xcenter,ycenter,'menuState=1')
	}
}
function showlinks(){
oLab = new Array()
for(var i=0; i<5; i++){
		oLab[i] = new lib_obj('lab'+i)
		oLab[i].showIt()
	}
oLab[0].moveIt(oBut[0].x-25,oBut[0].y-25)
oLab[1].moveIt(oBut[1].x+40,oBut[1].y)
oLab[2].moveIt(oBut[2].x+40,oBut[2].y)
oLab[3].moveIt(oBut[3].x-110,oBut[3].y)
oLab[4].moveIt(oBut[4].x-55,oBut[4].y)
}
/***************************************************************************
Mouseover and out on the buttons
****************************************************************************/
function mover(num){
return
	oBut[num].ref["img"+num].src = 'circlemenu1_1.gif'
}
function mout(num){
return
	oBut[num].ref["img"+num].src = 'circlemenu'+(num+1)+'.gif'
}
//Starting the menu on pageload.
onload = circleMenuInit;
