var finished = true;


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}



/**
* @param el	Reference to ID of html element
* @param x Final X which element will be moved to
* @param y Final Y which element will be moved to
* @param a offset (aka speed (5 is smooth))
* @param b ?
* @param c 0,1 or 2
* @param s Timeout prior animation start
*/
function P7AniMagic(el, x, y, a, b, c, s) { //v2.5 PVII
	finished = false;
	 var g, elo=el, f="", m=false, d="";
	 x=parseInt(x);y=parseInt(y);
	 var t = 'g.p7Magic = setTimeout("P7AniMagic(\''+elo+'\','; 

	 
	// get the object to animate
	 if ((g=MM_findObj(el))!=null)
		d=(document.layers)?g:g.style;
	 else
		return;
	 
	// if timeout is set...
	if (parseInt(s)>0) {
		eval(t+x+','+y+','+a+','+b+','+c+',0)",' + s+')');
		return;
	}
 // set initial xx and yy. Either left-top of DIV or 0,0
	var xx=(parseInt(d.left))?parseInt(d.left):0;
	var yy=(parseInt(d.top))?parseInt(d.top):0;
	
	if(parseInt(c)==1) {
		x+=xx;
		y+=yy;
		m=true;
		c=0;
	} else if (c==2) {
		m=false;
		clearTimeout(g.p7Magic);
	} else {
		var i=parseInt(a);		
		if (eval(g.moved)) {
			clearTimeout(g.p7Magic);
		}
			
		if (xx<x){xx+=i;m=true;if(xx>x){xx=x;}}
		if (xx>x){xx-=i;m=true;if(xx<x){xx=x;}}
		if (yy<y){yy+=i;m=true;if(yy>y){yy=y;}}
		if (yy>y){yy-=i;m=true;if(yy<y){yy=y;}}
		
		if(xx == x) {
			d.visibility = "hidden";
			d.left = 0; d.top = 0;	// to remove scrollbars
			finished = true;
		}
			
	}
	if (m) {
		if((navigator.appName=="Netscape") && parseInt(navigator.appVersion)>4) {
			xx+="px";yy+="px";
		}
		d.left=xx;
		d.top=yy;
		g.moved=true;
		eval(t+x+','+y+','+a+','+b+','+c+',0)",'+b+')');
	  }else {
		g.moved=false;
	}
}

/** Gets screen size of browser's window.
* @returns 2-elements array of (width, height)
*/
function getSize() {
	var theWidth, theHeight;

	if (window.innerWidth) {
		theWidth=window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
	} else if (document.body) {
		theWidth=document.body.clientWidth;
	}

	if (window.innerHeight) {
		theHeight=window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		theHeight=document.body.clientHeight;
	}
return(Array(theWidth, theHeight));
}


// left to right fly
function ltr(divName, elName) {
	if(divName && finished) {
		var g, d;
		// get the object to animate
		if ((g=MM_findObj(divName))!=null)
			d=(document.layers)?g:g.style;

		z = getSize();		
		d.left = 0;
		d.top = 0;
		d.visibility = "visible";
		var toX = z[0];
		var toY;

		if(d.height)
			toY = Math.floor(Math.random() * z[1]) + 500 - parseInt(d.height);
		else
			toY = Math.floor(Math.random() * z[1] + 500);

		if(d.height && (toY < parseInt(d.height)))
			toY = parseInt(d.height + 500 );		
		P7AniMagic(divName, toX, toY, 5, 30, 0, 0);
		//P7AniMagic(divName, z[0] - d.width, Math.floor(Math.random() * z[1]), 5, 30, 0, 0);
	}
}

// right to left fly
function rtl(divName, elName) {
	if(divName && finished) {
		var g, d;
		// get the object to animate
		if ((g=MM_findObj(divName))!=null)
			d=(document.layers)?g:g.style;

		z = getSize();	
		d.left = z[0]+"pt";
		d.top = "200pt";
		d.visibility = "visible";
		var toX, toY;
		
		if(d.width)
			toX = 0 - parseInt(d.width);
		else
			toX = -300;
			
		if(d.height)
			toY = Math.floor(Math.random() * z[1]) + 500 - parseInt(d.height);
		else 
			toY = Math.floor(Math.random() * z[1] + 500);
		// fix for out of bounds div
		if(d.height && (toY < parseInt(d.height)))
			toY = parseInt(d.height + 500);
		
		P7AniMagic(divName, toX, toY, 5, 30, 0, 0);
	}
}


function makeTimeout() {
	var TIMEOUT_LOW = 7;
	var TIMEOUT_HIGH = 15;
	var t = Math.floor(Math.random() * TIMEOUT_HIGH);
	if(t < TIMEOUT_LOW )
		t = TIMEOUT_LOW;
	t *= 1000;	//convert to millis 
return t;
}


/*
t = makeTimeout();
setTimeout("fly()", t);

function fly() {
	window.alert("fly");
	t = makeTimeout();
	setTimeout("fly()", t);
}
*/

//ltr('bird_ltr');
//rtl('bird_rtl');
