// hello!
// (c) David Barton. 2002.
// http://www.limpfish.com/
// works in NS4, IE4/5/6, Opera 5, NS6 / Mozilla 0.9.8
var layerRef="null",layerStyleRef="null",styleSwitch="null";
function init()
{
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	if (isNS4) 
	{
		layerStyleRef="layer.";
		layerRef="document.layers";
		bracketOpen='["';
		bracketClose='"]';
		styleSwitch="";
	}
	else
	{
		layerStyleRef="layer.style.";
		styleSwitch=".style";
		if (isIE4)
		{
			bracketOpen='["';
			bracketClose='"]';
			layerRef="document.all";
		}
		else
		{
			// IE5, 6 and NS6, moz
			bracketOpen='("';
			bracketClose='")';
			layerRef="document.getElementById";
		}
	}
}
function doStyleStuff(layerName,action)  // do any style action for any browser 
{
	eval(layerRef+bracketOpen+layerName+bracketClose+styleSwitch+'.'+action);
}
function showLayer(layerName) 
{
	doStyleStuff(layerName,'visibility="visible"');
}
function hideLayer(layerName) 
{
	doStyleStuff(layerName,'visibility="hidden"');
}
function moveLayerTo(layerName,left,top) 
{
	doStyleStuff(layerName,'top='+top);
	doStyleStuff(layerName,'left='+left);
}
function test(layerName)
{
	
}

var y = 50;
var x = 30;
var newanim=999;
var state;
var splash_down_totalTime=14;
var bob_totalTime=7;
var currTime=0;
var hideit=0;
var slide_bounce=new Array (2,4,6,10,14,19,24,30,36,43,53,67,85,108,135,165,185);
var splash_down_y=new Array (-75,-70,-60,-50,-35,-20,-5,15,  9,7,5, 6,7,9);
var bob_y=new Array (9,7,6,6,6,7,8);
var bob_alt_y=new Array (9,8,7,7,8,9,10);
function s()
{
currTime=0;
state = 1;
newanim=1;
x = 15+(Math.random()*104);
timelineController();
}



function timelineController()
{

	// splash down
	if (state == 0)
	{
			if (currTime <= splash_down_totalTime)
			{
				currTime++;
				if (splash_down_y[currTime] != null)
				{
					moveLayerTo('duck',x,splash_down_y[currTime])
				}
			}
			else
			{
				state = 1;
			}
	}
	// general idle state, animation logic.
	if (state == 1)  
	{
	currTime=0;
	r = Math.random() * 900;
	if (newanim==0) { state = 2; } // bob
	hideLayer('quack');
	if ((r < 100) && (newanim==0)) { state = 3; } // alternate bob 
	if ((r < 40) && (newanim==0) && (hideit == 0)){ showLayer('quack'); } // perform a random quack
	if ((r < 62) && (newanim==1)) { state = 0; x = 15+(Math.random()*104); moveLayerTo('duck',x,-80); showLayer('duck'); newanim=0; } //begin?
	if ((r < 60) && (newanim==0)) { hideLayer('duck'); hideit=1;  state = 1; newanim=1; hideLayer('quack'); } // end anim
	}
	// bob up and down anim
	if ((state == 2) || (state == 3)) 
	{
	if (currTime <= bob_totalTime)
	{
			currTime++;
			if (bob_y[currTime] != null)
			{
				if (state == 2) { moveLayerTo('duck',x,bob_y[currTime]); }
				if (state == 3) { moveLayerTo('duck',x,bob_alt_y[currTime]);}
				moveLayerTo('quack',x+40 ,5);
			}
		}
		else
		{
			state = 1;
		}
	}
	setTimeout("timelineController()",50);
}
function slidedown()
{
	y= 55;
	yy= 0;
	slideindex = 0;
	slideController();
}
function slideController()
{
	yy = (y + slide_bounce[slideindex]);
	doStyleStuff('nwstuff','clip="rect(0 auto '+yy+'px 0)"');
	if (slideindex < 16)
	{
	slideindex++;
	setTimeout("slideController()",20);
	}
	else
	{
			showLayer('nomore');
	}
}