﻿function flying()
{ 
	this.delay = 300; 
	this.xPos = Math.random() * 800; 
	this.yPos = Math.random() * 600; 
	this.step = 10; 
	this.pageW = 0; 
	this.pageH = 0; 
	this.pageX = 0;
	this.pageY = 0;
	this.offsetH = 0; 
	this.offsetW = 0; 
	this.yOn = 0; 
	this.xOn = 0; 
	this.object;
	this.p = false; 
	this.addItem = function(id,content)
		  {
			document.write('<div id="' + id + '" style="z-index:20; position:absolute; display:none; width:10px; height:10px; left:' + this.xPos + 'px; top:' + this.yPos + 'px;" onmouseover="' + id + '.pause();" onmouseout="' + id + '.goon();">' + content + '</div>');
			this.object = document.getElementById(id);
		  }
	this.play = function()
		  {
			this.object.style.display = '';
            var _this = this;
            var playFly = function(){ _this.playFly(); };
			window.setInterval(playFly,this.delay);
		  }
    this.playFly = function()
		{
			if (!this.p)
			{
				if (document.documentElement.clientWidth && document.documentElement.clientWidth<document.body.clientWidth)
				{
					this.pageW = document.documentElement.clientWidth;
				}
				else
				{
					this.pageW = document.body.clientWidth;
				}
				if (document.documentElement.clientHeight && document.documentElement.clientHeight<document.body.clientHeight)
				{
					this.pageH = document.documentElement.clientHeight;
				}
				else
				{
					this.pageH = document.body.clientHeight;
				}
				
				if (document.documentElement && document.documentElement.scrollTop)
				{
					this.pageX = document.documentElement.scrollLeft;
					this.pageY = document.documentElement.scrollTop;
				}
				else if (document.body)
				{
					this.pageX = document.body.scrollLeft;
					this.pageY = document.body.scrollTop;
				}
				else
				{
					this.pageX = window.pageXOffset;
					this.pageY = window.pageYOffset;
				}
				
				this.offsetH = this.object.offsetHeight; 
				this.offsetW = this.object.offsetWidth; 
				
				this.object.style.left = (this.xPos + this.pageX) + 'px'; 
				this.object.style.top = (this.yPos + this.pageY) + 'px'; 
				
				if (this.yOn)
				{ 
					this.yPos = this.yPos + this.step; 
				} 
				else
				{ 
					this.yPos = this.yPos - this.step; 
				} 
				if (this.yPos < 0)
				{ 
					this.yOn = 1; 
					this.yPos = 0; 
				} 
				if (this.yPos >= (this.pageH - this.offsetH))
				{ 
					this.yOn = 0; 
					this.yPos = (this.pageH - this.offsetH); 
				} 
				if (this.xOn)
				{ 
					this.xPos = this.xPos + this.step; 
				} 
				else
				{ 
					this.xPos = this.xPos - this.step; 
				} 
				if (this.xPos < 0)
				{ 
					this.xOn = 1; 
					this.xPos = 0; 
				} 
				if (this.xPos >= (this.pageW - this.offsetW))
				{ 
					this.xOn = 0; 
					this.xPos = (this.pageW - this.offsetW); 
				} 
			}
		}
	this.pause = function()
		  {
            this.p = true;
		  }
	this.goon = function()
		  {
            this.p = false;
		  }
} 

