// STEP 5

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns2 = (this.ns && (this.major == 3));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4b = (this.ns && (this.major == 4) && (this.minor <= 4.03));
  this.ns4 = (this.ns && (this.major >= 4));
  this.ns406 = (this.ns && (this.minor == 4.06));
  this.ns407 = (this.ns && (this.minor == 4.07));
  this.ns408 = (this.ns && (this.minor == 4.08));
  this.ns45 = (this.ns && (this.minor == 4.5));
  this.ns46 = (this.ns && (this.minor == 4.6));
  this.ns461 = (this.ns && (this.minor == 4.61));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major == 2));
  this.ie4 = (this.ie && (this.major == 4));
  this.ie5b1 = (agent.indexOf("5.0b1") != -1);
  this.op3 = (agent.indexOf("opera") != -1);
  this.op5 = (this.ie && (this.major == 5));
  this.win   = (agent.indexOf("win")!=-1);
  this.mac   = (agent.indexOf("mac")!=-1);
  this.unix  = (agent.indexOf("x11")!=-1);
}

var is = new Is()

if(is.ns4) {
	doc = "document";
	sty = "";
	htm = ".document"
	xpos = "e.pageX";
	ypos = "e.pageY";
} else if(is.ie4) {
	doc = "document.all";
	sty = ".style";
	htm = ""
	xpos = "event.x";
	ypos = "event.y";
}



// STEP 6

var count = 0;

function preLoad() {

	munseynet = new Image();
    munseynet.src = "images/munseynet.gif";

	ball = new Image();
    ball.src = "images/ball.gif";

	layerSetup();
}



// STEP 7

function layerSetup() {
	munseyLyr = eval(doc + '["munseyLayer"]' + sty);
	munseyLyr.left = -374;
	munseyLyr.top = 0;

	ball1Lyr = eval(doc + '["ball1Layer"]' + sty);
	ball1Lyr.left = 0;
	ball1Lyr.top = 0;

	ball2Lyr = eval(doc + '["ball2Layer"]' + sty);
	ball2Lyr.left = 0;
	ball2Lyr.top = 0;

	visibilitySetup();
}

// STEP 8

function visibilitySetup() {
	munseyLyr.visibility = "visible";
	arraysetup();
}


// STEP 9
function arraysetup() {
	var height = available_height-imageheight;
	var width = available_width;
	side_array = new Array((width*0)-(imagewidth/2),(width*.025)-(imagewidth/2),(width*.05)-(imagewidth/2),(width*.075)-(imagewidth/2),(width*.1)-(imagewidth/2),(width*.125)-(imagewidth/2),(width*.15)-(imagewidth/2),(width*.175)-(imagewidth/2),(width*.2)-(imagewidth/2),(width*.225)-(imagewidth/2),(width*.25)-(imagewidth/2),(width*.275)-(imagewidth/2),(width*.3)-(imagewidth/2),(width*.325)-(imagewidth/2),(width*.35)-(imagewidth/2),(width*.375)-(imagewidth/2),(width*.4)-(imagewidth/2),(width*.425)-(imagewidth/2),(width*.45)-(imagewidth/2),(width*.475)-(imagewidth/2),(width*.5)-(imagewidth/2),(width*.5)-(imagewidth/2))
	x_array1 = new Array((height*0),(height*.02),(height*.04),(height*.06),(height*.08),(height*.1),(height*.12),(height*.14),(height*.16),(height*.18),(height*.2),(height*.22),(height*.24),(height*.26),(height*.28),(height*.3),(height*.32),(height*.34),(height*.36),(height*.38),(height*.4),(height*.42),(height*.44),(height*.46),(height*.48),(height*.5),(height*.52),(height*.54),(height*.56),(height*.58),(height*.6),(height*.62),(height*.64),(height*.66),(height*.68),(height*.7),(height*.72),(height*.74),(height*.76),(height*.78),(height*.8),(height*.82),(height*.84),(height*.86),(height*.88),(height*.9),(height*.92),(height*.94),(height*.96),(height*.98),(height),(height));
	x_array2 = new Array((height),(height*.98),(height*.96),(height*.94),(height*.92),(height*.9),(height*.88),(height*.86),(height*.84),(height*.82),(height*.8),(height*.78),(height*.76),(height*.74),(height*.72),(height*.7),(height*.68),(height*.66),(height*.64),(height*.62),(height*.6),(height*.58),(height*.56),(height*.54),(height*.52),(height*.5),(height*.48),(height*.46),(height*.44),(height*.42),(height*.4),(height*.38),(height*.36),(height*.34),(height*.32),(height*.3),(height*.28),(height*.26),(height*.24),(height*.22),(height*.2),(height*.18),(height*.16),(height*.14),(height*.12),(height*.1),(height*.08),(height*.06),(height*.04),(height*.02),(height*0),(height*0));
	setTimeout("gomunsey()",500);
}
	
	

