// Unsolved (minor) issue: when leaving and returning to a link rotation may change direction

// Used to get brow version
var browVers = true;
bAgent = window.navigator.userAgent;
bAppName = window.navigator.appName;

if ((bAppName.indexOf("Netscape") >= 0) && (bAgent.indexOf("Mozilla/2") >= 0)) browVers = false;
if ((bAppName.indexOf("Netscape") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0)) browVers = false;
if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/2") >= 0)) browVers = false;
if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0)) browVers = false;

var position = 1;
var direction = 1;
var GoTo = 0;
// lastGoTo is used to stop rotation on mouseout AND to make sure that 'old loops' don't keep running!
// (Mouse is moved fast to another link => START-function would set an allowGoTo to true before the
// setTimeout-delay in CallROTATE tries to continue the 'old loop' => 2 loops running simultaneously)
var lastGoTo=0;

// preload images
kompas = new Array();

if(browVers) {
	for (y=0;y<=18;y++)
	{
		kompas[y] = new Image()
		kompas[y].src = "kompas/kompas"+y+".gif"
	}
}

function KLIK(clicked) {
lastGoTo = 0
document.images[2+clicked].blur()
document.images[4+clicked].blur()
}

function STOP() {
lastGoTo = 0
}

function START(GoTo) {
if (lastGoTo==0) { lastGoTo=GoTo; }
// Chooses the direction with the longest distance (short rotations look akward)
distance=GoTo-position
if (distance<1) { distance=18+distance; }
if (distance>8) { direction=1; }
if (distance<=8) { direction=-1; }
// Messy workaround to allow rotation even when at right position (no rotation would confuse user)
if (GoTo==position) { GoTo+=0.1; }
CallROTATE=ROTATE(GoTo,direction)
}

function ROTATE(GoTo,direction) {
//window.status="direction="+direction+" & GoTo="+GoTo+" & last="+lastGoTo+" & distance="+distance;
if(browVers) {
if (lastGoTo==Math.floor(GoTo)) {
if (position!=GoTo) {
GoTo=Math.floor(GoTo)
position = position+direction;
// Makes 'position' switch from 1 to 18 or 18 to 1 (makes animation loop)
if (position < 1 || position > 18) {
position = position + (18 * ( direction * -1 ) )
} 
document.KOMPAS.src=kompas[position].src;
CallROTATE=window.setTimeout("ROTATE("+GoTo+","+direction+")",80)
}
}
}
}
// -->
