// copyright 2005 Huub Schaeks
// use as you wish
// please give credit where it's due.

var initialized=false;
var doMove=true;
var xStart=10;
var yStart=10;
var xDelta=0;
var yDelta=0;
var xEnd=0;
var yEnd=0;
var moving=false;
var step=0;
var mainFrame;
var image;
var timer;
var BW=1200;
var halfBW=600;
var BH=1200;
var halfBH=600;
var CW=200;
var CH=300;
var aDelta=0;
var iWidth=0;
var tStart=0;
var turning=false;

function holdBack()
{
	clearInterval(timer);
	if (step < 50)
	{
		xStart=xStart+step*xDelta;
		yStart=yStart+step*yDelta;
	}
}

function action()
{
  if (doMove)
  	step++;
  else
  {
    step=51;
    mainFrame.style.backgroundPosition=xEnd+'px '+yEnd+'px';
 	  image.style.width=iWidth+'px';
 	}
	if (step > 50)
	{
		clearInterval(timer);
    xStart=xEnd;
    yStart=yEnd;
    turning=false;
  }
	else
	{
    xNew=xStart+step*xDelta;
    yNew=yStart+step*yDelta;
    mainFrame.style.backgroundPosition=xNew+'px '+yNew+'px';
    if (turning)
	   	image.style.width=iWidth*Math.sin((step-tStart)*aDelta)+'px';
  }
}

function move(frame, x, y, menuID, Width)
{
  if (initialized)
  	menu_bar.SetMenu(menuID);
	clearInterval(timer);
	mainFrame=frame.document.getElementById('main');
	mainFrame.style.backgroundPosition=xStart+'px '+yStart+'px';
	if (x!=0)
	{
		image=frame.document.getElementById('slide');
		iWidth=Width;
		xEnd=(1-x)*CW + 10;
		yEnd=(1-y)*CH + 10;
		if (xEnd > xStart)
			if ((xEnd - xStart) > halfBW)
				xNew = xEnd - BW;
			else
				xNew=xEnd;
		else
			if ((xStart - xEnd) > halfBW)
				xNew = xEnd + BW;
			else
				xNew=xEnd;
		xDelta = (xNew - xStart) / 50;
		if (yEnd > yStart)
			if ((yEnd - yStart) > halfBH)
				yNew = yEnd - BH;
			else
				yNew=yEnd;
		else
			if ((yStart - yEnd) > halfBH)
				yNew = yEnd + BH;
			else
				yNew=yEnd;
		yDelta = (yNew - yStart) / 50;
  	step=0;
		timer=setInterval('action()', 60);
	}
}

function turn()
{
  if (step<50)
  {
    tStart=step;
    aDelta=Math.PI/(50-tStart)/2;
    turning=true;
  }
  else
  {
    xDelta=0;
    yDelta=0;
    step=0;
    tStart=0;
    aDelta=Math.PI/100;
    turning=true;
    timer=setInterval('action', 40);
  }
}

function toggleMove()
{
  doMove=!doMove;
  if (doMove)
    menu_bar.document.getElementById('switch').src="pics/on.gif"
  else
    menu_bar.document.getElementById('switch').src="pics/off.gif"
}
