
window.onerror=null;
var distanceFromTop = 0;
var yOffset = 5;
var slideTime = 1200;
var loaded = false;
var findHt = 0;

var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);


var currentY = 0;
var scrollTop = 0;

var targetY = 0;
var A = 0;
var B = 0;
var C = 0;
var D = 0;
var pageWidth = 0;
var pageHeight = 0;


function main() 
{
	if (ns4) {
		if (this.loaded ) {
			this.currentY = document.layers["FloatingMenu1"].top;
		} 
		else {
			this.loaded = true;
		}
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	}
	else if(ns6) {
		if (this.loaded ) {
			this.currentY = parseInt(document.getElementById('FloatingMenu1').style.top);
		} 
		else {
			this.loaded = true;
		}
		this.scrollTop = scrollY;
		mainTrigger();
	} 
	else if(ie4) {
		if (this.loaded ) {
			this.currentY = FloatingMenu1.style.pixelTop;
		} 
		else {
			this.loaded = true;
		}
		
		this.scrollTop = document.body.scrollTop;
		mainTrigger();
	}
}

function mainTrigger() 
{
	var newTargetY
	if(this.scrollTop < (this.distanceFromTop - this.yOffset)){
		newTargetY = distanceFromTop;
	}
	else{
		newTargetY = this.scrollTop + this.yOffset;
		
	}
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			getFloatingstartFloatingMenu();
		}
		animate();
	}
}

function getFloatingstartFloatingMenu() 
{
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}
	else {
		this.D = this.currentY;
   	}
}

function animate() 
{
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {

		if ( ie4 )
		{
			document.all.FloatingMenu1.style.pixelTop = newY;
			document.all.FloatingMenu2.style.pixelTop = newY+63;
			
		}
		if ( ns4 )
		{
			document.layers["FloatingMenu1"].top = newY;
			document.layers["FloatingMenu2"].top = newY + 63;
		}
		if ( ns6 )
		{
			document.getElementById('FloatingMenu1').style.top = newY + "px";
			document.getElementById('FloatingMenu2').style.top = (newY + 63) + "px";
		}
	}
}

function startFloatingMenu(distance) 
{
	this.distanceFromTop = distance;
	if(ns6||ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		window.setInterval("main()", 10)
		findHt = window.innerHeight;
	}
	else if(ie4) {
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		window.setInterval("main()", 10)
		findHt = document.body.clientHeight;
	}

}