window.onerror = null;
var topMargin = 5;
var slideTime = 1000;


function layerObject(id,left) {
	this.obj = document.getElementById(id).style;
	this.obj.right = left;
	return this.obj;
}

function layerSetup() {
	floatLyr = new layerObject('floatingImageBox', pageWidth * .5);
	document.getElementById('floatingImageBox').style.right = 30 + "px";
	window.setInterval("main()", 10)
}

function floatObject() {
	if(self.innerWidth != undefined){
		findHt = [self.innerWidth,self.innerHeight];
	}else{
		var D = document.documentElement;
		if(D){
			findHt = [D.clientWidth,D.clientHeight];
		}
	}
}

function getScrollXY(what) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  if (what == 'x'){ return scrOfX; }
  return scrOfY;
}

function main() {
	this.currentY = parseInt(document.getElementById('floatingImageBox').style.top);
	this.scrollTop = getScrollXY('y');
	mainTrigger();
}

function mainTrigger() {
	var newTargetY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
	}
}

function floatStart() {
	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 animator() {
	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 )) {
		document.getElementById('floatingImageBox').style.top = newY + "px";
	}
}

function start() {
	if(self.innerWidth != undefined){
		innerWidth = self.innerWidth;
	}else{
		var D = document.documentElement;
		if(D){
			innerWidth = D.clientWidth;
		}
	}
	if(self.innerHeight != undefined){
		innerHeight = self.innerHeight;
	}else{
		var D = document.documentElement;
		if(D){
			innerHeight = D.clientHeight;
		}
	}
	pageWidth = innerWidth;
	pageHeight = innerHeight;
	layerSetup();
	floatObject();
}