// STEP 10
var coordflag = 0;
var imagewidth = 374;
var imageheight = 76;
var move_index = 0;
var ballimage=79;
var hpos1=ballimage/2;
var vpos1=ballimage/2;
var hpos2=ballimage/2;
var vpos2=ballimage/2;
var hdirection1=0;
var vdirection1=0;
var hdirection2=1;
var vdirection2=1;



function gomunsey() {
	if(move_index < side_array.length-1) {
		munseyLyr.left = (side_array[move_index]);
		move_index++;
		setTimeout("gomunsey()",40);
	} else {
		move_index = 0;
		setTimeout("gomunsey1()",500);
		ball1Lyr.visibility = "visible";
		ball2Lyr.visibility = "visible";		
		bounce();
	}
}


function gomunsey1() {
	if(move_index < x_array1.length-1) {
		munseyLyr.top = (x_array1[move_index]);
		move_index++;
		setTimeout("gomunsey1()",120);
	} else {
		move_index = 0;
		gomunsey2();
	}
}

function gomunsey2() {
	if(move_index < x_array2.length-1) {
		munseyLyr.top = (x_array2[move_index]);
		move_index++;
		setTimeout("gomunsey2()",10);
	} else {
		move_index = 0;
		setTimeout("gomunsey1()",500);
	}
}

function bounce() {
	if (coordflag == 0) {
		hpos2 = available_width-ballimage/2;
		vpos2 = available_height-ballimage/2;
	}

	ball1Lyr.left=hpos1;
	ball1Lyr.top=vpos1;

	ball2Lyr.left=hpos2;
	ball2Lyr.top=vpos2;

	if(vdirection1 == 0) {
		vpos1 = vpos1+10;
	}

	if(vdirection1 == 1) {
		vpos1 = vpos1-10;
	}

	if(vpos1 > (available_height - ballimage) & vdirection1 == 0) {
		vdirection1=1;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');
	}

	if(vpos1 < 0 & vdirection1 == 1) {
		vdirection1=0;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');		
	}

	if(hdirection1 == 0) {
		hpos1 = hpos1+10;
	}

	if(hdirection1 == 1) {
		hpos1 = hpos1-10;
	}

	if(hpos1 > (available_width - ballimage) & hdirection1 == 0) {
		hdirection1=1;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');
	}

	if(hpos1 < 0 & hdirection1 == 1) {
		hdirection1=0;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');		
	}





	if(vdirection2 == 0) {
		vpos2 = vpos2+10;
	}

	if(vdirection2 == 1) {
		vpos2 = vpos2-10;
	}

	if(vpos2 > (available_height - ballimage) & vdirection2 == 0) {
		vdirection2=1;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');
	}

	if(vpos2 < 0 & vdirection2 == 1) {
		vdirection2=0;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');		
	}

	if(hdirection2 == 0) {
		hpos2 = hpos2+10;
	}

	if(hdirection2 == 1) {
		hpos2 = hpos2-10;
	}

	if(hpos2 > (available_width - ballimage) & hdirection2 == 0) {
		hdirection2=1;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');
	}

	if(hpos2 < 0 & hdirection2 == 1) {
		hdirection2=0;
		FlashControls('document.layers[\'flashLayer\'].document.embeds[0]','document.flash','Play');		
	}

	coordflag = 1;
	setTimeout("bounce()",50);	
}

function FlashControls(Netscape,IE,Name,frameNum) { 
  		var which = (navigator.appName=='Netscape')?Netscape:IE;
 		if ((which.indexOf('document.layers[')==0 && document.layers==null) ||
      	(which.indexOf('document.all[')   ==0 && document.all   ==null))
   		which = 'document'+which.substring(which.lastIndexOf('.'),which.length);
  		if (eval(which) != null)
   		 eval(which+'.'+Name+'('+((Name=='GotoFrame')?frameNum:'')+')');
}

