

// FloatMe (22-11-2004)
// by Vic Phillips - http://www.VicsJavaScripts.org.uk/
// Progressive Scroll by:  Eddie Traversa (psych3@primus.com.au)


// Any and as many elements on the page as required can be made to Float,
// that is, retain their position in the window as the page is scrolled.
// Where the float element is nested in an element with 'position:relative;' or 'position:absolute;'
// it will scroll within the parent element while the parent object is in view.
//
// The float element scroll is progressive,
// and the scroll speed is specified by a customising variable or in the Initialising call.


// ***** Application Notes

// ***** The HTML Code.
//
// The 'Float Element' must have a style position of  'position:absolute;'
// If the scroll speed is to be specified in the initialisation call it must be assigned a unique ID name.
// Alternatively it must be assigned a class name which includes a specified character string.
// e.g.
//  <DIV id="Float1" style="position:absolute;height:200px;width:200px;left:130px;top:100px;z-index: 100">........ content ........</DIV>
//  <DIV class="zxcMyRule1" style="position:absolute;" >........ content ........</DIV>
//
// To 'Float' an element for the total page width and height, the element should not be nested.
// To 'Float' an element within the constraints of a parent element,
// the parent element must have a style of 'position:relative;' or 'position:absolute;'
// and specified style width/height.
// e.g.
//  <DIV  style="position:relative;width:200px;height:500px;" >
//   <DIV class="zxcMyRule1" style="position:absolute;" >........ content ........</DIV>
//  </DIV>
//


// **** Initialising the Float Element
//
//  The Float Element would normally be initialised from a <BODY> or window onload event
// e.g.
//  <BODY onload="zxcFloatMe('Float1',2000);zxcFloatMe('Float2',1000);zxcFloatClass('zxc');" >
// where 'zxcFloatMe'
//  parameter 0 = the unique ID name of the 'Float' element.           (string)
//  parameter 1 = (optional) the scroll speed (10 = fast, 5000 = slow) (digits)
// Note: subsequent calls function 'zxcFloatMe' will toggle the float of the specified element.
// where 'zxcFloatClass'
//  parameter 0 = the character string to identify the element is to float. (string)
//

// **** General
//
// All variable, function etc. names are prefixed with 'zxc' to minimise conflicts with other JavaScripts
// These characters may be changed to characters of choice using global find and replace
//
// The Functional Code (about 3.5) is best as an External JavaScripts
//
// Tested with IE6 and Mozilla FireFox


// **** Customising Variables

var zxcDefaultScrollSpeed=2000; // the default scroll speed  (10 = fast, 5000 = slow) (digits)



// **** Functional Code - NO NEED to Change

function zxcFloatClass(zxcc){
 var zxcobjs=document.getElementsByTagName('*');
 for (var zxc0=0;zxc0<zxcobjs.length;zxc0++){
  if (zxcobjs[zxc0].className.match(zxcc)){
   if (!window['zxc'+zxc0+'Tzxc']){
    window['zxc'+zxc0+'zxcC']=new zxcFloatMeOOP(zxcobjs[zxc0]);
    window['zxc'+zxc0+'zxcC'].getpos();
   }
  }
 }
}

function zxcFloatMe(zxcid,zxcspd){
 if (!document.getElementById(zxcid)){ return; }
 if (!window['zxc'+zxcid+'zxc']){ window['zxc'+zxcid+'zxc']=new zxcFloatMeOOP(zxcid,zxcspd); }
 var zxcobj=window['zxc'+zxcid+'zxc'];
 if (!zxcobj){ return; }
 zxcobj.spd=zxcspd||zxcobj.t;
 zxcobj.set=!zxcobj.set;
 zxcobj.set?clearTimeout(zxcobj.to):zxcobj.getpos();
}

var zxcOOPCnt=0;

