floatStreaker.holder = []; // arguments: id, left, top, direction, speed (pixels per loop), delay for restart or null, optional end function function floatStreaker(id,x,y,dir,sp,d,fn) { this.el = document.getElementById? document.getElementById(id): null; if (!this.el) return; var px = window.opera? 0: "px"; this.id = id; this.xOff = x; this.yOff = y; this.el.style.left = x + px; this.el.style.top = y + px; this.el.style.visibility = "visible"; this.speed = sp; this.ctr = 0; this.active = true; if (fn) this.onFloatEnd = fn; this.delay = d; if (!fn && !d) this.onFloatEnd = function() { this.el = null; this.active = false; }; this.prop = (dir == "left" || dir == "right")? "left": "top"; if (dir == "left" || dir == "up") this.speed = -sp; floatStreaker.holder[floatStreaker.holder.length] = this; if (!floatStreaker.Canvas.width || !floatStreaker.Canvas.height) floatStreaker.Canvas = floatStreaker.getDimensions(); } floatStreaker.prototype.do_float = function() { var cur; switch (this.prop) { case "left": cur = parseInt( this.el.style.left ); if ( ( this.speed > 0 && cur < floatStreaker.Canvas.width + this.el.offsetWidth ) || ( this.speed < 0 && cur > -this.el.offsetWidth ) ) { this.el.style.left = parseInt(this.el.style.left) + this.speed + "px"; } else { if (this.delay) this.hold_and_reset(this.xOff); this.onFloatEnd(this); } break; case "top": cur = parseInt( this.el.style.top ); if ( ( this.speed > 0 && cur < floatStreaker.Canvas.height + this.el.offsetHeight ) || ( this.speed < 0 && cur > -this.el.offsetHeight ) ) { this.el.style.top = parseInt(this.el.style.top) + this.speed + "px"; } else { if (this.delay) this.hold_and_reset(this.yOff); this.onFloatEnd(this); } break; } } floatStreaker.prototype.hold_and_reset = function(nOff) { if ( this.ctr < this.delay/floatStreaker.callRate ) { this.el.style.visibility = "hidden"; this.ctr++; } else { this.el.style[this.prop] = nOff + "px"; this.el.style.visibility = "visible"; this.ctr = 0; } } floatStreaker.prototype.onFloatEnd = function(){}; floatStreaker.callRate = 20; floatStreaker.timer = window.setInterval("floatStreaker.control()", floatStreaker.callRate); // Handle all instances with one timer - idea from youngpup.net floatStreaker.control = function() { var i, curObj; for (i=0; curObj = floatStreaker.holder[i]; i++) if ( curObj && curObj.active ) curObj.do_float(); } floatStreaker.Canvas = {}; // See last line of constructor // for obtaining largest of window and document width/height floatStreaker.getDimensions = function() { var winWd=0, winHt=0, docWd=0, docHt=0; if (window.innerWidth) winWd = window.innerWidth - 18; else if (document.documentElement && document.documentElement.clientWidth) winWd = document.documentElement.clientWidth; else if (document.body && document.body.clientWidth) winWd = document.body.clientWidth; if (window.innerHeight) winHt = window.innerHeight - 18; else if (document.documentElement && document.documentElement.clientHeight) winHt = document.documentElement.clientHeight; else if (document.body && document.body.clientHeight) winHt = document.body.clientHeight; if (document.width) docWd = document.width; else if (document.body) docWd = Math.max(document.body.scrollWidth, document.body.offsetWidth); if (document.height) docHt = document.height; else if (document.body) docHt = Math.max(document.body.scrollHeight, document.body.offsetHeight); return { width: Math.max(winWd, docWd), height: Math.max(winHt, docHt) } } function getWinWidth() { var winWd = 0; if (document.documentElement && document.documentElement.clientWidth) winWd = document.documentElement.clientWidth; else if (document.body && document.body.clientWidth) winWd = document.body.clientWidth; else if (document.body && document.body.offsetWidth) winWd = document.body.offsetWidth; else if (window.innerWidth) winWd = window.innerWidth-18; return winWd; } function getWinHeight() { var winHt = 0; if (window.innerHeight) winHt = window.innerHeight-18; else if (document.documentElement && document.documentElement.clientHeight) winHt = document.documentElement.clientHeight; else if (document.body && document.body.clientHeight) winHt = document.body.clientHeight; return winHt; } if (window.addEventListener) window.addEventListener("resize", function(){ floatStreaker.Canvas = floatStreaker.getDimensions() }, "false"); else if (window.attachEvent) window.attachEvent("onresize", function(){ floatStreaker.Canvas = floatStreaker.getDimensions() } ); fs_winHt = getWinHeight(); if (document.all) { fs_banerWidth = document.getElementById('floatStreakerDiv').offsetWidth+10; fs_banerHeight = document.getElementById('floatStreakerDiv').offsetHeight+10; }else if (document.layers){ fs_banerWidth = document.layers['floatStreakerDiv'].document.width; fs_banerHeight = document.layers['floatStreakerDiv'].document.height; }else{ fs_banerWidth = document.getElementById('floatStreakerDiv').offsetWidth; fs_banerHeight = document.getElementById('floatStreakerDiv').offsetHeight; } intWhereToPlaceStreakerDiv = 0 - fs_banerWidth; /*intHeightToPlaceStreakerDiv = (fs_winHt / 2) - (fs_banerHeight / 2);*/ intHeightToPlaceStreakerDiv = 120; window.onload = new floatStreaker("floatStreakerDiv", intWhereToPlaceStreakerDiv, intHeightToPlaceStreakerDiv, "right", 3, 10000);