/*
This file have the functions to float the required layer over the browser screen.
*/
window.onerror = null;
var topMargin = 250;
var slideTime = 1800;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
if (ns6) {
this.obj = document.getElementById(id).style;
this.obj.left = left;
return this.obj;
}
else if(ie4) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
else if(ns4) {
this.obj = document.layers[id];
this.obj.left = left;
return this.obj;
}
}
//This function creates a floating layer by using the incoming layer. The left alignment of the 
//floating layer will be set by using the second parameter.
function layerSetup() {
floatLyr = new layerObject('mainlayer', pageWidth * .2);
//setting the interval time for moving the floating layer and moving the floating layer by calling
//the function main()
window.setInterval("main()", 10)
}//end of function layerSetup() method

//This method finds the inner height of the browser screen.
function floatObject() {
//if the browser type is netscape
if (ns4 || ns6) {
//getting the inner height of the browser screen
findHt = window.innerHeight;
} 
//if the browser type is ie
else if(ie4) {
//getting the inner height of the browser screen
findHt = document.body.clientHeight;
}
} //end of function floatObject()

//This main method does the actual floating of the layer.
function main() {
//if the browser is ns4
if (ns4) {
//getting the mainlayer's top value.
this.currentY = document.layers["mainlayer"].top;
//getting the scroll bar top value.
this.scrollTop = window.pageYOffset;
//calling te mainTrigger function for floating
mainTrigger();
}
//if the browser is ns6
else if(ns6) {
//getting the mainlayer's top value.
this.currentY = parseInt(document.getElementById('mainlayer').style.top);
//getting the scroll bar top value.
this.scrollTop = scrollY;
//calling te mainTrigger function for floating
mainTrigger();
} 
//if the browser is ie4
else if(ie4) {
//getting the mainlayer's top value.
this.currentY = mainlayer.style.pixelTop;
//getting the scroll bar top value.
this.scrollTop = document.body.scrollTop;
//calling te mainTrigger function for floating
mainTrigger();
}
}//end of function main()


function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}//end of inner if
animator();
}//end of outer if
}//end of function mainTrigger() 

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 )) {
if ( ie4 )document.all.mainlayer.style.pixelTop = newY;
if ( ns4 )document.layers["mainlayer"].top = newY;
if ( ns6 )document.getElementById('mainlayer').style.top = newY + "px";
   }
}
//This function starts the floating of the input layer.
function start() {
//if the browser type is netscape
if(ns6||ns4) {
//getting the browser screen width and height
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
//if the browser type is ie
else if(ie4) {
//getting the browser screen width and height
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
}
}//end of function start() {