function zxcFloatMeOOP(zxcid,zxcspd){
 this.obj=(typeof(zxcid)=='string')?document.getElementById(zxcid):zxcid;
 this.obj.style.left=this.obj.style.left||this.obj.offsetLeft+'px';
 this.obj.style.top=this.obj.style.top||this.obj.offsetTop+'px';
 this.ref='zxcoopfm'+zxcOOPCnt++;
 window[this.ref]=this;
 this.to=null;
 this.os=[parseInt(this.obj.style.left),parseInt(this.obj.style.top)];
 this.set=true;
 this.spd=zxcspd||zxcDefaultScrollSpeed||1000;
 this.dly=10+zxcOOPCnt*10;
 this.max=[((parseInt(this.obj.parentNode.style.width||this.obj.parentNode.offsetWidth)))-((parseInt(this.obj.style.width||this.obj.offsetWidth))),((parseInt(this.obj.parentNode.style.height||this.obj.parentNode.offsetHeight)))-((parseInt(this.obj.style.height||this.obj.offsetHeight)))];
 this.pxy=zxcPos(this.obj.parentNode);
}

zxcFloatMeOOP.prototype.getpos=function(){
 this.inc=Math.PI/(2*this.spd);
 this.px=0;
 if (zxcDocS()[0]-this.pxy[0]>0){ this.px=zxcDocS()[0]-this.pxy[0]; }
 this.nowx=parseInt(this.obj.style.left);
 this.ckx=this.px+this.os[0];
 if ( this.nowx!=this.ckx){
  if ( this.ckx!=this.newx){
   this.newx=this.ckx;
   this.cngx=this.newx-this.nowx;
   this.lsttimex=new Date().getTime();
   this.lstposx=this.nowx;
  }
  this.movex();
 }
 this.py=0;
 if (zxcDocS()[1]-this.pxy[1]>0){ this.py=zxcDocS()[1]-this.pxy[1]; }
 this.nowy=parseInt(this.obj.style.top);
 this.cky=this.py+this.os[1];
 if ( this.nowy!=this.cky){
  if ( this.cky!=this.newy){
   this.newy=this.cky;
   this.cngy=this.newy-this.nowy;
   this.lsttimey=new Date().getTime();
   this.lstposy=this.nowy;
   this.oldsy=zxcDocS()[1]
  }
  this.movey();
 }
 this.setTimeOut('getpos();',this.dly);
}

zxcFloatMeOOP.prototype.movex=function(){
 this.posx=Math.round(this.cngx*Math.sin(this.inc*(new Date().getTime()-this.lsttimex))+this.lstposx);
 if (( this.cngx>0&&this.posx>this.nowx&&this.posx<this.max[0])||(this.cngx<0&&this.posx<this.nowx)){
  this.obj.style.left=(this.posx)+'px';
 }
}

zxcFloatMeOOP.prototype.movey=function(){
 this.posy=Math.round(this.cngy*Math.sin(this.inc*(new Date().getTime()-this.lsttimey))+this.lstposy);
 if ((this.cngy>0&&this.posy>this.nowy&&this.posy<this.max[1])||(this.cngy<0&&this.posy<this.nowy)){
  this.obj.style.top=(this.posy)+'px';
 }
}

zxcFloatMeOOP.prototype.setTimeOut=function(zxcf,zxcd){
 this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}

function zxcDocS(){
 if (!document.body.scrollTop){ return [document.documentElement.scrollLeft,document.documentElement.scrollTop]; }
 else { return [document.body.scrollLeft,zxcsy=document.body.scrollTop]; }
}

function zxcPos(zxcobj){
 zxclft=zxcobj.offsetLeft;
 zxctop=zxcobj.offsetTop;
 while(zxcobj.offsetParent!=null){
  zxcpar=zxcobj.offsetParent;
  zxclft+=zxcpar.offsetLeft;
  zxctop+=zxcpar.offsetTop;
  zxcobj=zxcpar;
 }
 return [zxclft,zxctop];
}

//  End -->

