//=====================================================================
// Pigeon
// by bedrockjava.com
//
//=====================================================================

//=====================================================================
// Initialize Variables
//=====================================================================

var pigeonSpeed	=30;
var pigeonX=-80;
var pigeonY=250;
var pigeonRight;
var pigeonRise;

var signX=-80;
var signY=250;

var page;
var preloadSign_o=new Image();
preloadSign_o.src='../images/util/subscribe_o.gif';

function doUnload()
{}

function doOnload()
{
	page=new pageSize();
	if(Math.random()>.8)
	{
		window.status='+';
		setTimeout('startFlying()',Math.round((Math.random()*5000)+24000));
	}
	else
	{
		window.status='-';
		setTimeout('startFlying()',50000);
	}
}

function startFlying()
{
	pigeonRight=(Math.random()*3)+3;
	pigeonRise=(Math.random()*2)-1.6;
	var top=findViewTop();
	if(pigeonRise>0)
	{
		pigeonY=top+Math.round((Math.random()*250));
	}
	else
	{
		pigeonY=top+Math.round((Math.random()*250))+300;
	}
	fly();
}

function fly()
{
	pigeonX+=pigeonRight;
	pigeonY+=pigeonRise;
	signX=pigeonX-300;
	signY=pigeonY-20;
	if(pigeonX<(page.width+300))
	{
		setX(getObjectRef('pigeon'),pigeonX);	
		setY(getObjectRef('pigeon'),pigeonY);	
		setX(getObjectRef('sign'),signX);	
		setY(getObjectRef('sign'),signY);	
		setTimeout('fly()', pigeonSpeed);
	}
	else
	{
		setX(getObjectRef('pigeon'),-80);
		setX(getObjectRef('sign'),-200);
		pigeonX=-80;	
		setTimeout('startFlying()', 240000);
	}
	
}

//=====================================================================
// Utility Functions
//=====================================================================

function getObjectRef(elName)
{
	if(document.all)
	{
		return document.all[elName];
	}
	else if(document.getElementById)
	{
		return document.getElementById(elName);
	}
	else if(document.layers)
	{
		return document.layers[elName]
	}
	return false;
}

function setX(obj,x)
{
	if(document.all){obj.style.pixelLeft=x;return;}
	if(document.getElementById){obj.style.left=x+"px";return;}
	if(document.layers){obj.left=x;}
}
function setY(obj,y)
{
	if(document.all){obj.style.pixelTop=y;return;}
	if(document.getElementById){obj.style.top=y+"px";return;}
	if(document.layers){obj.top=y;}
}


function pageSize()
{ 
	this.width=document.body&&document.body.offsetWidth?document.body.offsetWidth-20:document.body&&document.body.innerWidth?document.body.innerWidth:innerWidth?innerWidth:0;
	this.height=document.body&&document.body.offsetHeight?document.body.offsetHeight-5:document.body&&document.body.innerHeight?document.body.innerHeight:innerHeight?innerHeight:0;
}

function findViewTop()
{
	var top=0;
	
	if(window.pageYOffset)
	{
		top=window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		top = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		if(document.body.scrollTop==null)
			top=0;
		else
		{
			top = document.body.scrollTop;
		}
	}
	else
	{
		top=0;
	}
	return top;
}
















