// Copyright 2008 by Bontrager Connection, LLC - http://www.willmaster.com/ // Modifications Copyright 2008 by Julian Kalmar - http://www.thehappinessformula.com // -- Customization Area -- // var divID = "topbar"; // div's id var divWidth = 105; // div's width var divBorderWidth = 0; // div's border width (0 if none) // -- No other customization necessary -- // var doingTimeout; var scrolloffsetX = (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Opera') == -1) ? 10 : 20; var totop, nowtop, toleft, nowleft; var pushtotop, pushnowtop, pushtoleft, pushnowleft; var firsttime = 1; var timeincrement=.01; //time increment in seconds var xdifference, ydifference, xinitial, yinitial; var t=0; //time since clock started var rightnow; //current time in milliseconds var timestart; //motion start time: milliseconds var timenow; //current time: milliseconds function SlideTheMessage() { clearTimeout(doingTimeout); rightnow = new Date(); timenow = rightnow.getMilliseconds() + rightnow.getSeconds()*1000 + rightnow.getMinutes()*60000; if (firsttime==1) { GetCoordinates(); xdifference = toleft-nowleft; ydifference = totop-nowtop; xinitial = nowleft; yinitial = nowtop; timestart = timenow; t = 0; firsttime = 0; } else { pushnowleft = nowleft; pushnowtop = nowtop; pushtoleft = toleft; pushtotop = totop; GetCoordinates(); if (totop!=pushtotop || toleft!=pushtoleft || nowtop!=pushnowtop || nowleft!=pushnowleft) { xdifference = toleft-nowleft; ydifference = totop-nowtop; xinitial = nowleft; yinitial = nowtop; timestart = timenow; t = 0; firsttime = 0; } } t = (timenow - timestart)/1000; if ( (Math.abs(nowleft-toleft) + Math.abs(nowtop-totop )) <= 0 || t > 1) { firsttime = 1; t=1; nowleft = parseInt(xdifference*(-.5*t*t*t+1.5*t)+xinitial); //starting velocity=maximum, ending velocity=0 nowtop = parseInt(ydifference*(-.5*t*t*t+1.5*t)+yinitial); //starting velocity=maximum, ending velocity=0 document.getElementById(divID).style.top = nowtop + 'px'; document.getElementById(divID).style.left = nowleft + 'px'; return; } else { nowleft = parseInt(xdifference*(-.5*t*t*t+1.5*t)+xinitial); //starting velocity=maximum, ending velocity=0 nowtop = parseInt(ydifference*(-.5*t*t*t+1.5*t)+yinitial); //starting velocity=maximum, ending velocity=0 document.getElementById(divID).style.top = nowtop + 'px'; document.getElementById(divID).style.left = nowleft + 'px'; } doingTimeout = setTimeout("SlideTheMessage()",parseInt(1000*timeincrement)); } function GetCoordinates() { var scrollpositionX = 0, scrollpositionY = 0, viewX = 0, viewY = 0; if(self.pageYOffset) { scrollpositionX = self.pageXOffset; scrollpositionY = self.pageYOffset;} else if(document.documentElement&&document.documentElement.scrollTop) { scrollpositionX = document.documentElement.scrollLeft; scrollpositionY = document.documentElement.scrollTop; } else if(document.body) { scrollpositionX = document.body.scrollLeft; scrollpositionY = document.body.scrollTop; } if(self.innerWidth) { viewX = self.innerWidth; } else if(document.documentElement&&document.documentElement.clientWidth) { viewX = document.documentElement.clientWidth; } else if(document.body) { viewX = document.body.clientWidth; } var rightEdge = viewX - scrolloffsetX + scrollpositionX; nowleft = parseInt(document.getElementById(divID).style.left); toleft = rightEdge-divWidth-divBorderWidth-divBorderWidth; nowtop = parseInt(document.getElementById(divID).style.top); totop = scrollpositionY; } function PositionFloatingMessage() { clearTimeout(doingTimeout); SlideTheMessage(); } window.onscroll = PositionFloatingMessage; window.onresize = PositionFloatingMessage; window.onload = PositionFloatingMessage;